Skip to content

Commit 6ddb97b

Browse files
fix(core): actionErrorDetail shows a flat refusal's message, not its bare error code (#37138)
Fixes #37081 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:在控制台里,会话失效后某个操作或设置页被拒时,报错不再显示「UNAUTHENTICATED」这个代号,而是显示一句「需要登录才能访问」的英文说明。 - 为什么做:属于“报错要说人话”的体验改进,替所有读这类拒绝答复的设置页与操作按钮解决同一个问题。 - 出错会怎样:最坏是某条报错显示的句子与以前不同(仍是服务器给的原句),不影响数据;可以直接撤回。 - 要你做什么:无。 ## What changes `actionErrorDetail` (`@object-ui/core`) returned a bare-string `error` before it read `message`. The REST seam's flat 401 body (`ANONYMOUS_DENY_BODY`, `packages/core/src/security/anonymous-deny.ts`) is `{error: 'UNAUTHENTICATED', code: 'UNAUTHENTICATED', message: 'Authentication is required to access this endpoint.'}`, so every caller showed the user the machine code. Now, when the body carries both a non-empty string `error` and a non-empty string `message`, the message wins. Everything else keeps today's order: - `{error: 'sentence'}` alone still returns the sentence (the legacy `/actions` shape). - `{error: {message}}` (the ADR-0112 nested envelope) is read as before, and still ahead of a top-level `message`. No body shape on the platform was found that carries both a nested `error.message` and a different top-level `message`, so that order is kept. - An empty or non-string `message` beside a string `error` returns the `error`; nothing readable returns the caller's fallback. Callers (all read through this one function, none changed): `useConsoleActionRuntime.tsx`, `FlowItemMoreMenu.tsx`, `sharing-rule-catalog.ts`, `catalog-activation.ts`, `permission-set-clone.ts`, `packagedActionLedger.ts`, `connectorConnections.ts`, `connectorCredentials.ts`, `packagedFlowLedger.ts`, `flowResponse.ts` (app-shell) and `actionResponse.ts` (core). Files to read first: 1. `ui/packages/core/src/actions/actionErrorDetail.ts` — the one changed branch (the bare-string `error` case). 2. `ui/packages/core/src/actions/__tests__/actionErrorDetail-37081.test.ts` — the pins. Two-minute verification: `cd ui && pnpm exec vitest run packages/core/src/actions/__tests__/actionErrorDetail-37081.test.ts` — expect 5 passed. ## Tests New file `actionErrorDetail-37081.test.ts` (no existing harness pins `actionErrorDetail` directly), five cases: the flat 401 body returns its message; `{error: 'sentence'}` alone returns the sentence; empty or non-string `message` returns the `error`; the nested envelope is unchanged and still beats a top-level `message`; lone `message` and the fallback are unchanged. Flipped pins: none. No existing test asserted the code-over-message order. Two checks: a static scan of every `ui/**` test for an object literal carrying both a string `error` and a string `message` found 8 hits, none routed through `actionErrorDetail` (the `data-objectstack` and `AuditLogPage` / `PackagesPage` fixtures use their own readers); and the 113 test files that name a caller module or the code `UNAUTHENTICATED` in app-shell / console all pass with the change. <details><summary>Readings at 39f1bca</summary> - `cd ui && pnpm exec vitest run packages/core/` — Test Files 247 passed (247), Tests 4774 passed, 27 skipped; exit 0. - `cd ui && pnpm exec vitest run` over the 113 caller test files — Test Files 113 passed (113), Tests 1564 passed; exit 0. - `pnpm exec turbo run type-check --filter=@object-ui/core` — `@object-ui/core:type-check` executed (cache miss), Tasks 4 successful; exit 0. - `pnpm --dir ui exec vitest run scripts/` after the seven-package Test UI build — Test Files 172 passed, 2 skipped; Tests 5131 passed; lock VERDICT command-exit 0. - Ablation (fix committed first; `scripts/ablation-replace.mjs --delete` on the new `return b.message` line, anchor 1 -> 0, blob 03bc828 -> 7c90c74a): the flat 401 pin went red, `Expected: "Authentication is required to access this endpoint." Received: "UNAUTHENTICATED"`, 1 failed / 4 passed; restore verified blob == HEAD, `git diff HEAD` empty. </details> ## Acceptance notes - `@object-ui/core` does not depend on `@objectstack/core`, so the pin copies `ANONYMOUS_DENY_BODY` field for field and names its source file. ## Verification Derived gate families (`dispatch-gates --commands` at 39f1bca, 38): 37 run locally with exit 0, including `pnpm --dir ui exec vitest run scripts/` after the seven-package Test UI build. `pnpm check:type-check-debt` is NOT MEASURED locally: its first run exited 3 (PREREQUISITE NOT MET, its closure build got no turn on the shared verify lock) and two locked retries timed out in the queue (exit 99). It runs in CI under Lint and Repo Gates; read it there. `dispatch-gates --ran` reconciles 38 of 38. `overlap-check`: clean. Repo-wide families run in CI. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D)_ Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 355c73c commit 6ddb97b

