Skip to content

Commit 098a08f

Browse files
os-trumpclaude
andauthored
feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes (#13510)
* feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes Every machine-readable failure the CLI emits was `{ success: false, error: error.message }` and nothing else — 48 sites under `packages/cli/src/commands/`. The error reaching those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's `fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized across both server dialects) and `err.httpStatus`. Both were discarded at the CLI boundary, so a script had to substring-match an English sentence that no contract pins. One shared builder (`errorCodeFields` in `utils/format.ts`) plus 48 call-site spreads. Additive: `success` and `error` keep their meaning and spelling, the payload stays flat, and the two keys are ABSENT — not `undefined` — when the thrown error did not carry them. No fallback code is invented for a locally-thrown plain `Error`. Human `table` output is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * test(cli): give the #13347 envelope cases an explicit wall-clock budget Each case drives a real `Command.run` against the real oclif root — ~0.8s per case on an idle box, and measured TIMING OUT at vitest's 5s default when the file ran inside `@objectstack/cli`'s full 220-file suite on a shared container. Wall-clock only: no assertion moves. The neighbouring `delete-reset-carriers.test.ts` reaches the same conclusion the same way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * docs(cli): declare errorCodeFields.code's real value space — pass-through, ADR-0112 for wire failures, Node errno for local I/O Contract-review amendment on #13510: the field doc and changeset called code 'the semantic ADR-0112 code', but the builder is a structural pass-through and os validate/compile/lint throw errno-carrying fs errors inside the same try, so ENOENT/ENOTDIR are genuinely publishable values. Behaviour unchanged (the ruling's literal pass-through shape stands); only the declaration now matches it. The vocabularies are disjoint (errnos are E-prefixed OS names), so ADR-0112 branches cannot false-match an errno. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ec4c4d2 commit 098a08f

42 files changed

Lines changed: 763 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
"@objectstack/cli": minor
3+
---
4+
5+
feat(cli): `--format json` failure envelopes carry the ADR-0112 `code` and `httpStatus` (#13347)
6+
7+
Every machine-readable failure this CLI emits was built the same way — 48 sites
8+
under `packages/cli/src/commands/`:
9+
10+
```ts
11+
awaitemitJson({ success: false, error: error.message });
12+
```
13+
14+
The payload carried the human sentence and nothing else. The error reaching
15+
those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's
16+
`fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized to
17+
the same spelling across the flat `@objectstack/rest` envelope and the wrapped
18+
runtime-dispatcher one) and `err.httpStatus`. Both were discarded at the CLI
19+
boundary, so the one outcome a script most needs to branch on — *someone else
20+
edited it, re-read and retry* vs *you are not allowed* vs *the server is down*
21+
was separable only by substring-matching an English sentence that no contract
22+
pins.
23+
24+
A stale-pin refusal from `os meta delete --if-match` used to read:
25+
26+
```json
27+
{
28+
"success": false,
29+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …"
30+
}
31+
```
32+
33+
and now reads:
34+
35+
```json
36+
{
37+
"success": false,
38+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …",
39+
"code": "METADATA_CONFLICT",
40+
"httpStatus": 409
41+
}
42+
```
43+
44+
Maintainer ruling 2026-08-30 (option **A** of three):
45+
46+
- The payload stays **FLAT**. Nesting into `{ error: { code, message, httpStatus } }`
47+
was considered and declined as breaking.
48+
-`success` and `error` keep their current meaning **and spelling**.
49+
- The two keys are emitted **only when the thrown error carries them**, and are
50+
**absent** — not `undefined` — otherwise. No fallback code is invented for a
51+
locally-thrown plain `Error`: this CLI's own input refusals get no code,
52+
deliberately, because ADR-0112's ledger is the authority on who may mint one.
53+
54+
One value-space note, stated so the declaration matches what ships: `code` is a
55+
**pass-through**, never minted or filtered. On wire failures it is the semantic
56+
ADR-0112 string the SDK attached; on local I/O failures inside the same `try`
57+
(`os validate` reading a `src/docs` that is a file, say) it is the Node errno
58+
(`ENOENT`, `ENOTDIR`, …). The two vocabularies are disjoint — errnos are
59+
`E`-prefixed OS names — so a consumer branching on ADR-0112 codes cannot
60+
false-match an errno, but not every emitted `code` is ledger-owned.
61+
62+
Human (`table`) output is untouched.
63+
64+
**Why `minor` and not `patch`.** Maintainer-set, and it overrides the obvious
65+
reading: this is a shape change to an **already-published error envelope**, and
66+
that makes it minor even though it is purely additive.
67+
68+
**Migration.** Nothing is required — no key is removed, renamed or re-typed, and
69+
every payload this CLI emitted before is still emitted, byte-for-byte, minus the
70+
two new keys. Two things are worth knowing before you rely on the new ones:
71+
72+
-**The envelope is polymorphic, by design.**`code` and `httpStatus` are absent
73+
whenever the failure did not carry them, which a consumer cannot distinguish
74+
from an older CLI. Branch on presence (`if (payload.code === 'METADATA_CONFLICT')`),
75+
never on absence meaning "success" or "unsupported version". This cost was
76+
weighed against breaking every existing consumer, and the non-breaking side won.
77+
-**Stop substring-matching the sentence.**`error` is prose and no contract pins
78+
its wording; the bracketed `[metadata_conflict]` tag some messages carry today
79+
is a property of one producer, not a contract, and a separate card argues for
80+
removing it. Code that reads the sentence to classify a failure should move to
81+
`code` (with `httpStatus` as the coarse fallback).

‎packages/cli/src/commands/cloud/login.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import * as readline from 'node:readline/promises';
7373
import{stdinasinput,stdoutasoutput}from'node:process';
7474
import{Command,Flags}from'@oclif/core';
7575
importtype{CliExitCode}from'../../utils/format.js';
76-
import{printHeader,printKV,printSuccess,printError,emitJson}from'../../utils/format.js';
76+
import{printHeader,printKV,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
7777
import{loginWithBrowser,loginWithPassword}from'../../utils/auth-flows.js';
7878
import{DEFAULT_CLOUD_URL,readCloudConfig,writeCloudConfig}from'../../utils/cloud-config.js';
7979

@@ -246,7 +246,7 @@ export default class CloudLogin extends Command {
246246
// written (an expired code, a denied approval, a poll failure), so an
247247
// indented payload here would recreate a two-document stream on the
248248
// path a consumer is least able to recover from.
249-
awaitemitRecord({success: false,error: error.message});
249+
awaitemitRecord({success: false,error: error.message, ...errorCodeFields(error)});
250250
this.exit(1);
251251
}
252252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/logout.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import{Command,Flags}from'@oclif/core';
1010
import{ObjectStackClient}from'@objectstack/client';
11-
import{printHeader,printSuccess,printError,emitJson}from'../../utils/format.js';
11+
import{printHeader,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
1212
import{deleteCloudConfig,tryReadCloudConfig}from'../../utils/cloud-config.js';
1313

1414
exportdefaultclassCloudLogoutextendsCommand{
@@ -46,7 +46,7 @@ export default class CloudLogout extends Command {
4646
}
4747
}catch(error: any){
4848
if(flags.json){
49-
awaitemitJson({success: false,error: error.message});
49+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
5050
this.exit(1);
5151
}
5252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/whoami.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import{Command,Flags}from'@oclif/core';
10-
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal}from'../../utils/format.js';
10+
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal,errorCodeFields}from'../../utils/format.js';
1111
import{tryReadCloudConfig}from'../../utils/cloud-config.js';
1212

1313
exportdefaultclassCloudWhoamiextendsCommand{
@@ -72,7 +72,7 @@ export default class CloudWhoami extends Command {
7272
}catch(error: any){
7373
if(isExitSignal(error))throwerror;
7474
if(flags.json){
75-
awaitemitJson({success: false,error: error.message});
75+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
7676
this.exit(1);
7777
}
7878
printError(error.message||String(error));

‎packages/cli/src/commands/compile.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
printMetadataStats,
4040
emitJson,
4141
isExitSignal,
42+
errorCodeFields,
4243
}from'../utils/format.js';
4344
import{checkSpecVersionGap}from'../utils/spec-version.js';
4445

@@ -720,7 +721,7 @@ export default class Compile extends Command {
720721
}catch(error: any){
721722
if(isExitSignal(error))throwerror;
722723
if(flags.json){
723-
awaitemitJson({success: false,error: error.message,warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724+
awaitemitJson({success: false,error: error.message,...errorCodeFields(error),warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724725
this.exit(1);
725726
}
726727
console.log('');

‎packages/cli/src/commands/data/create.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -100,6 +100,7 @@ export default class DataCreate extends Command {
100100
awaitemitJson({
101101
success: false,
102102
error: error.message,
103+
...errorCodeFields(error),
103104
});
104105
this.exit(1);
105106
}

‎packages/cli/src/commands/data/delete.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -83,6 +83,7 @@ export default class DataDelete extends Command {
8383
awaitemitJson({
8484
success: false,
8585
error: error.message,
86+
...errorCodeFields(error),
8687
});
8788
this.exit(1);
8889
}

‎packages/cli/src/commands/data/get.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -74,6 +74,7 @@ export default class DataGet extends Command {
7474
awaitemitJson({
7575
success: false,
7676
error: error.message,
77+
...errorCodeFields(error),
7778
});
7879
this.exit(1);
7980
}

‎packages/cli/src/commands/data/query.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -117,6 +117,7 @@ export default class DataQuery extends Command {
117117
awaitemitJson({
118118
success: false,
119119
error: error.message,
120+
...errorCodeFields(error),
120121
});
121122
this.exit(1);
122123
}

‎packages/cli/src/commands/data/update.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -104,6 +104,7 @@ export default class DataUpdate extends Command {
104104
awaitemitJson({
105105
success: false,
106106
error: error.message,
107+
...errorCodeFields(error),
107108
});
108109
this.exit(1);
109110
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
feat(cli): carry the ADR-0112 code and httpStatus in `--format json` … · objectstack-ai/objectstack@098a08f · GitHub
Skip to content

Commit 098a08f

Browse files
os-trumpclaude
andauthored
feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes (#13510)
* feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes Every machine-readable failure the CLI emits was `{ success: false, error: error.message }` and nothing else — 48 sites under `packages/cli/src/commands/`. The error reaching those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's `fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized across both server dialects) and `err.httpStatus`. Both were discarded at the CLI boundary, so a script had to substring-match an English sentence that no contract pins. One shared builder (`errorCodeFields` in `utils/format.ts`) plus 48 call-site spreads. Additive: `success` and `error` keep their meaning and spelling, the payload stays flat, and the two keys are ABSENT — not `undefined` — when the thrown error did not carry them. No fallback code is invented for a locally-thrown plain `Error`. Human `table` output is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * test(cli): give the #13347 envelope cases an explicit wall-clock budget Each case drives a real `Command.run` against the real oclif root — ~0.8s per case on an idle box, and measured TIMING OUT at vitest's 5s default when the file ran inside `@objectstack/cli`'s full 220-file suite on a shared container. Wall-clock only: no assertion moves. The neighbouring `delete-reset-carriers.test.ts` reaches the same conclusion the same way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * docs(cli): declare errorCodeFields.code's real value space — pass-through, ADR-0112 for wire failures, Node errno for local I/O Contract-review amendment on #13510: the field doc and changeset called code 'the semantic ADR-0112 code', but the builder is a structural pass-through and os validate/compile/lint throw errno-carrying fs errors inside the same try, so ENOENT/ENOTDIR are genuinely publishable values. Behaviour unchanged (the ruling's literal pass-through shape stands); only the declaration now matches it. The vocabularies are disjoint (errnos are E-prefixed OS names), so ADR-0112 branches cannot false-match an errno. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ec4c4d2 commit 098a08f

42 files changed

Lines changed: 763 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
"@objectstack/cli": minor
3+
---
4+
5+
feat(cli): `--format json` failure envelopes carry the ADR-0112 `code` and `httpStatus` (#13347)
6+
7+
Every machine-readable failure this CLI emits was built the same way — 48 sites
8+
under `packages/cli/src/commands/`:
9+
10+
```ts
11+
awaitemitJson({ success: false, error: error.message });
12+
```
13+
14+
The payload carried the human sentence and nothing else. The error reaching
15+
those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's
16+
`fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized to
17+
the same spelling across the flat `@objectstack/rest` envelope and the wrapped
18+
runtime-dispatcher one) and `err.httpStatus`. Both were discarded at the CLI
19+
boundary, so the one outcome a script most needs to branch on — *someone else
20+
edited it, re-read and retry* vs *you are not allowed* vs *the server is down*
21+
was separable only by substring-matching an English sentence that no contract
22+
pins.
23+
24+
A stale-pin refusal from `os meta delete --if-match` used to read:
25+
26+
```json
27+
{
28+
"success": false,
29+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …"
30+
}
31+
```
32+
33+
and now reads:
34+
35+
```json
36+
{
37+
"success": false,
38+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …",
39+
"code": "METADATA_CONFLICT",
40+
"httpStatus": 409
41+
}
42+
```
43+
44+
Maintainer ruling 2026-08-30 (option **A** of three):
45+
46+
- The payload stays **FLAT**. Nesting into `{ error: { code, message, httpStatus } }`
47+
was considered and declined as breaking.
48+
-`success` and `error` keep their current meaning **and spelling**.
49+
- The two keys are emitted **only when the thrown error carries them**, and are
50+
**absent** — not `undefined` — otherwise. No fallback code is invented for a
51+
locally-thrown plain `Error`: this CLI's own input refusals get no code,
52+
deliberately, because ADR-0112's ledger is the authority on who may mint one.
53+
54+
One value-space note, stated so the declaration matches what ships: `code` is a
55+
**pass-through**, never minted or filtered. On wire failures it is the semantic
56+
ADR-0112 string the SDK attached; on local I/O failures inside the same `try`
57+
(`os validate` reading a `src/docs` that is a file, say) it is the Node errno
58+
(`ENOENT`, `ENOTDIR`, …). The two vocabularies are disjoint — errnos are
59+
`E`-prefixed OS names — so a consumer branching on ADR-0112 codes cannot
60+
false-match an errno, but not every emitted `code` is ledger-owned.
61+
62+
Human (`table`) output is untouched.
63+
64+
**Why `minor` and not `patch`.** Maintainer-set, and it overrides the obvious
65+
reading: this is a shape change to an **already-published error envelope**, and
66+
that makes it minor even though it is purely additive.
67+
68+
**Migration.** Nothing is required — no key is removed, renamed or re-typed, and
69+
every payload this CLI emitted before is still emitted, byte-for-byte, minus the
70+
two new keys. Two things are worth knowing before you rely on the new ones:
71+
72+
-**The envelope is polymorphic, by design.**`code` and `httpStatus` are absent
73+
whenever the failure did not carry them, which a consumer cannot distinguish
74+
from an older CLI. Branch on presence (`if (payload.code === 'METADATA_CONFLICT')`),
75+
never on absence meaning "success" or "unsupported version". This cost was
76+
weighed against breaking every existing consumer, and the non-breaking side won.
77+
-**Stop substring-matching the sentence.**`error` is prose and no contract pins
78+
its wording; the bracketed `[metadata_conflict]` tag some messages carry today
79+
is a property of one producer, not a contract, and a separate card argues for
80+
removing it. Code that reads the sentence to classify a failure should move to
81+
`code` (with `httpStatus` as the coarse fallback).

‎packages/cli/src/commands/cloud/login.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import * as readline from 'node:readline/promises';
7373
import{stdinasinput,stdoutasoutput}from'node:process';
7474
import{Command,Flags}from'@oclif/core';
7575
importtype{CliExitCode}from'../../utils/format.js';
76-
import{printHeader,printKV,printSuccess,printError,emitJson}from'../../utils/format.js';
76+
import{printHeader,printKV,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
7777
import{loginWithBrowser,loginWithPassword}from'../../utils/auth-flows.js';
7878
import{DEFAULT_CLOUD_URL,readCloudConfig,writeCloudConfig}from'../../utils/cloud-config.js';
7979

@@ -246,7 +246,7 @@ export default class CloudLogin extends Command {
246246
// written (an expired code, a denied approval, a poll failure), so an
247247
// indented payload here would recreate a two-document stream on the
248248
// path a consumer is least able to recover from.
249-
awaitemitRecord({success: false,error: error.message});
249+
awaitemitRecord({success: false,error: error.message, ...errorCodeFields(error)});
250250
this.exit(1);
251251
}
252252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/logout.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import{Command,Flags}from'@oclif/core';
1010
import{ObjectStackClient}from'@objectstack/client';
11-
import{printHeader,printSuccess,printError,emitJson}from'../../utils/format.js';
11+
import{printHeader,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
1212
import{deleteCloudConfig,tryReadCloudConfig}from'../../utils/cloud-config.js';
1313

1414
exportdefaultclassCloudLogoutextendsCommand{
@@ -46,7 +46,7 @@ export default class CloudLogout extends Command {
4646
}
4747
}catch(error: any){
4848
if(flags.json){
49-
awaitemitJson({success: false,error: error.message});
49+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
5050
this.exit(1);
5151
}
5252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/whoami.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import{Command,Flags}from'@oclif/core';
10-
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal}from'../../utils/format.js';
10+
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal,errorCodeFields}from'../../utils/format.js';
1111
import{tryReadCloudConfig}from'../../utils/cloud-config.js';
1212

1313
exportdefaultclassCloudWhoamiextendsCommand{
@@ -72,7 +72,7 @@ export default class CloudWhoami extends Command {
7272
}catch(error: any){
7373
if(isExitSignal(error))throwerror;
7474
if(flags.json){
75-
awaitemitJson({success: false,error: error.message});
75+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
7676
this.exit(1);
7777
}
7878
printError(error.message||String(error));

‎packages/cli/src/commands/compile.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
printMetadataStats,
4040
emitJson,
4141
isExitSignal,
42+
errorCodeFields,
4243
}from'../utils/format.js';
4344
import{checkSpecVersionGap}from'../utils/spec-version.js';
4445

@@ -720,7 +721,7 @@ export default class Compile extends Command {
720721
}catch(error: any){
721722
if(isExitSignal(error))throwerror;
722723
if(flags.json){
723-
awaitemitJson({success: false,error: error.message,warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724+
awaitemitJson({success: false,error: error.message,...errorCodeFields(error),warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724725
this.exit(1);
725726
}
726727
console.log('');

‎packages/cli/src/commands/data/create.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -100,6 +100,7 @@ export default class DataCreate extends Command {
100100
awaitemitJson({
101101
success: false,
102102
error: error.message,
103+
...errorCodeFields(error),
103104
});
104105
this.exit(1);
105106
}

‎packages/cli/src/commands/data/delete.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -83,6 +83,7 @@ export default class DataDelete extends Command {
8383
awaitemitJson({
8484
success: false,
8585
error: error.message,
86+
...errorCodeFields(error),
8687
});
8788
this.exit(1);
8889
}

‎packages/cli/src/commands/data/get.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -74,6 +74,7 @@ export default class DataGet extends Command {
7474
awaitemitJson({
7575
success: false,
7676
error: error.message,
77+
...errorCodeFields(error),
7778
});
7879
this.exit(1);
7980
}

‎packages/cli/src/commands/data/query.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -117,6 +117,7 @@ export default class DataQuery extends Command {
117117
awaitemitJson({
118118
success: false,
119119
error: error.message,
120+
...errorCodeFields(error),
120121
});
121122
this.exit(1);
122123
}

‎packages/cli/src/commands/data/update.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -104,6 +104,7 @@ export default class DataUpdate extends Command {
104104
awaitemitJson({
105105
success: false,
106106
error: error.message,
107+
...errorCodeFields(error),
107108
});
108109
this.exit(1);
109110
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat(cli): carry the ADR-0112 code and httpStatus in `--format json` … · objectstack-ai/objectstack@098a08f · GitHub
Skip to content

Commit 098a08f

Browse files
os-trumpclaude
andauthored
feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes (#13510)
* feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes Every machine-readable failure the CLI emits was `{ success: false, error: error.message }` and nothing else — 48 sites under `packages/cli/src/commands/`. The error reaching those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's `fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized across both server dialects) and `err.httpStatus`. Both were discarded at the CLI boundary, so a script had to substring-match an English sentence that no contract pins. One shared builder (`errorCodeFields` in `utils/format.ts`) plus 48 call-site spreads. Additive: `success` and `error` keep their meaning and spelling, the payload stays flat, and the two keys are ABSENT — not `undefined` — when the thrown error did not carry them. No fallback code is invented for a locally-thrown plain `Error`. Human `table` output is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * test(cli): give the #13347 envelope cases an explicit wall-clock budget Each case drives a real `Command.run` against the real oclif root — ~0.8s per case on an idle box, and measured TIMING OUT at vitest's 5s default when the file ran inside `@objectstack/cli`'s full 220-file suite on a shared container. Wall-clock only: no assertion moves. The neighbouring `delete-reset-carriers.test.ts` reaches the same conclusion the same way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * docs(cli): declare errorCodeFields.code's real value space — pass-through, ADR-0112 for wire failures, Node errno for local I/O Contract-review amendment on #13510: the field doc and changeset called code 'the semantic ADR-0112 code', but the builder is a structural pass-through and os validate/compile/lint throw errno-carrying fs errors inside the same try, so ENOENT/ENOTDIR are genuinely publishable values. Behaviour unchanged (the ruling's literal pass-through shape stands); only the declaration now matches it. The vocabularies are disjoint (errnos are E-prefixed OS names), so ADR-0112 branches cannot false-match an errno. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ec4c4d2 commit 098a08f

42 files changed

Lines changed: 763 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
"@objectstack/cli": minor
3+
---
4+
5+
feat(cli): `--format json` failure envelopes carry the ADR-0112 `code` and `httpStatus` (#13347)
6+
7+
Every machine-readable failure this CLI emits was built the same way — 48 sites
8+
under `packages/cli/src/commands/`:
9+
10+
```ts
11+
awaitemitJson({ success: false, error: error.message });
12+
```
13+
14+
The payload carried the human sentence and nothing else. The error reaching
15+
those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's
16+
`fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized to
17+
the same spelling across the flat `@objectstack/rest` envelope and the wrapped
18+
runtime-dispatcher one) and `err.httpStatus`. Both were discarded at the CLI
19+
boundary, so the one outcome a script most needs to branch on — *someone else
20+
edited it, re-read and retry* vs *you are not allowed* vs *the server is down*
21+
was separable only by substring-matching an English sentence that no contract
22+
pins.
23+
24+
A stale-pin refusal from `os meta delete --if-match` used to read:
25+
26+
```json
27+
{
28+
"success": false,
29+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …"
30+
}
31+
```
32+
33+
and now reads:
34+
35+
```json
36+
{
37+
"success": false,
38+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …",
39+
"code": "METADATA_CONFLICT",
40+
"httpStatus": 409
41+
}
42+
```
43+
44+
Maintainer ruling 2026-08-30 (option **A** of three):
45+
46+
- The payload stays **FLAT**. Nesting into `{ error: { code, message, httpStatus } }`
47+
was considered and declined as breaking.
48+
-`success` and `error` keep their current meaning **and spelling**.
49+
- The two keys are emitted **only when the thrown error carries them**, and are
50+
**absent** — not `undefined` — otherwise. No fallback code is invented for a
51+
locally-thrown plain `Error`: this CLI's own input refusals get no code,
52+
deliberately, because ADR-0112's ledger is the authority on who may mint one.
53+
54+
One value-space note, stated so the declaration matches what ships: `code` is a
55+
**pass-through**, never minted or filtered. On wire failures it is the semantic
56+
ADR-0112 string the SDK attached; on local I/O failures inside the same `try`
57+
(`os validate` reading a `src/docs` that is a file, say) it is the Node errno
58+
(`ENOENT`, `ENOTDIR`, …). The two vocabularies are disjoint — errnos are
59+
`E`-prefixed OS names — so a consumer branching on ADR-0112 codes cannot
60+
false-match an errno, but not every emitted `code` is ledger-owned.
61+
62+
Human (`table`) output is untouched.
63+
64+
**Why `minor` and not `patch`.** Maintainer-set, and it overrides the obvious
65+
reading: this is a shape change to an **already-published error envelope**, and
66+
that makes it minor even though it is purely additive.
67+
68+
**Migration.** Nothing is required — no key is removed, renamed or re-typed, and
69+
every payload this CLI emitted before is still emitted, byte-for-byte, minus the
70+
two new keys. Two things are worth knowing before you rely on the new ones:
71+
72+
-**The envelope is polymorphic, by design.**`code` and `httpStatus` are absent
73+
whenever the failure did not carry them, which a consumer cannot distinguish
74+
from an older CLI. Branch on presence (`if (payload.code === 'METADATA_CONFLICT')`),
75+
never on absence meaning "success" or "unsupported version". This cost was
76+
weighed against breaking every existing consumer, and the non-breaking side won.
77+
-**Stop substring-matching the sentence.**`error` is prose and no contract pins
78+
its wording; the bracketed `[metadata_conflict]` tag some messages carry today
79+
is a property of one producer, not a contract, and a separate card argues for
80+
removing it. Code that reads the sentence to classify a failure should move to
81+
`code` (with `httpStatus` as the coarse fallback).

‎packages/cli/src/commands/cloud/login.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import * as readline from 'node:readline/promises';
7373
import{stdinasinput,stdoutasoutput}from'node:process';
7474
import{Command,Flags}from'@oclif/core';
7575
importtype{CliExitCode}from'../../utils/format.js';
76-
import{printHeader,printKV,printSuccess,printError,emitJson}from'../../utils/format.js';
76+
import{printHeader,printKV,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
7777
import{loginWithBrowser,loginWithPassword}from'../../utils/auth-flows.js';
7878
import{DEFAULT_CLOUD_URL,readCloudConfig,writeCloudConfig}from'../../utils/cloud-config.js';
7979

@@ -246,7 +246,7 @@ export default class CloudLogin extends Command {
246246
// written (an expired code, a denied approval, a poll failure), so an
247247
// indented payload here would recreate a two-document stream on the
248248
// path a consumer is least able to recover from.
249-
awaitemitRecord({success: false,error: error.message});
249+
awaitemitRecord({success: false,error: error.message, ...errorCodeFields(error)});
250250
this.exit(1);
251251
}
252252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/logout.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import{Command,Flags}from'@oclif/core';
1010
import{ObjectStackClient}from'@objectstack/client';
11-
import{printHeader,printSuccess,printError,emitJson}from'../../utils/format.js';
11+
import{printHeader,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
1212
import{deleteCloudConfig,tryReadCloudConfig}from'../../utils/cloud-config.js';
1313

1414
exportdefaultclassCloudLogoutextendsCommand{
@@ -46,7 +46,7 @@ export default class CloudLogout extends Command {
4646
}
4747
}catch(error: any){
4848
if(flags.json){
49-
awaitemitJson({success: false,error: error.message});
49+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
5050
this.exit(1);
5151
}
5252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/whoami.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import{Command,Flags}from'@oclif/core';
10-
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal}from'../../utils/format.js';
10+
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal,errorCodeFields}from'../../utils/format.js';
1111
import{tryReadCloudConfig}from'../../utils/cloud-config.js';
1212

1313
exportdefaultclassCloudWhoamiextendsCommand{
@@ -72,7 +72,7 @@ export default class CloudWhoami extends Command {
7272
}catch(error: any){
7373
if(isExitSignal(error))throwerror;
7474
if(flags.json){
75-
awaitemitJson({success: false,error: error.message});
75+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
7676
this.exit(1);
7777
}
7878
printError(error.message||String(error));

‎packages/cli/src/commands/compile.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
printMetadataStats,
4040
emitJson,
4141
isExitSignal,
42+
errorCodeFields,
4243
}from'../utils/format.js';
4344
import{checkSpecVersionGap}from'../utils/spec-version.js';
4445

@@ -720,7 +721,7 @@ export default class Compile extends Command {
720721
}catch(error: any){
721722
if(isExitSignal(error))throwerror;
722723
if(flags.json){
723-
awaitemitJson({success: false,error: error.message,warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724+
awaitemitJson({success: false,error: error.message,...errorCodeFields(error),warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724725
this.exit(1);
725726
}
726727
console.log('');

‎packages/cli/src/commands/data/create.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -100,6 +100,7 @@ export default class DataCreate extends Command {
100100
awaitemitJson({
101101
success: false,
102102
error: error.message,
103+
...errorCodeFields(error),
103104
});
104105
this.exit(1);
105106
}

‎packages/cli/src/commands/data/delete.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -83,6 +83,7 @@ export default class DataDelete extends Command {
8383
awaitemitJson({
8484
success: false,
8585
error: error.message,
86+
...errorCodeFields(error),
8687
});
8788
this.exit(1);
8889
}

‎packages/cli/src/commands/data/get.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -74,6 +74,7 @@ export default class DataGet extends Command {
7474
awaitemitJson({
7575
success: false,
7676
error: error.message,
77+
...errorCodeFields(error),
7778
});
7879
this.exit(1);
7980
}

‎packages/cli/src/commands/data/query.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -117,6 +117,7 @@ export default class DataQuery extends Command {
117117
awaitemitJson({
118118
success: false,
119119
error: error.message,
120+
...errorCodeFields(error),
120121
});
121122
this.exit(1);
122123
}

‎packages/cli/src/commands/data/update.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -104,6 +104,7 @@ export default class DataUpdate extends Command {
104104
awaitemitJson({
105105
success: false,
106106
error: error.message,
107+
...errorCodeFields(error),
107108
});
108109
this.exit(1);
109110
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat(cli): carry the ADR-0112 code and httpStatus in `--format json` … · objectstack-ai/objectstack@098a08f · GitHub
Skip to content

Commit 098a08f

Browse files
os-trumpclaude
andauthored
feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes (#13510)
* feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes Every machine-readable failure the CLI emits was `{ success: false, error: error.message }` and nothing else — 48 sites under `packages/cli/src/commands/`. The error reaching those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's `fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized across both server dialects) and `err.httpStatus`. Both were discarded at the CLI boundary, so a script had to substring-match an English sentence that no contract pins. One shared builder (`errorCodeFields` in `utils/format.ts`) plus 48 call-site spreads. Additive: `success` and `error` keep their meaning and spelling, the payload stays flat, and the two keys are ABSENT — not `undefined` — when the thrown error did not carry them. No fallback code is invented for a locally-thrown plain `Error`. Human `table` output is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * test(cli): give the #13347 envelope cases an explicit wall-clock budget Each case drives a real `Command.run` against the real oclif root — ~0.8s per case on an idle box, and measured TIMING OUT at vitest's 5s default when the file ran inside `@objectstack/cli`'s full 220-file suite on a shared container. Wall-clock only: no assertion moves. The neighbouring `delete-reset-carriers.test.ts` reaches the same conclusion the same way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * docs(cli): declare errorCodeFields.code's real value space — pass-through, ADR-0112 for wire failures, Node errno for local I/O Contract-review amendment on #13510: the field doc and changeset called code 'the semantic ADR-0112 code', but the builder is a structural pass-through and os validate/compile/lint throw errno-carrying fs errors inside the same try, so ENOENT/ENOTDIR are genuinely publishable values. Behaviour unchanged (the ruling's literal pass-through shape stands); only the declaration now matches it. The vocabularies are disjoint (errnos are E-prefixed OS names), so ADR-0112 branches cannot false-match an errno. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ec4c4d2 commit 098a08f

42 files changed

Lines changed: 763 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
"@objectstack/cli": minor
3+
---
4+
5+
feat(cli): `--format json` failure envelopes carry the ADR-0112 `code` and `httpStatus` (#13347)
6+
7+
Every machine-readable failure this CLI emits was built the same way — 48 sites
8+
under `packages/cli/src/commands/`:
9+
10+
```ts
11+
awaitemitJson({ success: false, error: error.message });
12+
```
13+
14+
The payload carried the human sentence and nothing else. The error reaching
15+
those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's
16+
`fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized to
17+
the same spelling across the flat `@objectstack/rest` envelope and the wrapped
18+
runtime-dispatcher one) and `err.httpStatus`. Both were discarded at the CLI
19+
boundary, so the one outcome a script most needs to branch on — *someone else
20+
edited it, re-read and retry* vs *you are not allowed* vs *the server is down*
21+
was separable only by substring-matching an English sentence that no contract
22+
pins.
23+
24+
A stale-pin refusal from `os meta delete --if-match` used to read:
25+
26+
```json
27+
{
28+
"success": false,
29+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …"
30+
}
31+
```
32+
33+
and now reads:
34+
35+
```json
36+
{
37+
"success": false,
38+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …",
39+
"code": "METADATA_CONFLICT",
40+
"httpStatus": 409
41+
}
42+
```
43+
44+
Maintainer ruling 2026-08-30 (option **A** of three):
45+
46+
- The payload stays **FLAT**. Nesting into `{ error: { code, message, httpStatus } }`
47+
was considered and declined as breaking.
48+
-`success` and `error` keep their current meaning **and spelling**.
49+
- The two keys are emitted **only when the thrown error carries them**, and are
50+
**absent** — not `undefined` — otherwise. No fallback code is invented for a
51+
locally-thrown plain `Error`: this CLI's own input refusals get no code,
52+
deliberately, because ADR-0112's ledger is the authority on who may mint one.
53+
54+
One value-space note, stated so the declaration matches what ships: `code` is a
55+
**pass-through**, never minted or filtered. On wire failures it is the semantic
56+
ADR-0112 string the SDK attached; on local I/O failures inside the same `try`
57+
(`os validate` reading a `src/docs` that is a file, say) it is the Node errno
58+
(`ENOENT`, `ENOTDIR`, …). The two vocabularies are disjoint — errnos are
59+
`E`-prefixed OS names — so a consumer branching on ADR-0112 codes cannot
60+
false-match an errno, but not every emitted `code` is ledger-owned.
61+
62+
Human (`table`) output is untouched.
63+
64+
**Why `minor` and not `patch`.** Maintainer-set, and it overrides the obvious
65+
reading: this is a shape change to an **already-published error envelope**, and
66+
that makes it minor even though it is purely additive.
67+
68+
**Migration.** Nothing is required — no key is removed, renamed or re-typed, and
69+
every payload this CLI emitted before is still emitted, byte-for-byte, minus the
70+
two new keys. Two things are worth knowing before you rely on the new ones:
71+
72+
-**The envelope is polymorphic, by design.**`code` and `httpStatus` are absent
73+
whenever the failure did not carry them, which a consumer cannot distinguish
74+
from an older CLI. Branch on presence (`if (payload.code === 'METADATA_CONFLICT')`),
75+
never on absence meaning "success" or "unsupported version". This cost was
76+
weighed against breaking every existing consumer, and the non-breaking side won.
77+
-**Stop substring-matching the sentence.**`error` is prose and no contract pins
78+
its wording; the bracketed `[metadata_conflict]` tag some messages carry today
79+
is a property of one producer, not a contract, and a separate card argues for
80+
removing it. Code that reads the sentence to classify a failure should move to
81+
`code` (with `httpStatus` as the coarse fallback).

‎packages/cli/src/commands/cloud/login.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import * as readline from 'node:readline/promises';
7373
import{stdinasinput,stdoutasoutput}from'node:process';
7474
import{Command,Flags}from'@oclif/core';
7575
importtype{CliExitCode}from'../../utils/format.js';
76-
import{printHeader,printKV,printSuccess,printError,emitJson}from'../../utils/format.js';
76+
import{printHeader,printKV,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
7777
import{loginWithBrowser,loginWithPassword}from'../../utils/auth-flows.js';
7878
import{DEFAULT_CLOUD_URL,readCloudConfig,writeCloudConfig}from'../../utils/cloud-config.js';
7979

@@ -246,7 +246,7 @@ export default class CloudLogin extends Command {
246246
// written (an expired code, a denied approval, a poll failure), so an
247247
// indented payload here would recreate a two-document stream on the
248248
// path a consumer is least able to recover from.
249-
awaitemitRecord({success: false,error: error.message});
249+
awaitemitRecord({success: false,error: error.message, ...errorCodeFields(error)});
250250
this.exit(1);
251251
}
252252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/logout.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import{Command,Flags}from'@oclif/core';
1010
import{ObjectStackClient}from'@objectstack/client';
11-
import{printHeader,printSuccess,printError,emitJson}from'../../utils/format.js';
11+
import{printHeader,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
1212
import{deleteCloudConfig,tryReadCloudConfig}from'../../utils/cloud-config.js';
1313

1414
exportdefaultclassCloudLogoutextendsCommand{
@@ -46,7 +46,7 @@ export default class CloudLogout extends Command {
4646
}
4747
}catch(error: any){
4848
if(flags.json){
49-
awaitemitJson({success: false,error: error.message});
49+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
5050
this.exit(1);
5151
}
5252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/whoami.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import{Command,Flags}from'@oclif/core';
10-
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal}from'../../utils/format.js';
10+
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal,errorCodeFields}from'../../utils/format.js';
1111
import{tryReadCloudConfig}from'../../utils/cloud-config.js';
1212

1313
exportdefaultclassCloudWhoamiextendsCommand{
@@ -72,7 +72,7 @@ export default class CloudWhoami extends Command {
7272
}catch(error: any){
7373
if(isExitSignal(error))throwerror;
7474
if(flags.json){
75-
awaitemitJson({success: false,error: error.message});
75+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
7676
this.exit(1);
7777
}
7878
printError(error.message||String(error));

‎packages/cli/src/commands/compile.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
printMetadataStats,
4040
emitJson,
4141
isExitSignal,
42+
errorCodeFields,
4243
}from'../utils/format.js';
4344
import{checkSpecVersionGap}from'../utils/spec-version.js';
4445

@@ -720,7 +721,7 @@ export default class Compile extends Command {
720721
}catch(error: any){
721722
if(isExitSignal(error))throwerror;
722723
if(flags.json){
723-
awaitemitJson({success: false,error: error.message,warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724+
awaitemitJson({success: false,error: error.message,...errorCodeFields(error),warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724725
this.exit(1);
725726
}
726727
console.log('');

‎packages/cli/src/commands/data/create.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -100,6 +100,7 @@ export default class DataCreate extends Command {
100100
awaitemitJson({
101101
success: false,
102102
error: error.message,
103+
...errorCodeFields(error),
103104
});
104105
this.exit(1);
105106
}

‎packages/cli/src/commands/data/delete.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -83,6 +83,7 @@ export default class DataDelete extends Command {
8383
awaitemitJson({
8484
success: false,
8585
error: error.message,
86+
...errorCodeFields(error),
8687
});
8788
this.exit(1);
8889
}

‎packages/cli/src/commands/data/get.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -74,6 +74,7 @@ export default class DataGet extends Command {
7474
awaitemitJson({
7575
success: false,
7676
error: error.message,
77+
...errorCodeFields(error),
7778
});
7879
this.exit(1);
7980
}

‎packages/cli/src/commands/data/query.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -117,6 +117,7 @@ export default class DataQuery extends Command {
117117
awaitemitJson({
118118
success: false,
119119
error: error.message,
120+
...errorCodeFields(error),
120121
});
121122
this.exit(1);
122123
}

‎packages/cli/src/commands/data/update.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -104,6 +104,7 @@ export default class DataUpdate extends Command {
104104
awaitemitJson({
105105
success: false,
106106
error: error.message,
107+
...errorCodeFields(error),
107108
});
108109
this.exit(1);
109110
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' feat(cli): carry the ADR-0112 code and httpStatus in `--format json` … · objectstack-ai/objectstack@098a08f · GitHub
Skip to content

Commit 098a08f

Browse files
os-trumpclaude
andauthored
feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes (#13510)
* feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes Every machine-readable failure the CLI emits was `{ success: false, error: error.message }` and nothing else — 48 sites under `packages/cli/src/commands/`. The error reaching those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's `fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized across both server dialects) and `err.httpStatus`. Both were discarded at the CLI boundary, so a script had to substring-match an English sentence that no contract pins. One shared builder (`errorCodeFields` in `utils/format.ts`) plus 48 call-site spreads. Additive: `success` and `error` keep their meaning and spelling, the payload stays flat, and the two keys are ABSENT — not `undefined` — when the thrown error did not carry them. No fallback code is invented for a locally-thrown plain `Error`. Human `table` output is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * test(cli): give the #13347 envelope cases an explicit wall-clock budget Each case drives a real `Command.run` against the real oclif root — ~0.8s per case on an idle box, and measured TIMING OUT at vitest's 5s default when the file ran inside `@objectstack/cli`'s full 220-file suite on a shared container. Wall-clock only: no assertion moves. The neighbouring `delete-reset-carriers.test.ts` reaches the same conclusion the same way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * docs(cli): declare errorCodeFields.code's real value space — pass-through, ADR-0112 for wire failures, Node errno for local I/O Contract-review amendment on #13510: the field doc and changeset called code 'the semantic ADR-0112 code', but the builder is a structural pass-through and os validate/compile/lint throw errno-carrying fs errors inside the same try, so ENOENT/ENOTDIR are genuinely publishable values. Behaviour unchanged (the ruling's literal pass-through shape stands); only the declaration now matches it. The vocabularies are disjoint (errnos are E-prefixed OS names), so ADR-0112 branches cannot false-match an errno. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ec4c4d2 commit 098a08f

42 files changed

Lines changed: 763 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
"@objectstack/cli": minor
3+
---
4+
5+
feat(cli): `--format json` failure envelopes carry the ADR-0112 `code` and `httpStatus` (#13347)
6+
7+
Every machine-readable failure this CLI emits was built the same way — 48 sites
8+
under `packages/cli/src/commands/`:
9+
10+
```ts
11+
awaitemitJson({ success: false, error: error.message });
12+
```
13+
14+
The payload carried the human sentence and nothing else. The error reaching
15+
those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's
16+
`fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized to
17+
the same spelling across the flat `@objectstack/rest` envelope and the wrapped
18+
runtime-dispatcher one) and `err.httpStatus`. Both were discarded at the CLI
19+
boundary, so the one outcome a script most needs to branch on — *someone else
20+
edited it, re-read and retry* vs *you are not allowed* vs *the server is down*
21+
was separable only by substring-matching an English sentence that no contract
22+
pins.
23+
24+
A stale-pin refusal from `os meta delete --if-match` used to read:
25+
26+
```json
27+
{
28+
"success": false,
29+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …"
30+
}
31+
```
32+
33+
and now reads:
34+
35+
```json
36+
{
37+
"success": false,
38+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …",
39+
"code": "METADATA_CONFLICT",
40+
"httpStatus": 409
41+
}
42+
```
43+
44+
Maintainer ruling 2026-08-30 (option **A** of three):
45+
46+
- The payload stays **FLAT**. Nesting into `{ error: { code, message, httpStatus } }`
47+
was considered and declined as breaking.
48+
-`success` and `error` keep their current meaning **and spelling**.
49+
- The two keys are emitted **only when the thrown error carries them**, and are
50+
**absent** — not `undefined` — otherwise. No fallback code is invented for a
51+
locally-thrown plain `Error`: this CLI's own input refusals get no code,
52+
deliberately, because ADR-0112's ledger is the authority on who may mint one.
53+
54+
One value-space note, stated so the declaration matches what ships: `code` is a
55+
**pass-through**, never minted or filtered. On wire failures it is the semantic
56+
ADR-0112 string the SDK attached; on local I/O failures inside the same `try`
57+
(`os validate` reading a `src/docs` that is a file, say) it is the Node errno
58+
(`ENOENT`, `ENOTDIR`, …). The two vocabularies are disjoint — errnos are
59+
`E`-prefixed OS names — so a consumer branching on ADR-0112 codes cannot
60+
false-match an errno, but not every emitted `code` is ledger-owned.
61+
62+
Human (`table`) output is untouched.
63+
64+
**Why `minor` and not `patch`.** Maintainer-set, and it overrides the obvious
65+
reading: this is a shape change to an **already-published error envelope**, and
66+
that makes it minor even though it is purely additive.
67+
68+
**Migration.** Nothing is required — no key is removed, renamed or re-typed, and
69+
every payload this CLI emitted before is still emitted, byte-for-byte, minus the
70+
two new keys. Two things are worth knowing before you rely on the new ones:
71+
72+
-**The envelope is polymorphic, by design.**`code` and `httpStatus` are absent
73+
whenever the failure did not carry them, which a consumer cannot distinguish
74+
from an older CLI. Branch on presence (`if (payload.code === 'METADATA_CONFLICT')`),
75+
never on absence meaning "success" or "unsupported version". This cost was
76+
weighed against breaking every existing consumer, and the non-breaking side won.
77+
-**Stop substring-matching the sentence.**`error` is prose and no contract pins
78+
its wording; the bracketed `[metadata_conflict]` tag some messages carry today
79+
is a property of one producer, not a contract, and a separate card argues for
80+
removing it. Code that reads the sentence to classify a failure should move to
81+
`code` (with `httpStatus` as the coarse fallback).

‎packages/cli/src/commands/cloud/login.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import * as readline from 'node:readline/promises';
7373
import{stdinasinput,stdoutasoutput}from'node:process';
7474
import{Command,Flags}from'@oclif/core';
7575
importtype{CliExitCode}from'../../utils/format.js';
76-
import{printHeader,printKV,printSuccess,printError,emitJson}from'../../utils/format.js';
76+
import{printHeader,printKV,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
7777
import{loginWithBrowser,loginWithPassword}from'../../utils/auth-flows.js';
7878
import{DEFAULT_CLOUD_URL,readCloudConfig,writeCloudConfig}from'../../utils/cloud-config.js';
7979

@@ -246,7 +246,7 @@ export default class CloudLogin extends Command {
246246
// written (an expired code, a denied approval, a poll failure), so an
247247
// indented payload here would recreate a two-document stream on the
248248
// path a consumer is least able to recover from.
249-
awaitemitRecord({success: false,error: error.message});
249+
awaitemitRecord({success: false,error: error.message, ...errorCodeFields(error)});
250250
this.exit(1);
251251
}
252252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/logout.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import{Command,Flags}from'@oclif/core';
1010
import{ObjectStackClient}from'@objectstack/client';
11-
import{printHeader,printSuccess,printError,emitJson}from'../../utils/format.js';
11+
import{printHeader,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
1212
import{deleteCloudConfig,tryReadCloudConfig}from'../../utils/cloud-config.js';
1313

1414
exportdefaultclassCloudLogoutextendsCommand{
@@ -46,7 +46,7 @@ export default class CloudLogout extends Command {
4646
}
4747
}catch(error: any){
4848
if(flags.json){
49-
awaitemitJson({success: false,error: error.message});
49+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
5050
this.exit(1);
5151
}
5252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/whoami.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import{Command,Flags}from'@oclif/core';
10-
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal}from'../../utils/format.js';
10+
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal,errorCodeFields}from'../../utils/format.js';
1111
import{tryReadCloudConfig}from'../../utils/cloud-config.js';
1212

1313
exportdefaultclassCloudWhoamiextendsCommand{
@@ -72,7 +72,7 @@ export default class CloudWhoami extends Command {
7272
}catch(error: any){
7373
if(isExitSignal(error))throwerror;
7474
if(flags.json){
75-
awaitemitJson({success: false,error: error.message});
75+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
7676
this.exit(1);
7777
}
7878
printError(error.message||String(error));

‎packages/cli/src/commands/compile.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
printMetadataStats,
4040
emitJson,
4141
isExitSignal,
42+
errorCodeFields,
4243
}from'../utils/format.js';
4344
import{checkSpecVersionGap}from'../utils/spec-version.js';
4445

@@ -720,7 +721,7 @@ export default class Compile extends Command {
720721
}catch(error: any){
721722
if(isExitSignal(error))throwerror;
722723
if(flags.json){
723-
awaitemitJson({success: false,error: error.message,warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724+
awaitemitJson({success: false,error: error.message,...errorCodeFields(error),warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724725
this.exit(1);
725726
}
726727
console.log('');

‎packages/cli/src/commands/data/create.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -100,6 +100,7 @@ export default class DataCreate extends Command {
100100
awaitemitJson({
101101
success: false,
102102
error: error.message,
103+
...errorCodeFields(error),
103104
});
104105
this.exit(1);
105106
}

‎packages/cli/src/commands/data/delete.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -83,6 +83,7 @@ export default class DataDelete extends Command {
8383
awaitemitJson({
8484
success: false,
8585
error: error.message,
86+
...errorCodeFields(error),
8687
});
8788
this.exit(1);
8889
}

‎packages/cli/src/commands/data/get.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -74,6 +74,7 @@ export default class DataGet extends Command {
7474
awaitemitJson({
7575
success: false,
7676
error: error.message,
77+
...errorCodeFields(error),
7778
});
7879
this.exit(1);
7980
}

‎packages/cli/src/commands/data/query.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -117,6 +117,7 @@ export default class DataQuery extends Command {
117117
awaitemitJson({
118118
success: false,
119119
error: error.message,
120+
...errorCodeFields(error),
120121
});
121122
this.exit(1);
122123
}

‎packages/cli/src/commands/data/update.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -104,6 +104,7 @@ export default class DataUpdate extends Command {
104104
awaitemitJson({
105105
success: false,
106106
error: error.message,
107+
...errorCodeFields(error),
107108
});
108109
this.exit(1);
109110
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat(cli): carry the ADR-0112 code and httpStatus in `--format json` … · objectstack-ai/objectstack@098a08f · GitHub
Skip to content

Commit 098a08f

Browse files
os-trumpclaude
andauthored
feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes (#13510)
* feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes Every machine-readable failure the CLI emits was `{ success: false, error: error.message }` and nothing else — 48 sites under `packages/cli/src/commands/`. The error reaching those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's `fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized across both server dialects) and `err.httpStatus`. Both were discarded at the CLI boundary, so a script had to substring-match an English sentence that no contract pins. One shared builder (`errorCodeFields` in `utils/format.ts`) plus 48 call-site spreads. Additive: `success` and `error` keep their meaning and spelling, the payload stays flat, and the two keys are ABSENT — not `undefined` — when the thrown error did not carry them. No fallback code is invented for a locally-thrown plain `Error`. Human `table` output is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * test(cli): give the #13347 envelope cases an explicit wall-clock budget Each case drives a real `Command.run` against the real oclif root — ~0.8s per case on an idle box, and measured TIMING OUT at vitest's 5s default when the file ran inside `@objectstack/cli`'s full 220-file suite on a shared container. Wall-clock only: no assertion moves. The neighbouring `delete-reset-carriers.test.ts` reaches the same conclusion the same way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * docs(cli): declare errorCodeFields.code's real value space — pass-through, ADR-0112 for wire failures, Node errno for local I/O Contract-review amendment on #13510: the field doc and changeset called code 'the semantic ADR-0112 code', but the builder is a structural pass-through and os validate/compile/lint throw errno-carrying fs errors inside the same try, so ENOENT/ENOTDIR are genuinely publishable values. Behaviour unchanged (the ruling's literal pass-through shape stands); only the declaration now matches it. The vocabularies are disjoint (errnos are E-prefixed OS names), so ADR-0112 branches cannot false-match an errno. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ec4c4d2 commit 098a08f

42 files changed

Lines changed: 763 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
"@objectstack/cli": minor
3+
---
4+
5+
feat(cli): `--format json` failure envelopes carry the ADR-0112 `code` and `httpStatus` (#13347)
6+
7+
Every machine-readable failure this CLI emits was built the same way — 48 sites
8+
under `packages/cli/src/commands/`:
9+
10+
```ts
11+
awaitemitJson({ success: false, error: error.message });
12+
```
13+
14+
The payload carried the human sentence and nothing else. The error reaching
15+
those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's
16+
`fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized to
17+
the same spelling across the flat `@objectstack/rest` envelope and the wrapped
18+
runtime-dispatcher one) and `err.httpStatus`. Both were discarded at the CLI
19+
boundary, so the one outcome a script most needs to branch on — *someone else
20+
edited it, re-read and retry* vs *you are not allowed* vs *the server is down*
21+
was separable only by substring-matching an English sentence that no contract
22+
pins.
23+
24+
A stale-pin refusal from `os meta delete --if-match` used to read:
25+
26+
```json
27+
{
28+
"success": false,
29+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …"
30+
}
31+
```
32+
33+
and now reads:
34+
35+
```json
36+
{
37+
"success": false,
38+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …",
39+
"code": "METADATA_CONFLICT",
40+
"httpStatus": 409
41+
}
42+
```
43+
44+
Maintainer ruling 2026-08-30 (option **A** of three):
45+
46+
- The payload stays **FLAT**. Nesting into `{ error: { code, message, httpStatus } }`
47+
was considered and declined as breaking.
48+
-`success` and `error` keep their current meaning **and spelling**.
49+
- The two keys are emitted **only when the thrown error carries them**, and are
50+
**absent** — not `undefined` — otherwise. No fallback code is invented for a
51+
locally-thrown plain `Error`: this CLI's own input refusals get no code,
52+
deliberately, because ADR-0112's ledger is the authority on who may mint one.
53+
54+
One value-space note, stated so the declaration matches what ships: `code` is a
55+
**pass-through**, never minted or filtered. On wire failures it is the semantic
56+
ADR-0112 string the SDK attached; on local I/O failures inside the same `try`
57+
(`os validate` reading a `src/docs` that is a file, say) it is the Node errno
58+
(`ENOENT`, `ENOTDIR`, …). The two vocabularies are disjoint — errnos are
59+
`E`-prefixed OS names — so a consumer branching on ADR-0112 codes cannot
60+
false-match an errno, but not every emitted `code` is ledger-owned.
61+
62+
Human (`table`) output is untouched.
63+
64+
**Why `minor` and not `patch`.** Maintainer-set, and it overrides the obvious
65+
reading: this is a shape change to an **already-published error envelope**, and
66+
that makes it minor even though it is purely additive.
67+
68+
**Migration.** Nothing is required — no key is removed, renamed or re-typed, and
69+
every payload this CLI emitted before is still emitted, byte-for-byte, minus the
70+
two new keys. Two things are worth knowing before you rely on the new ones:
71+
72+
-**The envelope is polymorphic, by design.**`code` and `httpStatus` are absent
73+
whenever the failure did not carry them, which a consumer cannot distinguish
74+
from an older CLI. Branch on presence (`if (payload.code === 'METADATA_CONFLICT')`),
75+
never on absence meaning "success" or "unsupported version". This cost was
76+
weighed against breaking every existing consumer, and the non-breaking side won.
77+
-**Stop substring-matching the sentence.**`error` is prose and no contract pins
78+
its wording; the bracketed `[metadata_conflict]` tag some messages carry today
79+
is a property of one producer, not a contract, and a separate card argues for
80+
removing it. Code that reads the sentence to classify a failure should move to
81+
`code` (with `httpStatus` as the coarse fallback).

‎packages/cli/src/commands/cloud/login.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import * as readline from 'node:readline/promises';
7373
import{stdinasinput,stdoutasoutput}from'node:process';
7474
import{Command,Flags}from'@oclif/core';
7575
importtype{CliExitCode}from'../../utils/format.js';
76-
import{printHeader,printKV,printSuccess,printError,emitJson}from'../../utils/format.js';
76+
import{printHeader,printKV,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
7777
import{loginWithBrowser,loginWithPassword}from'../../utils/auth-flows.js';
7878
import{DEFAULT_CLOUD_URL,readCloudConfig,writeCloudConfig}from'../../utils/cloud-config.js';
7979

@@ -246,7 +246,7 @@ export default class CloudLogin extends Command {
246246
// written (an expired code, a denied approval, a poll failure), so an
247247
// indented payload here would recreate a two-document stream on the
248248
// path a consumer is least able to recover from.
249-
awaitemitRecord({success: false,error: error.message});
249+
awaitemitRecord({success: false,error: error.message, ...errorCodeFields(error)});
250250
this.exit(1);
251251
}
252252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/logout.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import{Command,Flags}from'@oclif/core';
1010
import{ObjectStackClient}from'@objectstack/client';
11-
import{printHeader,printSuccess,printError,emitJson}from'../../utils/format.js';
11+
import{printHeader,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
1212
import{deleteCloudConfig,tryReadCloudConfig}from'../../utils/cloud-config.js';
1313

1414
exportdefaultclassCloudLogoutextendsCommand{
@@ -46,7 +46,7 @@ export default class CloudLogout extends Command {
4646
}
4747
}catch(error: any){
4848
if(flags.json){
49-
awaitemitJson({success: false,error: error.message});
49+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
5050
this.exit(1);
5151
}
5252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/whoami.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import{Command,Flags}from'@oclif/core';
10-
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal}from'../../utils/format.js';
10+
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal,errorCodeFields}from'../../utils/format.js';
1111
import{tryReadCloudConfig}from'../../utils/cloud-config.js';
1212

1313
exportdefaultclassCloudWhoamiextendsCommand{
@@ -72,7 +72,7 @@ export default class CloudWhoami extends Command {
7272
}catch(error: any){
7373
if(isExitSignal(error))throwerror;
7474
if(flags.json){
75-
awaitemitJson({success: false,error: error.message});
75+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
7676
this.exit(1);
7777
}
7878
printError(error.message||String(error));

‎packages/cli/src/commands/compile.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
printMetadataStats,
4040
emitJson,
4141
isExitSignal,
42+
errorCodeFields,
4243
}from'../utils/format.js';
4344
import{checkSpecVersionGap}from'../utils/spec-version.js';
4445

@@ -720,7 +721,7 @@ export default class Compile extends Command {
720721
}catch(error: any){
721722
if(isExitSignal(error))throwerror;
722723
if(flags.json){
723-
awaitemitJson({success: false,error: error.message,warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724+
awaitemitJson({success: false,error: error.message,...errorCodeFields(error),warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724725
this.exit(1);
725726
}
726727
console.log('');

‎packages/cli/src/commands/data/create.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -100,6 +100,7 @@ export default class DataCreate extends Command {
100100
awaitemitJson({
101101
success: false,
102102
error: error.message,
103+
...errorCodeFields(error),
103104
});
104105
this.exit(1);
105106
}

‎packages/cli/src/commands/data/delete.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -83,6 +83,7 @@ export default class DataDelete extends Command {
8383
awaitemitJson({
8484
success: false,
8585
error: error.message,
86+
...errorCodeFields(error),
8687
});
8788
this.exit(1);
8889
}

‎packages/cli/src/commands/data/get.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -74,6 +74,7 @@ export default class DataGet extends Command {
7474
awaitemitJson({
7575
success: false,
7676
error: error.message,
77+
...errorCodeFields(error),
7778
});
7879
this.exit(1);
7980
}

‎packages/cli/src/commands/data/query.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -117,6 +117,7 @@ export default class DataQuery extends Command {
117117
awaitemitJson({
118118
success: false,
119119
error: error.message,
120+
...errorCodeFields(error),
120121
});
121122
this.exit(1);
122123
}

‎packages/cli/src/commands/data/update.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -104,6 +104,7 @@ export default class DataUpdate extends Command {
104104
awaitemitJson({
105105
success: false,
106106
error: error.message,
107+
...errorCodeFields(error),
107108
});
108109
this.exit(1);
109110
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat(cli): carry the ADR-0112 code and httpStatus in `--format json` … · objectstack-ai/objectstack@098a08f · GitHub
Skip to content

Commit 098a08f

Browse files
os-trumpclaude
andauthored
feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes (#13510)
* feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes Every machine-readable failure the CLI emits was `{ success: false, error: error.message }` and nothing else — 48 sites under `packages/cli/src/commands/`. The error reaching those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's `fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized across both server dialects) and `err.httpStatus`. Both were discarded at the CLI boundary, so a script had to substring-match an English sentence that no contract pins. One shared builder (`errorCodeFields` in `utils/format.ts`) plus 48 call-site spreads. Additive: `success` and `error` keep their meaning and spelling, the payload stays flat, and the two keys are ABSENT — not `undefined` — when the thrown error did not carry them. No fallback code is invented for a locally-thrown plain `Error`. Human `table` output is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * test(cli): give the #13347 envelope cases an explicit wall-clock budget Each case drives a real `Command.run` against the real oclif root — ~0.8s per case on an idle box, and measured TIMING OUT at vitest's 5s default when the file ran inside `@objectstack/cli`'s full 220-file suite on a shared container. Wall-clock only: no assertion moves. The neighbouring `delete-reset-carriers.test.ts` reaches the same conclusion the same way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * docs(cli): declare errorCodeFields.code's real value space — pass-through, ADR-0112 for wire failures, Node errno for local I/O Contract-review amendment on #13510: the field doc and changeset called code 'the semantic ADR-0112 code', but the builder is a structural pass-through and os validate/compile/lint throw errno-carrying fs errors inside the same try, so ENOENT/ENOTDIR are genuinely publishable values. Behaviour unchanged (the ruling's literal pass-through shape stands); only the declaration now matches it. The vocabularies are disjoint (errnos are E-prefixed OS names), so ADR-0112 branches cannot false-match an errno. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ec4c4d2 commit 098a08f

42 files changed

Lines changed: 763 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
"@objectstack/cli": minor
3+
---
4+
5+
feat(cli): `--format json` failure envelopes carry the ADR-0112 `code` and `httpStatus` (#13347)
6+
7+
Every machine-readable failure this CLI emits was built the same way — 48 sites
8+
under `packages/cli/src/commands/`:
9+
10+
```ts
11+
awaitemitJson({ success: false, error: error.message });
12+
```
13+
14+
The payload carried the human sentence and nothing else. The error reaching
15+
those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's
16+
`fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized to
17+
the same spelling across the flat `@objectstack/rest` envelope and the wrapped
18+
runtime-dispatcher one) and `err.httpStatus`. Both were discarded at the CLI
19+
boundary, so the one outcome a script most needs to branch on — *someone else
20+
edited it, re-read and retry* vs *you are not allowed* vs *the server is down*
21+
was separable only by substring-matching an English sentence that no contract
22+
pins.
23+
24+
A stale-pin refusal from `os meta delete --if-match` used to read:
25+
26+
```json
27+
{
28+
"success": false,
29+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …"
30+
}
31+
```
32+
33+
and now reads:
34+
35+
```json
36+
{
37+
"success": false,
38+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …",
39+
"code": "METADATA_CONFLICT",
40+
"httpStatus": 409
41+
}
42+
```
43+
44+
Maintainer ruling 2026-08-30 (option **A** of three):
45+
46+
- The payload stays **FLAT**. Nesting into `{ error: { code, message, httpStatus } }`
47+
was considered and declined as breaking.
48+
-`success` and `error` keep their current meaning **and spelling**.
49+
- The two keys are emitted **only when the thrown error carries them**, and are
50+
**absent** — not `undefined` — otherwise. No fallback code is invented for a
51+
locally-thrown plain `Error`: this CLI's own input refusals get no code,
52+
deliberately, because ADR-0112's ledger is the authority on who may mint one.
53+
54+
One value-space note, stated so the declaration matches what ships: `code` is a
55+
**pass-through**, never minted or filtered. On wire failures it is the semantic
56+
ADR-0112 string the SDK attached; on local I/O failures inside the same `try`
57+
(`os validate` reading a `src/docs` that is a file, say) it is the Node errno
58+
(`ENOENT`, `ENOTDIR`, …). The two vocabularies are disjoint — errnos are
59+
`E`-prefixed OS names — so a consumer branching on ADR-0112 codes cannot
60+
false-match an errno, but not every emitted `code` is ledger-owned.
61+
62+
Human (`table`) output is untouched.
63+
64+
**Why `minor` and not `patch`.** Maintainer-set, and it overrides the obvious
65+
reading: this is a shape change to an **already-published error envelope**, and
66+
that makes it minor even though it is purely additive.
67+
68+
**Migration.** Nothing is required — no key is removed, renamed or re-typed, and
69+
every payload this CLI emitted before is still emitted, byte-for-byte, minus the
70+
two new keys. Two things are worth knowing before you rely on the new ones:
71+
72+
-**The envelope is polymorphic, by design.**`code` and `httpStatus` are absent
73+
whenever the failure did not carry them, which a consumer cannot distinguish
74+
from an older CLI. Branch on presence (`if (payload.code === 'METADATA_CONFLICT')`),
75+
never on absence meaning "success" or "unsupported version". This cost was
76+
weighed against breaking every existing consumer, and the non-breaking side won.
77+
-**Stop substring-matching the sentence.**`error` is prose and no contract pins
78+
its wording; the bracketed `[metadata_conflict]` tag some messages carry today
79+
is a property of one producer, not a contract, and a separate card argues for
80+
removing it. Code that reads the sentence to classify a failure should move to
81+
`code` (with `httpStatus` as the coarse fallback).

‎packages/cli/src/commands/cloud/login.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import * as readline from 'node:readline/promises';
7373
import{stdinasinput,stdoutasoutput}from'node:process';
7474
import{Command,Flags}from'@oclif/core';
7575
importtype{CliExitCode}from'../../utils/format.js';
76-
import{printHeader,printKV,printSuccess,printError,emitJson}from'../../utils/format.js';
76+
import{printHeader,printKV,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
7777
import{loginWithBrowser,loginWithPassword}from'../../utils/auth-flows.js';
7878
import{DEFAULT_CLOUD_URL,readCloudConfig,writeCloudConfig}from'../../utils/cloud-config.js';
7979

@@ -246,7 +246,7 @@ export default class CloudLogin extends Command {
246246
// written (an expired code, a denied approval, a poll failure), so an
247247
// indented payload here would recreate a two-document stream on the
248248
// path a consumer is least able to recover from.
249-
awaitemitRecord({success: false,error: error.message});
249+
awaitemitRecord({success: false,error: error.message, ...errorCodeFields(error)});
250250
this.exit(1);
251251
}
252252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/logout.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import{Command,Flags}from'@oclif/core';
1010
import{ObjectStackClient}from'@objectstack/client';
11-
import{printHeader,printSuccess,printError,emitJson}from'../../utils/format.js';
11+
import{printHeader,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
1212
import{deleteCloudConfig,tryReadCloudConfig}from'../../utils/cloud-config.js';
1313

1414
exportdefaultclassCloudLogoutextendsCommand{
@@ -46,7 +46,7 @@ export default class CloudLogout extends Command {
4646
}
4747
}catch(error: any){
4848
if(flags.json){
49-
awaitemitJson({success: false,error: error.message});
49+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
5050
this.exit(1);
5151
}
5252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/whoami.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import{Command,Flags}from'@oclif/core';
10-
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal}from'../../utils/format.js';
10+
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal,errorCodeFields}from'../../utils/format.js';
1111
import{tryReadCloudConfig}from'../../utils/cloud-config.js';
1212

1313
exportdefaultclassCloudWhoamiextendsCommand{
@@ -72,7 +72,7 @@ export default class CloudWhoami extends Command {
7272
}catch(error: any){
7373
if(isExitSignal(error))throwerror;
7474
if(flags.json){
75-
awaitemitJson({success: false,error: error.message});
75+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
7676
this.exit(1);
7777
}
7878
printError(error.message||String(error));

‎packages/cli/src/commands/compile.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
printMetadataStats,
4040
emitJson,
4141
isExitSignal,
42+
errorCodeFields,
4243
}from'../utils/format.js';
4344
import{checkSpecVersionGap}from'../utils/spec-version.js';
4445

@@ -720,7 +721,7 @@ export default class Compile extends Command {
720721
}catch(error: any){
721722
if(isExitSignal(error))throwerror;
722723
if(flags.json){
723-
awaitemitJson({success: false,error: error.message,warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724+
awaitemitJson({success: false,error: error.message,...errorCodeFields(error),warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724725
this.exit(1);
725726
}
726727
console.log('');

‎packages/cli/src/commands/data/create.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -100,6 +100,7 @@ export default class DataCreate extends Command {
100100
awaitemitJson({
101101
success: false,
102102
error: error.message,
103+
...errorCodeFields(error),
103104
});
104105
this.exit(1);
105106
}

‎packages/cli/src/commands/data/delete.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -83,6 +83,7 @@ export default class DataDelete extends Command {
8383
awaitemitJson({
8484
success: false,
8585
error: error.message,
86+
...errorCodeFields(error),
8687
});
8788
this.exit(1);
8889
}

‎packages/cli/src/commands/data/get.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -74,6 +74,7 @@ export default class DataGet extends Command {
7474
awaitemitJson({
7575
success: false,
7676
error: error.message,
77+
...errorCodeFields(error),
7778
});
7879
this.exit(1);
7980
}

‎packages/cli/src/commands/data/query.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -117,6 +117,7 @@ export default class DataQuery extends Command {
117117
awaitemitJson({
118118
success: false,
119119
error: error.message,
120+
...errorCodeFields(error),
120121
});
121122
this.exit(1);
122123
}

‎packages/cli/src/commands/data/update.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -104,6 +104,7 @@ export default class DataUpdate extends Command {
104104
awaitemitJson({
105105
success: false,
106106
error: error.message,
107+
...errorCodeFields(error),
107108
});
108109
this.exit(1);
109110
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); feat(cli): carry the ADR-0112 code and httpStatus in `--format json` … · objectstack-ai/objectstack@098a08f · GitHub
Skip to content

Commit 098a08f

Browse files
os-trumpclaude
andauthored
feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes (#13510)
* feat(cli): carry the ADR-0112 code and httpStatus in --format json failure envelopes Every machine-readable failure the CLI emits was `{ success: false, error: error.message }` and nothing else — 48 sites under `packages/cli/src/commands/`. The error reaching those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's `fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized across both server dialects) and `err.httpStatus`. Both were discarded at the CLI boundary, so a script had to substring-match an English sentence that no contract pins. One shared builder (`errorCodeFields` in `utils/format.ts`) plus 48 call-site spreads. Additive: `success` and `error` keep their meaning and spelling, the payload stays flat, and the two keys are ABSENT — not `undefined` — when the thrown error did not carry them. No fallback code is invented for a locally-thrown plain `Error`. Human `table` output is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * test(cli): give the #13347 envelope cases an explicit wall-clock budget Each case drives a real `Command.run` against the real oclif root — ~0.8s per case on an idle box, and measured TIMING OUT at vitest's 5s default when the file ran inside `@objectstack/cli`'s full 220-file suite on a shared container. Wall-clock only: no assertion moves. The neighbouring `delete-reset-carriers.test.ts` reaches the same conclusion the same way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TvqBFLRzXdSPcbusDoED9k * docs(cli): declare errorCodeFields.code's real value space — pass-through, ADR-0112 for wire failures, Node errno for local I/O Contract-review amendment on #13510: the field doc and changeset called code 'the semantic ADR-0112 code', but the builder is a structural pass-through and os validate/compile/lint throw errno-carrying fs errors inside the same try, so ENOENT/ENOTDIR are genuinely publishable values. Behaviour unchanged (the ruling's literal pass-through shape stands); only the declaration now matches it. The vocabularies are disjoint (errnos are E-prefixed OS names), so ADR-0112 branches cannot false-match an errno. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ec4c4d2 commit 098a08f

42 files changed

Lines changed: 763 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
"@objectstack/cli": minor
3+
---
4+
5+
feat(cli): `--format json` failure envelopes carry the ADR-0112 `code` and `httpStatus` (#13347)
6+
7+
Every machine-readable failure this CLI emits was built the same way — 48 sites
8+
under `packages/cli/src/commands/`:
9+
10+
```ts
11+
awaitemitJson({ success: false, error: error.message });
12+
```
13+
14+
The payload carried the human sentence and nothing else. The error reaching
15+
those `catch` blocks from `@objectstack/client` is not a bare `Error`: the SDK's
16+
`fetch` wrapper attaches `err.code` (the semantic ADR-0112 string, normalized to
17+
the same spelling across the flat `@objectstack/rest` envelope and the wrapped
18+
runtime-dispatcher one) and `err.httpStatus`. Both were discarded at the CLI
19+
boundary, so the one outcome a script most needs to branch on — *someone else
20+
edited it, re-read and retry* vs *you are not allowed* vs *the server is down*
21+
was separable only by substring-matching an English sentence that no contract
22+
pins.
23+
24+
A stale-pin refusal from `os meta delete --if-match` used to read:
25+
26+
```json
27+
{
28+
"success": false,
29+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …"
30+
}
31+
```
32+
33+
and now reads:
34+
35+
```json
36+
{
37+
"success": false,
38+
"error": "[metadata_conflict] view/race_probe has been modified since you loaded it. …",
39+
"code": "METADATA_CONFLICT",
40+
"httpStatus": 409
41+
}
42+
```
43+
44+
Maintainer ruling 2026-08-30 (option **A** of three):
45+
46+
- The payload stays **FLAT**. Nesting into `{ error: { code, message, httpStatus } }`
47+
was considered and declined as breaking.
48+
-`success` and `error` keep their current meaning **and spelling**.
49+
- The two keys are emitted **only when the thrown error carries them**, and are
50+
**absent** — not `undefined` — otherwise. No fallback code is invented for a
51+
locally-thrown plain `Error`: this CLI's own input refusals get no code,
52+
deliberately, because ADR-0112's ledger is the authority on who may mint one.
53+
54+
One value-space note, stated so the declaration matches what ships: `code` is a
55+
**pass-through**, never minted or filtered. On wire failures it is the semantic
56+
ADR-0112 string the SDK attached; on local I/O failures inside the same `try`
57+
(`os validate` reading a `src/docs` that is a file, say) it is the Node errno
58+
(`ENOENT`, `ENOTDIR`, …). The two vocabularies are disjoint — errnos are
59+
`E`-prefixed OS names — so a consumer branching on ADR-0112 codes cannot
60+
false-match an errno, but not every emitted `code` is ledger-owned.
61+
62+
Human (`table`) output is untouched.
63+
64+
**Why `minor` and not `patch`.** Maintainer-set, and it overrides the obvious
65+
reading: this is a shape change to an **already-published error envelope**, and
66+
that makes it minor even though it is purely additive.
67+
68+
**Migration.** Nothing is required — no key is removed, renamed or re-typed, and
69+
every payload this CLI emitted before is still emitted, byte-for-byte, minus the
70+
two new keys. Two things are worth knowing before you rely on the new ones:
71+
72+
-**The envelope is polymorphic, by design.**`code` and `httpStatus` are absent
73+
whenever the failure did not carry them, which a consumer cannot distinguish
74+
from an older CLI. Branch on presence (`if (payload.code === 'METADATA_CONFLICT')`),
75+
never on absence meaning "success" or "unsupported version". This cost was
76+
weighed against breaking every existing consumer, and the non-breaking side won.
77+
-**Stop substring-matching the sentence.**`error` is prose and no contract pins
78+
its wording; the bracketed `[metadata_conflict]` tag some messages carry today
79+
is a property of one producer, not a contract, and a separate card argues for
80+
removing it. Code that reads the sentence to classify a failure should move to
81+
`code` (with `httpStatus` as the coarse fallback).

‎packages/cli/src/commands/cloud/login.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import * as readline from 'node:readline/promises';
7373
import{stdinasinput,stdoutasoutput}from'node:process';
7474
import{Command,Flags}from'@oclif/core';
7575
importtype{CliExitCode}from'../../utils/format.js';
76-
import{printHeader,printKV,printSuccess,printError,emitJson}from'../../utils/format.js';
76+
import{printHeader,printKV,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
7777
import{loginWithBrowser,loginWithPassword}from'../../utils/auth-flows.js';
7878
import{DEFAULT_CLOUD_URL,readCloudConfig,writeCloudConfig}from'../../utils/cloud-config.js';
7979

@@ -246,7 +246,7 @@ export default class CloudLogin extends Command {
246246
// written (an expired code, a denied approval, a poll failure), so an
247247
// indented payload here would recreate a two-document stream on the
248248
// path a consumer is least able to recover from.
249-
awaitemitRecord({success: false,error: error.message});
249+
awaitemitRecord({success: false,error: error.message, ...errorCodeFields(error)});
250250
this.exit(1);
251251
}
252252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/logout.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import{Command,Flags}from'@oclif/core';
1010
import{ObjectStackClient}from'@objectstack/client';
11-
import{printHeader,printSuccess,printError,emitJson}from'../../utils/format.js';
11+
import{printHeader,printSuccess,printError,emitJson,errorCodeFields}from'../../utils/format.js';
1212
import{deleteCloudConfig,tryReadCloudConfig}from'../../utils/cloud-config.js';
1313

1414
exportdefaultclassCloudLogoutextendsCommand{
@@ -46,7 +46,7 @@ export default class CloudLogout extends Command {
4646
}
4747
}catch(error: any){
4848
if(flags.json){
49-
awaitemitJson({success: false,error: error.message});
49+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
5050
this.exit(1);
5151
}
5252
printError(error.message||String(error));

‎packages/cli/src/commands/cloud/whoami.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import{Command,Flags}from'@oclif/core';
10-
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal}from'../../utils/format.js';
10+
import{printHeader,printKV,printSuccess,printError,emitJson,isExitSignal,errorCodeFields}from'../../utils/format.js';
1111
import{tryReadCloudConfig}from'../../utils/cloud-config.js';
1212

1313
exportdefaultclassCloudWhoamiextendsCommand{
@@ -72,7 +72,7 @@ export default class CloudWhoami extends Command {
7272
}catch(error: any){
7373
if(isExitSignal(error))throwerror;
7474
if(flags.json){
75-
awaitemitJson({success: false,error: error.message});
75+
awaitemitJson({success: false,error: error.message, ...errorCodeFields(error)});
7676
this.exit(1);
7777
}
7878
printError(error.message||String(error));

‎packages/cli/src/commands/compile.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
printMetadataStats,
4040
emitJson,
4141
isExitSignal,
42+
errorCodeFields,
4243
}from'../utils/format.js';
4344
import{checkSpecVersionGap}from'../utils/spec-version.js';
4445

@@ -720,7 +721,7 @@ export default class Compile extends Command {
720721
}catch(error: any){
721722
if(isExitSignal(error))throwerror;
722723
if(flags.json){
723-
awaitemitJson({success: false,error: error.message,warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724+
awaitemitJson({success: false,error: error.message,...errorCodeFields(error),warnings: warningsSoFar(),conversions: conversionNotices},0,{compact: true});
724725
this.exit(1);
725726
}
726727
console.log('');

‎packages/cli/src/commands/data/create.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -100,6 +100,7 @@ export default class DataCreate extends Command {
100100
awaitemitJson({
101101
success: false,
102102
error: error.message,
103+
...errorCodeFields(error),
103104
});
104105
this.exit(1);
105106
}

‎packages/cli/src/commands/data/delete.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -83,6 +83,7 @@ export default class DataDelete extends Command {
8383
awaitemitJson({
8484
success: false,
8585
error: error.message,
86+
...errorCodeFields(error),
8687
});
8788
this.exit(1);
8889
}

‎packages/cli/src/commands/data/get.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -74,6 +74,7 @@ export default class DataGet extends Command {
7474
awaitemitJson({
7575
success: false,
7676
error: error.message,
77+
...errorCodeFields(error),
7778
});
7879
this.exit(1);
7980
}

‎packages/cli/src/commands/data/query.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,emitJson}from'../../utils/format.js';
4+
import{printError,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -117,6 +117,7 @@ export default class DataQuery extends Command {
117117
awaitemitJson({
118118
success: false,
119119
error: error.message,
120+
...errorCodeFields(error),
120121
});
121122
this.exit(1);
122123
}

‎packages/cli/src/commands/data/update.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import{Args,Command,Flags}from'@oclif/core';
4-
import{printError,printSuccess,emitJson}from'../../utils/format.js';
4+
import{printError,printSuccess,emitJson,errorCodeFields}from'../../utils/format.js';
55
import{createApiClient,requireAuth}from'../../utils/api-client.js';
66
import{formatOutput}from'../../utils/output-formatter.js';
77

@@ -104,6 +104,7 @@ export default class DataUpdate extends Command {
104104
awaitemitJson({
105105
success: false,
106106
error: error.message,
107+
...errorCodeFields(error),
107108
});
108109
this.exit(1);
109110
}

0 commit comments

Comments
 (0)