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分
- マージ済み PR(30日)
- 194
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 1週間以上 初心者へのやさしさ 28/100
voidzero-dev/void#692 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
voidzero-dev/void#689 ·
メンテナーはふだん 1 日以内に返信
voidzero-dev/void の issue をすべて見る
似ている issue
-
needs-area-label
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
liberation-data/drivine#615 ·
メンテナーはふだん 1 日以内に返信
-
backend bug ready-for-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
geolens-io/geolens#3639 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
radius-project/ai-extensions#1196 ·
メンテナーはふだん 1 日以内に返信
-
good first issue
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100