Skip to content

fix(js/verify): fail clearly on non-JSON explorer responses instead of crashing#17

Open
Equious wants to merge 2 commits into
Cyfrin:mainfrom
Equious:fix/verify-nonjson-response
Open

fix(js/verify): fail clearly on non-JSON explorer responses instead of crashing#17
Equious wants to merge 2 commits into
Cyfrin:mainfrom
Equious:fix/verify-nonjson-response

Conversation

@Equious

@Equious Equious commented Jun 25, 2026

Copy link
Copy Markdown

Problem

verify.ts's httpGet / httpPostForm call await res.json() directly:

async function httpGet(url: string) {
  const res = await fetch(url);
  return (await res.json()) as Record<string, unknown>;
}

If the explorer returns anything that isn't JSON, res.json() throws an opaque
SyntaxError: Unexpected token 'o', "no available server" is not valid JSON,
which propagates up and aborts the entire deploy/verify flow with no
indication that the explorer was at fault.

Hit live while running the hardhat-template flow during a brief explorer
outage — the gateway returned a plaintext no available server and the whole
just all died at step 1 (MockToken verification), even though the deploy
itself had succeeded.

Fix

Route both helpers through a shared readJsonResponse that checks the HTTP
status and guards JSON.parse, throwing a descriptive BattleChainError
(status + a body snippet) instead of an opaque SyntaxError. This mirrors the
resilient response handling already in query.ts (queryAgreementByContract).

No API change; build + vitest (39/39) pass.

Note for maintainers: this makes the failure legible; callers (e.g. the
starter's all.ts) may additionally want to treat verification as best-effort
so a transient explorer hiccup doesn't abort an otherwise-successful deploy.

🤖 Generated with Claude Code

Equious and others added 2 commits June 25, 2026 12:58
…f crashing

`httpGet`/`httpPostForm` called `await res.json()` directly, so any non-JSON
response from the explorer threw an opaque `SyntaxError: Unexpected token ...`.
During an explorer outage the API returns a plaintext "no available server",
which crashed the entire deploy/verify flow with no hint that the explorer was
at fault.

Route both helpers through `readJsonResponse`, which checks the HTTP status and
guards `JSON.parse`, throwing a descriptive `BattleChainError` (status + body
snippet) — mirroring the resilient handling already in `query.ts`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The vyper-json path sent the compiler version via normalizeCompilerVersion, which
just prepends "v" — so a bare "0.4.3" became "v0.4.3". The explorer's Sourcify
verifier fetches the compiler by version and needs the full "0.4.3+commit.<hash>"
with NO leading "v" (unlike solc); a bare version 404s ("Failed fetching vyper
0.4.3 for platform linux"). The Vyper fallback therefore never verified.

Add resolveVyperVersion() to derive the full X.Y.Z+commit.<hash> from the vyper
releases mirror (the same source the explorer UI uses) and use it for vyper-json;
solc keeps the "v"-prefixed full version callers already pass. Mirrors the
battlechain-lib-py fix. Latent until now — the hardhat-template verifies Solidity.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Equious

Equious commented Jun 26, 2026

Copy link
Copy Markdown
Author

Added a second fix to this branch: verify.ts now resolves the full vyper compiler version (X.Y.Z+commit.<hash>, no leading v) for the vyper-json path. It previously sent a bare v0.4.3, which Sourcify can't fetch ("Failed fetching vyper 0.4.3 for platform linux") — so the Vyper fallback never verified. Mirrors the battlechain-lib-py fix in #18 (confirmed live). Latent in practice since the hardhat-template verifies Solidity. build + vitest (39/39) pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant