Skip to content

Commit 9bbbd9f

Browse files
committed
fix(server): keep the parse failure as the cause of a refused settings save
1 parent 77f34b2 commit 9bbbd9f

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎apps/server/src/serverSettings.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ const make = Effect.gen(function* () {
723723
// A file that failed to decode must stay on disk for the user to repair;
724724
// the fold below only writes when it started from the file's real contents.
725725
let settingsFileTrusted = true;
726+
let parseFailure = Option.none<unknown>();
726727

727728
if (yield* readConfigExists) {
728729
const raw = yield* readRawConfig;
@@ -741,6 +742,7 @@ const make = Effect.gen(function* () {
741742
// The file may hold an opt-out we can no longer read; never resume threads on a guess.
742743
settings = { ...DEFAULT_SERVER_SETTINGS, continueThreadsAfterServerUpdate: false };
743744
if (failure._tag === "Failure") {
745+
parseFailure = Option.some(Cause.squash(failure.cause));
744746
yield* Effect.logWarning("failed to parse settings.json, using defaults", {
745747
path: settingsPath,
746748
issues: Cause.pretty(failure.cause),
@@ -852,13 +854,13 @@ const make = Effect.gen(function* () {
852854
yield* secretStore.remove(move.from).pipe(Effect.ignore);
853855
}
854856
}
855-
return { settings: migrated, fileTrusted: settingsFileTrusted };
857+
return { settings: migrated, parseFailure };
856858
});
857859

858860
// A failed read is not kept: the next read retries instead of replaying the failure.
859861
const settingsCache = yield* Cache.makeWith<
860862
typeof cacheKey,
861-
{ readonly settings: ServerSettings; readonly fileTrusted: boolean },
863+
{ readonly settings: ServerSettings; readonly parseFailure: Option.Option<unknown> },
862864
ServerSettingsError
863865
>(() => loadSettingsFromDisk, {
864866
capacity: 1,
@@ -1074,9 +1076,13 @@ const make = Effect.gen(function* () {
10741076
): Effect.Effect<ServerSettings, ServerSettingsError> =>
10751077
writeSemaphore.withPermits(1)(
10761078
Effect.gen(function* () {
1077-
const { settings: current, fileTrusted } = yield* reloadSettings;
1078-
if (!fileTrusted) {
1079-
return yield* new ServerSettingsError({ settingsPath, operation: "read-file" });
1079+
const { settings: current, parseFailure } = yield* reloadSettings;
1080+
if (Option.isSome(parseFailure)) {
1081+
return yield* new ServerSettingsError({
1082+
settingsPath,
1083+
operation: "read-file",
1084+
cause: parseFailure.value,
1085+
});
10801086
}
10811087
const updated = yield* update(current);
10821088
const persisted = yield* persistSettingsSecrets(current, updated);
@@ -1097,7 +1103,7 @@ const make = Effect.gen(function* () {
10971103
return materializedExit.value;
10981104
}),
10991105
);
1100-
yield* Cache.set(settingsCache, cacheKey, { settings: next, fileTrusted: true });
1106+
yield* Cache.set(settingsCache, cacheKey, { settings: next, parseFailure: Option.none() });
11011107
yield* emitChange(next);
11021108
return resolveTextGenerationProvider(materialized);
11031109
}),

0 commit comments

Comments
 (0)