Export a guard for `VoidActionError` at every status
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 78/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
调研方向
Start by locating the exports for isCallSiteActionError() in void/pages-client and the thrown-error section of docs/guide/pages-routing/actions-and-forms.md. Check how categorizeActionError() classifies statuses and how the existing guard is tested. Done means a new guard recognizes VoidActionError across statuses, the call-site guard uses it, and both guards are documented.
由索引模型根据 Issue 内容生成。
描述
Summary
Follow-up to #680, as #691 suggested ("that can be a separate change"). Since 1.6.0, a 4xx action error's message is the server's text, thanks for that. #680's other ask is still open: a guard that recognises a VoidActionError at every status.
The actions guide says 401, 403 and 5xx are thrown, and to "handle them with your framework's error boundary". But the only guard Void exports, isCallSiteActionError(), is false for exactly those statuses. So an error boundary can't tell an action error from any other error without reproducing Void's internals.
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 403, { message: 'You can vote once your account is a day old' });
});
// pages/notes.tsx
import { isCallSiteActionError } from 'void/pages-client';
try {
await action(`/notes?status=${status}`, { data: {} });
} catch (error) {
isCallSiteActionError(error); // false for 401, 403 and 5xx
}
| Status | action() |
error.name |
isCallSiteActionError() |
|---|---|---|---|
| 409 | returns | VoidActionError |
true |
| 401 | throws | VoidActionError |
false |
| 403 | throws | VoidActionError |
false |
| 500 | throws | VoidActionError |
false |
Why it matters
- The boundary the docs point to has no guard. It has to tell an action error from a render bug to show a 403's message, send a 401 to login, or show a generic message for a 500.
- Every app copies the guard's internals.
instanceof VoidActionErrorisn't reliable when the class is bundled more than once, which is whyisCallSiteActionError()checkserror.name. Apps do the same by hand, relying on a class name the docs never mention. - Neither exported helper is documented.
isCallSiteActionError()andcategorizeActionError()are exported fromvoid/pages-clientbut don't appear in the guide or the API reference.
Proposal
-
Export
isVoidActionError()next toisCallSiteActionError(), true for every status:export function isVoidActionError(error: unknown): error is VoidActionError { return ( typeof error === 'object' && error !== null && 'name' in error && error.name === 'VoidActionError' && 'status' in error && typeof error.status === 'number' ); } export function isCallSiteActionError(error: unknown): error is VoidActionError { return isVoidActionError(error) && categorizeActionError(error.status) === 'callSite'; } -
Document both guards in the actions guide, next to the paragraph on thrown errors.
Prior art
- React Router:
isRouteErrorResponse(error)recognises a thrown response in an error boundary, at any status. - SvelteKit:
isHttpError(error, status?)recognises anerror()at any status, or a given one.
Workaround
// By name: instanceof fails across bundled copies.
export function isActionError(error: unknown): error is VoidActionError {
return error instanceof Error && error.name === 'VoidActionError';
}
Environment
void1.6.1@void/react1.6.1
- 主要语言
- TypeScript
- 星标
- 627
- 派生
- 66
- 平均合并
- 13 小时 57 分钟
- 30 天内合并 PR
- 194
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
voidzero-dev/void 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
voidzero-dev/void#677 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 72/100
voidzero-dev/void#713 · 1 条评论 ·
维护者通常 1 天内回复
-
`@void/solid`: `useParams()` keeps the first page's params after client-side navigation可能已有人在做 @yujiym 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 20/100
voidzero-dev/void#708 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 28/100
voidzero-dev/void#692 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 30/100
voidzero-dev/void#689 ·
维护者通常 1 天内回复
查看 voidzero-dev/void 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
Open-Earth-Foundation/CityCatalyst#3399 ·
维护者通常 2 天内回复
-
userReport
难度 1/5 1 小时以内 新手友好度 72/100
nkprasad12/morcus-net#631 ·
维护者通常 1 天内回复
-
fix(app): fail closed if GetGeneralSetting fails during initialization可能已有人在做 @kalavt 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
nekko-labs/nekko-agent#1756 ·
维护者通常 1 天内回复
-
needs-area-label
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 2 天内回复