`VoidActionError.message` ignores the server's message, though the docs show it to users
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 52/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- react, typescript
研究方向
Start in pages/action-result.ts, where the VoidActionError constructor builds message and currently reads body only for a 429 usage limit. Then read the action() section of docs/guide/pages-routing/actions-and-forms.md, which shows result.error.message in a toast. Done when a 4xx with a text body sets message to that body, 5xx and empty bodies keep the status line, and the docs describe message accurately. The optional isVoidActionError() export is a separate decision to confirm with maintainers.
由索引模型根據 Issue 內容生成。
描述
Summary
When an action fails, VoidActionError.message is a status line such as Action failed with 404 Not Found. A 429's usage-limit message is the only exception. The handler's own message, for example from HTTPException, ends up only in error.body.
The action() guide shows the message to users:
if (!result.ok) {
showToast(result.error.message);
}
Followed as written, that toast says "Action failed with 404 Not Found" instead of what the action said.
Reproduction
// pages/notes.server.ts
import { HTTPException } from 'hono/http-exception';
import { defineHandler } from 'void';
export const action = defineHandler(async (c) => {
const status = Number(c.req.query('status'));
throw new HTTPException(status as 404, { message: 'That note was deleted.' });
});
// pages/notes.tsx
const result = await action(`/notes?status=${status}`, { data: {} });
// For 403 and 500, action() throws, so read the caught error instead.
The server answers with the message as text/plain. On the client:
| Status | action() |
error.message |
error.body |
isCallSiteActionError() |
|---|---|---|---|---|
| 404 | returns | Action failed with 404 Not Found |
That note was deleted. |
true |
| 409 | returns | Action failed with 409 Conflict |
That note was deleted. |
true |
| 422 | returns | Action failed with 422 Unprocessable Entity |
That note was deleted. |
true |
| 403 | throws | Action failed with 403 Forbidden |
That note was deleted. |
false |
| 500 | throws | Action failed with 500 Internal Server Error |
That note was deleted. |
false |
The message is built in VoidActionError's constructor (pages/action-result.ts), which reads body only for a 429's usage limit.
Why it matters
- The documented pattern shows a status line. An app that follows the guide shows users text written for developers.
- Every app writes the same helper. To show the action's message, each app checks that
bodyis a non-empty string and falls back otherwise, and has to know that Void stores a text body there. - Thrown errors have no guard. 401, 403 and 5xx reach the error boundary, where the only exported guard,
isCallSiteActionError(), isfalsefor them. Apps checkerror.name === 'VoidActionError'by hand, as the guard itself does, becauseinstanceofisn't reliable when the class is bundled more than once.
Proposal
- Use the server's text for 4xx. When the status is 4xx and
bodyis a non-empty string, setmessageto it, as the constructor already does for a 429's limit message. Keep the status line for 5xx, where the text may not be meant for users, and when there's no body.statusandstatusTextstill carry the status. - Export
isVoidActionError(), true for every status, so error boundaries can recognise action errors. - At minimum, fix the docs. Say what
messageholds, and change theaction()example to readerror.bodywith a fallback.
Prior art
- Better Auth, which Void bundles: a failed call's
error.messageis the server's message. - SvelteKit:
error(404, 'That note was deleted.')reaches the page aspage.error.message.
Workaround
// By name: instanceof fails across bundled copies.
function isActionError(error: unknown): error is VoidActionError {
return error instanceof Error && error.name === 'VoidActionError';
}
function getErrorMessage(error: unknown): string {
if (isActionError(error) && error.status < 500 && typeof error.body === 'string' && error.body) {
return error.body;
}
return 'Something went wrong, please try again';
}
Environment
void1.5.0@void/react1.5.0
- 主要語言
- TypeScript
- 星號
- 627
- 分支
- 66
- 平均合併
- 14 小時 56 分鐘
- 30 天內合併 PR
- 170
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
voidzero-dev/void 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 62/100
voidzero-dev/void#677 ·
維護者通常 1 天內回覆
-
`withValidator({ body })` rejects the multipart bodies that `useForm` and `action()` send for files未關閉
難度 4/5 3-5 天 新手友好度 35/100
voidzero-dev/void#679 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 25/100
voidzero-dev/void#676 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 18/100
voidzero-dev/void#667 ·
維護者通常 1 天內回覆
-
platform: interrupted install ignores a replacement runtime token and never updates deployed Workers未關閉
難度 4/5 3-5 天 新手友好度 35/100
voidzero-dev/void#666 ·
維護者通常 1 天內回覆
查看 voidzero-dev/void 的全部 Issue
相似的 Issue
-
area: cli bug flake ready-for-agent
難度 2/5 1-3 小時 新手友好度 62/100
gazetta-studio/gazetta-studio#1772 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
-
needs-triage
難度 2/5 1-3 小時 新手友好度 66/100
microsoft/playwright#43875 · 1 則留言 ·
維護者通常 1 天內回覆
-
documentation good first issue
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
feature
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