3 files changed

Lines changed: 78 additions & 1 deletion

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/core': patch
3+
---
4+
5+
fix(core): a refusal that carries a `message` beside a bare-string `error` code shows the message
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`actionErrorDetail` returned a bare-string `error` before it read `message`. Against the REST seam's flat 401 body, `{error: 'UNAUTHENTICATED', code, message}`, every caller showed the user the code `UNAUTHENTICATED` instead of the sentence. Now, when the body has both a non-empty string `error` and a non-empty string `message`, the message is returned. A body with only `{error: 'sentence'}` still returns that sentence, the nested `{error: {message}}` envelope is read as before (still ahead of a top-level `message`), and the fallback is unchanged.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* objectstack-ai/objectstack#37081 — a flat refusal body's bare-string `error`
6+
* is a machine code; when the body also carries a `message`, the user reads
7+
* the message.
8+
*
9+
* The body below is the REST seam's flat 401, `ANONYMOUS_DENY_BODY` in
10+
* `packages/core/src/security/anonymous-deny.ts`, copied field for field:
11+
* `@object-ui/core` does not depend on `@objectstack/core`.
12+
*/
13+
14+
import { describe, it, expect } from 'vitest';
15+
import { actionErrorDetail } from '../actionErrorDetail';
16+
17+
const ANONYMOUS_DENY_BODY = {
18+
error: 'UNAUTHENTICATED',
19+
code: 'UNAUTHENTICATED',
20+
message: 'Authentication is required to access this endpoint.',
21+
};
22+
23+
describe('actionErrorDetail — message before a bare-string error code', () => {
24+
it('returns the flat 401 body\'s message, not its code', () => {
25+
expect(actionErrorDetail(ANONYMOUS_DENY_BODY, 'HTTP 401')).toBe(
26+
'Authentication is required to access this endpoint.',
27+
);
28+
});
29+
30+
it('still returns a bare-string error when the body has no message', () => {
31+
expect(actionErrorDetail({ error: 'Record is locked' }, 'fallback')).toBe('Record is locked');
32+
});
33+
34+
it('returns the bare-string error when the message is empty or not a string', () => {
35+
expect(actionErrorDetail({ error: 'Record is locked', message: '' }, 'fallback')).toBe('Record is locked');
36+
expect(actionErrorDetail({ error: 'Record is locked', message: 42 }, 'fallback')).toBe('Record is locked');
37+
});
38+
39+
it('reads the nested envelope message as before, ahead of a top-level message', () => {
40+
expect(
41+
actionErrorDetail({ error: { code: 'PERMISSION_DENIED', message: 'Nested sentence' } }, 'fallback'),
42+
).toBe('Nested sentence');
43+
expect(
44+
actionErrorDetail(
45+
{ error: { code: 'PERMISSION_DENIED', message: 'Nested sentence' }, message: 'Top sentence' },
46+
'fallback',
47+
),
48+
).toBe('Nested sentence');
49+
});
50+
51+
it('reads a lone top-level message, and falls back when nothing is readable', () => {
52+
expect(actionErrorDetail({ message: 'Top sentence' }, 'fallback')).toBe('Top sentence');
53+
expect(actionErrorDetail({ error: '', message: '' }, 'fallback')).toBe('fallback');
54+
expect(actionErrorDetail({}, 'fallback')).toBe('fallback');
55+
expect(actionErrorDetail(null, 'fallback')).toBe('fallback');
56+
});
57+
});

‎ui/packages/core/src/actions/actionErrorDetail.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,24 @@
2020
* Handles, in order: `{error: 'msg'}`, `{error: {message: 'msg'}}`,
2121
* `{message: 'msg'}`, else the caller's fallback.
2222
*
23+
* One exception to that order: a bare-string `error` beside a non-empty
24+
* `message` is a machine code, not a sentence. The REST seam's flat 401 body
25+
* (`ANONYMOUS_DENY_BODY` in `@objectstack/core`) is
26+
* `{error: 'UNAUTHENTICATED', code, message}`, and returning `error` there
27+
* showed the user the code. So when both are strings, `message` wins; a body
28+
* carrying only `{error: 'sentence'}` still returns that sentence.
29+
*
2330
* Moved here from `@object-ui/app-shell` (`utils/actionErrorDetail`) by
2431
* objectui#2904 so `createServerActionHandler` — the core dispatch every
2532
* consumer registers — can own the rule.
2633
*/
2734
export function actionErrorDetail(body: unknown, fallback: string): string {
2835
const b = body as { error?: unknown; message?: unknown } | null;
2936
const err = b?.error;
30-
if (typeof err === 'string' && err.length > 0) return err;
37+
if (typeof err === 'string' && err.length > 0) {
38+
if (typeof b?.message === 'string' && b.message.length > 0) return b.message;
39+
return err;
40+
}
3141
const nested = (err as { message?: unknown } | null)?.message;
3242
if (typeof nested === 'string' && nested.length > 0) return nested;
3343
if (typeof b?.message === 'string' && b.message.length > 0) return b.message;

0 commit comments

Comments
 (0)