Skip to content

Commit bba4d9f

Browse files
committed
refactor: address low-priority review follow-ups
- daemon-client RPC error path: stringify any non-null data.code instead of only forwarding strings. Preserves numeric codes from hypothetical future proxies/servers; for first-party daemon today this is a no-op since handlers already emit strings. - errors.ts: expand AppErrorCode comment to call out the exhaustiveness tradeoff of the '(string & {})' widening for SDK consumers.
1 parent 8e75778 commit bba4d9f

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/daemon-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ async function sendHttpRequest(
977977
reject(
978978
new AppError(
979979
toAppErrorCode(
980-
typeof data.code === 'string' ? data.code : undefined,
980+
data.code != null ? String(data.code) : undefined,
981981
'COMMAND_FAILED',
982982
),
983983
String(data.message ?? parsed.error.message ?? 'Daemon RPC request failed'),

src/utils/errors.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ export type KnownAppErrorCode =
1515
| 'AMBIGUOUS_MATCH'
1616
| 'UNKNOWN';
1717

18-
// Accepts any string so wire codes from the daemon are preserved verbatim; the
19-
// `(string & {})` form keeps IDE autocomplete of the known codes.
18+
// Intentionally widened with `(string & {})` so daemon-originated codes pass
19+
// through verbatim without requiring the SDK union to be updated first. Known
20+
// codes still autocomplete in IDEs. Tradeoff: `switch (err.code)` is no longer
21+
// exhaustive by construction — SDK consumers handling unknown codes should
22+
// include a default branch.
2023
export type AppErrorCode = KnownAppErrorCode | (string & {});
2124

2225
export function toAppErrorCode(

0 commit comments

Comments
 (0)