`VoidActionError.message` ignores the server's message, though the docs show it to users
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 52/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react, typescript
- Lĩnh vực
- documentation, frontend
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- TypeScript
- Star
- 627
- Fork
- 66
- Merge trung bình
- 14 giờ 56 phút
- Pull request đã merge (30 ngày)
- 170
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của voidzero-dev/void
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
voidzero-dev/void#677 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`withValidator({ body })` rejects the multipart bodies that `useForm` and `action()` send for filesĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
voidzero-dev/void#679 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
voidzero-dev/void#676 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 18/100
voidzero-dev/void#667 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
platform: interrupted install ignores a replacement runtime token and never updates deployed WorkersĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
voidzero-dev/void#666 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của voidzero-dev/void
Issue tương tự
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
microsoft/playwright#43875 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
calagopus/panel#285 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 88/100
adobe/react-spectrum#10909 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Keybind conflict with "Tileset"Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Run the dependency drift checkCó thể đã có người làm @spaceninja đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
cloudfour/lighthouse-parade#449 ·
Maintainer thường phản hồi trong vòng 1 ngày