fix(data): never let the compile_options probe block opening an index

Any failure of the informational PRAGMA compile_options probe is logged
and gives an empty list; before, anything but a SqliteException was cached
by the lazy value and rethrown by every later open.

Tests now cover the decode-tier fields end to end: the Library's
preview-only chip and its plural tooltip, server cards and frames carrying
previewOnlyCount and the preview size over the API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 11:17:55 +00:00
1 parent 5599e4de89
commit bbc7f244fa
4 files changed
+100 -21

No files matched your search

+32 -21
View File
@@ -37,7 +37,7 @@ public sealed class SqliteDatabase : IDatabase
internal const int BusyTimeoutMs = 5000;
private const string LogCategory = "Data.Sqlite";
private static readonly TimeSpan WriteLockTimeout = TimeSpan.FromSeconds(60);
private static readonly Lazy<IReadOnlyList<string>> ProbedCompileOptions = new(ProbeCompileOptions);
private static readonly Lazy<IReadOnlyList<string>> ProbedCompileOptions = new(() => ProbeCompileOptions(ReadCompileOptions));
private readonly string _filename;
private readonly bool _memory;
@@ -275,34 +275,45 @@ public sealed class SqliteDatabase : IDatabase
throw new NotSupportedException($"SQLite {version / 1_000_000}.{version / 1000 % 1000}.{version % 1000} is too old; 3.31 or newer is required.");
}
private static IReadOnlyList<string> ProbeCompileOptions()
/// <summary>
/// The options <paramref name="read"/> returns, logged; any failure is logged and gives none, since the probe is
/// informational and must never stop an index from opening (a failure escaping the lazy value would be rethrown by
/// every later open).
/// </summary>
internal static IReadOnlyList<string> ProbeCompileOptions(Func<IReadOnlyList<string>> read)
{
var options = new List<string>();
try
{
using var connection = SqliteConnection.Open(":memory:", isMemory: true, BusyTimeoutMs);
var statement = connection.Rent("PRAGMA compile_options");
try
{
var columns = statement.ReadColumns();
int rc;
while ((rc = statement.Step()) == SQLITE_ROW)
{
if (statement.ReadRow(columns).GetStringOrNull(0) is { Length: > 0 } option) options.Add(option);
}
if (rc != SQLITE_DONE) throw connection.Error(rc);
}
finally
{
connection.Return(statement);
}
var options = read();
Log.Info(LogCategory, $"SQLite {LibraryVersion}; compile options: {string.Join(' ', options)}");
return options;
}
catch (SqliteException ex)
catch (Exception ex) when (ex is not OutOfMemoryException)
{
Log.Warning(LogCategory, "PRAGMA compile_options could not be read", ex);
return [];
}
Log.Info(LogCategory, $"SQLite {LibraryVersion}; compile options: {string.Join(' ', options)}");
}
private static List<string> ReadCompileOptions()
{
var options = new List<string>();
using var connection = SqliteConnection.Open(":memory:", isMemory: true, BusyTimeoutMs);
var statement = connection.Rent("PRAGMA compile_options");
try
{
var columns = statement.ReadColumns();
int rc;
while ((rc = statement.Step()) == SQLITE_ROW)
{
if (statement.ReadRow(columns).GetStringOrNull(0) is { Length: > 0 } option) options.Add(option);
}
if (rc != SQLITE_DONE) throw connection.Error(rc);
}
finally
{
connection.Return(statement);
}
return options;
}