Skip to content

Commit 357af8f

Browse files
fix(settings): name each rejected environment with its own reason
Two environments can reject a fan-out write for different reasons; the report used the first error for every label. Co-Authored-By: Claude Code <[email protected]>
1 parent 0d2df6b commit 357af8f

4 files changed

Lines changed: 38 additions & 19 deletions

File tree

‎apps/mobile/src/features/settings/SettingsRouteScreen.tsx‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
type ServerSettingsPatch,
4646
} from "@t3tools/contracts";
4747
import {
48+
describeRejectedSettingsWrites,
4849
findSharedSettingsMismatches,
4950
pickSharedServerSettings,
5051
supportsSharedSettings,
@@ -594,16 +595,9 @@ function AutoSettleSettingsRows() {
594595
}
595596
}),
596597
);
597-
if (failed.length === 0) {
598-
return;
598+
if (failed.length > 0) {
599+
Alert.alert("Setting not saved", describeRejectedSettingsWrites(failed));
599600
}
600-
const error = failed[0]?.error;
601-
Alert.alert(
602-
"Setting not saved",
603-
`${failed.map(({ label }) => label).join(", ")}: ${
604-
error instanceof Error ? error.message : "The server rejected the change."
605-
}`,
606-
);
607601
},
608602
[updateSettings],
609603
);

‎apps/web/src/hooks/useSettings.ts‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
squashAtomCommandFailure,
3131
} from "@t3tools/client-runtime/state/runtime";
3232
import {
33+
describeRejectedSettingsWrites,
3334
findSharedSettingsMismatches,
3435
pickSharedServerSettings,
3536
splitSharedServerPatch,
@@ -374,17 +375,13 @@ function useWriteServerSettings() {
374375
}
375376
}),
376377
);
377-
if (failed.length === 0) {
378-
return;
378+
if (failed.length > 0) {
379+
toastManager.add({
380+
type: "error",
381+
title: "Setting not saved",
382+
description: describeRejectedSettingsWrites(failed),
383+
});
379384
}
380-
const error = failed[0]?.error;
381-
toastManager.add({
382-
type: "error",
383-
title: "Setting not saved",
384-
description: `${failed.map(({ label }) => label).join(", ")}: ${
385-
error instanceof Error ? error.message : "The server rejected the change."
386-
}`,
387-
});
388385
},
389386
[persistServerSettings],
390387
);

‎packages/client-runtime/src/state/sharedSettings.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
EnvironmentPresentation,
1010
} from "../connection/presentation.ts";
1111
import {
12+
describeRejectedSettingsWrites,
1213
findSharedSettingsMismatches,
1314
pickSharedServerSettings,
1415
splitSharedServerPatch,
@@ -188,3 +189,14 @@ describe("supportsSharedSettings", () => {
188189
expect(supportsSharedSettings(presentation("connected", null))).toBe(false);
189190
});
190191
});
192+
193+
describe("describeRejectedSettingsWrites", () => {
194+
it("keeps each environment's own reason", () => {
195+
expect(
196+
describeRejectedSettingsWrites([
197+
{ label: "Laptop", error: new Error("Laptop is not connected.") },
198+
{ label: "Remote Box", error: { _tag: "EnvironmentAuthorizationError" } },
199+
]),
200+
).toBe("Laptop: Laptop is not connected.\nRemote Box: The server rejected the change.");
201+
});
202+
});

‎packages/client-runtime/src/state/sharedSettings.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ export function supportsSharedSettings(environment: EnvironmentPresentation): bo
6666
);
6767
}
6868

69+
/**
70+
* One line per environment that rejected a settings write, each with its own
71+
* reason. Two environments can fail for different reasons (one dropped its
72+
* session, one refused the scope), so the reasons are never collapsed.
73+
*/
74+
export function describeRejectedSettingsWrites(
75+
failed: ReadonlyArray<{ readonly label: string; readonly error: unknown }>,
76+
): string {
77+
return failed
78+
.map(
79+
({ label, error }) =>
80+
`${label}: ${error instanceof Error ? error.message : "The server rejected the change."}`,
81+
)
82+
.join("\n");
83+
}
84+
6985
export interface SharedSettingsEnvironment {
7086
readonly environmentId: EnvironmentId;
7187
readonly label: string;

0 commit comments

Comments
 (0)