From 8d3935412c0de0dad014a7d8f14c80418e8a6af6 Mon Sep 17 00:00:00 2001 From: F88 <685250+F88@users.noreply.github.com> Date: Mon, 9 Nov 2026 14:14:03 +0900 Subject: [PATCH] feat!: support promidas 5 promidas 5 renames kind 'cors' to 'browser_fetch' and code 'CORS_BLOCKED' to 'BROWSER_FETCH_FAILED', and moves the code of the error from details.res.code to details.causeCode. Follow both. BREAKING CHANGE: promidas ^5.0.0 is required. Use promidas-utils 4.x with promidas 4.x. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 10 +++++ docs/api/repository.md | 8 ++-- docs/installation.md | 12 ++++-- .../snapshot-operation-failure-utils.ts | 12 +++--- package-lock.json | 10 ++--- package.json | 4 +- .../snapshot-operation-failure-utils.test.ts | 39 +++++++------------ 7 files changed, 51 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8a8de5..1bcdee8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +この版は promidas 5.x 向けです。 + +### BREAKING CHANGES + +- **Peer dependency**: `promidas` の要件を `^5.0.0` に変更しました (以前は `^4.0.0`) + - `promidas` 4.x を使う場合は `promidas-utils` 4.x を使ってください +- **リポジトリ**: promidas 5 の失敗の変更に対応しました + - `CORS_BLOCKED` の文言は `BROWSER_FETCH_FAILED` に表示されます + - `[参考情報]` の `通信エラーコード` は `details.causeCode` を表示します。promidas が作った値 (`TIMEOUT` など) は届かなくなりました + ## [4.0.0] - 2026-11-09 この版は promidas 4.x 向けです。 diff --git a/docs/api/repository.md b/docs/api/repository.md index ab8eec7..4610824 100644 --- a/docs/api/repository.md +++ b/docs/api/repository.md @@ -92,7 +92,7 @@ APIリクエストの失敗時に生成されるメッセージ。以下の情 - HTTPステータスコード (400, 404, 500など) - エラーコード (CLIENT_ERROR, SERVER_ERROR, NETWORK_ERROR, TIMEOUT など) - 分類 (kind) -- 通信エラーコード (UND_ERR_SOCKET など。エラーコードと異なる場合のみ) +- 通信エラーコード (`details.causeCode`。UND_ERR_SOCKET など。エラーコードと異なる場合のみ) - リクエスト情報 (メソッド、URL) - レスポンス情報 (ステータスコード、ステータステキスト) @@ -105,11 +105,11 @@ APIリクエストの失敗時に生成されるメッセージ。以下の情 - `"サーバーの応答を処理できませんでした。応答の形式が正しくない可能性があります。"` (正常なステータスで、応答を処理できない場合) - `"ネットワークエラーが発生しました。\n次のような原因が考えられます:\n- ネットワークがオフライン\n- 通信が途中で切断された\n- サーバーが一時的に利用できない\n- ファイアウォールやプロキシの設定"` - `"リクエストがタイムアウトしました。\n次を試してください:\n- ネットワーク接続を確認する\n- limitパラメータを減らす\n- timeoutMs を長くする (設定できる場合)"` (`TIMEOUT`) -- `"APIサーバーとの通信に失敗しました。\nブラウザの制限により、原因を特定できません。\n次のような原因が考えられます:\n- APIトークンが無効 (認証エラーはこの表示になります)\n- ネットワークがオフライン\n- サーバーに接続できない"` (`CORS_BLOCKED`) +- `"APIサーバーとの通信に失敗しました。\nブラウザの制限により、原因を特定できません。\n次のような原因が考えられます:\n- APIトークンが無効 (認証エラーはこの表示になります)\n- ネットワークがオフライン\n- サーバーに接続できない"` (`BROWSER_FETCH_FAILED`) -#### `CORS_BLOCKED` の原因の調べ方 +#### `BROWSER_FETCH_FAILED` の原因の調べ方 -`CORS_BLOCKED` は、CORS が原因だと判定した結果ではありません。ブラウザの `fetch` が JavaScript に応答を渡さずに失敗したことを表します。 +`BROWSER_FETCH_FAILED` は、原因を判定した結果ではありません。ブラウザの `fetch` が JavaScript に応答を渡さずに失敗したことを表します。 ブラウザは、無効なトークン (401)、CORS のブロック、接続の失敗を、JavaScript には同じエラーとして渡します。そのため、`promidas` でも `promidas-utils` でも原因を特定できません。 diff --git a/docs/installation.md b/docs/installation.md index 1d9a85f..2eeb0a8 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -14,9 +14,15 @@ instructions-for-ais: - Node.js 22 以降 - npm 9 以降 (推奨 npm 10 以降) -- `promidas` 4.0.0 以降の 4.x +- `promidas` 5.0.0 以降の 5.x -`promidas` 3.x を使う場合は `promidas-utils` 3.x を使ってください。 +以前の `promidas` を使う場合は、対応する `promidas-utils` を使ってください。 + +| `promidas` | `promidas-utils` | +| ---------- | ---------------- | +| 5.x | 5.x | +| 4.x | 4.x | +| 3.x | 3.x | ## インストール @@ -31,7 +37,7 @@ npm install promidas-utils ### 特定バージョンのインストール ```bash -npm install promidas-utils@4.0.0 +npm install promidas-utils@5.0.0 ``` ## 更新 diff --git a/lib/repository/snapshot-operation-failure-utils.ts b/lib/repository/snapshot-operation-failure-utils.ts index 008d919..d3d91c2 100644 --- a/lib/repository/snapshot-operation-failure-utils.ts +++ b/lib/repository/snapshot-operation-failure-utils.ts @@ -48,7 +48,8 @@ export function parseFetcherSnapshotFailure( lines.push(`リクエスト: ${[method, url].filter(Boolean).join(' ')}`); } - const { statusText, code: networkCode } = failure.details.res ?? {}; + const { statusText } = failure.details.res ?? {}; + const { causeCode } = failure.details; if (failure.status || statusText) { if (failure.status) { lines.push( @@ -65,10 +66,9 @@ export function parseFetcherSnapshotFailure( if (failure.kind) { lines.push(`分類: ${failure.kind}`); } - // `details.res.code` does not come from a response: it identifies the failure - // at the network layer (e.g. UND_ERR_SOCKET). Only show it when it adds something. - if (networkCode && networkCode !== failure.code) { - lines.push(`通信エラーコード: ${networkCode}`); + // The code found on the error (e.g. UND_ERR_SOCKET). Only show it when it adds something. + if (causeCode && causeCode !== failure.code) { + lines.push(`通信エラーコード: ${causeCode}`); } // Keep raw message as-is for stability (no parsing). @@ -235,7 +235,7 @@ export function parseFetcherSnapshotFailure( return withFetcherReferenceInfo('リクエストがキャンセルされました。'); // Browsers report a CORS block and a failed connection with the same error. - case 'CORS_BLOCKED': + case 'BROWSER_FETCH_FAILED': return withFetcherReferenceInfo( [ 'APIサーバーとの通信に失敗しました。', diff --git a/package-lock.json b/package-lock.json index c01e0f0..9d70483 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "eslint-config-prettier": "^10.1.8", "eslint-plugin-import-x": "^4.18.0", "prettier": "^3.9.10", - "promidas": "^4.0.0", + "promidas": "^5.0.0", "rimraf": "^6.1.4", "ts-essentials": "^10.2.1", "typescript": "^5.9.3", @@ -32,7 +32,7 @@ "node": ">=22" }, "peerDependencies": { - "promidas": "^4.0.0" + "promidas": "^5.0.0" } }, "node_modules/@algolia/abtesting": { @@ -4827,9 +4827,9 @@ } }, "node_modules/promidas": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/promidas/-/promidas-4.0.0.tgz", - "integrity": "sha512-3zfxx7JDrcRN+MwRoN6QS0wg1BI4Kwi42cffWLoPGUH1lwRxoWtELLiAbXzgpHgUBgnyLN3ASy2C3HoQqtFXiQ==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/promidas/-/promidas-5.0.0.tgz", + "integrity": "sha512-TV37tfAvcXLsrLZXG1EKLIdI+D76b9Ad5pyx4DIxOXIJyrUw9K4+kXDjOQ0Y3zeOMf84Le6es+RCayewtbD4UQ==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 0f544e3..0a7f600 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "docs:preview": "vitepress preview docs" }, "peerDependencies": { - "promidas": "^4.0.0" + "promidas": "^5.0.0" }, "devDependencies": { "@types/eslint": "^9.6.1", @@ -62,7 +62,7 @@ "eslint-config-prettier": "^10.1.8", "eslint-plugin-import-x": "^4.18.0", "prettier": "^3.9.10", - "promidas": "^4.0.0", + "promidas": "^5.0.0", "rimraf": "^6.1.4", "ts-essentials": "^10.2.1", "typescript": "^5.9.3", diff --git a/test/repository/snapshot-operation-failure-utils.test.ts b/test/repository/snapshot-operation-failure-utils.test.ts index 1d7f97a..fff2f58 100644 --- a/test/repository/snapshot-operation-failure-utils.test.ts +++ b/test/repository/snapshot-operation-failure-utils.test.ts @@ -574,12 +574,12 @@ describe('snapshot-operation-failure-utils', () => { }); describe('CORS errors', () => { - it('should handle CORS_BLOCKED', () => { + it('should handle BROWSER_FETCH_FAILED', () => { const failure: FetcherSnapshotFailure = { ok: false, origin: 'fetcher', - kind: 'cors', - code: 'CORS_BLOCKED', + kind: 'browser_fetch', + code: 'BROWSER_FETCH_FAILED', message: 'CORS blocked', details: { req: {}, res: {} }, }; @@ -665,9 +665,7 @@ describe('snapshot-operation-failure-utils', () => { message: 'Failed to read the response body', details: { req: {}, - res: { - code: 'UND_ERR_SOCKET', - }, + causeCode: 'UND_ERR_SOCKET', }, }; @@ -680,19 +678,17 @@ describe('snapshot-operation-failure-utils', () => { const failure: FetcherSnapshotFailure = { ok: false, origin: 'fetcher', - kind: 'timeout', - code: 'TIMEOUT', - message: 'Upstream request timed out', + kind: 'network', + code: 'ECONNREFUSED', + message: 'fetch failed', details: { req: {}, - res: { - code: 'TIMEOUT', - }, + causeCode: 'ECONNREFUSED', }, }; const result = parseFetcherSnapshotFailure(failure); - expect(result).toContain('エラーコード: TIMEOUT'); + expect(result).toContain('エラーコード: ECONNREFUSED'); expect(result).not.toContain('通信エラーコード'); }); @@ -700,23 +696,18 @@ describe('snapshot-operation-failure-utils', () => { const failure: FetcherSnapshotFailure = { ok: false, origin: 'fetcher', - kind: 'cors', - code: 'CORS_BLOCKED', + kind: 'browser_fetch', + code: 'BROWSER_FETCH_FAILED', message: 'Failed to fetch', - details: { - res: { - code: 'NETWORK_ERROR', - }, - }, + details: {}, }; const result = parseFetcherSnapshotFailure(failure); expect(result).toContain( [ '[参考情報]', - 'エラーコード: CORS_BLOCKED', - '分類: cors', - '通信エラーコード: NETWORK_ERROR', + 'エラーコード: BROWSER_FETCH_FAILED', + '分類: browser_fetch', '詳細: Failed to fetch', ].join('\n'), ); @@ -1250,7 +1241,7 @@ describe('snapshot-operation-failure-utils', () => { status: 401, details: { req: { method: 'GET', url: 'https://api.example.com/data' }, - res: { statusText: 'Unauthorized', code: 'UNAUTHORIZED' }, + res: { statusText: 'Unauthorized' }, }, };