Skip to content

feat(web-client): expose stable errorCode on thrown JS errors for variant dispatch#25

Open
WiktorStarczewski wants to merge 9 commits intomainfrom
wiktor/migrate-2060-errorcode
Open

feat(web-client): expose stable errorCode on thrown JS errors for variant dispatch#25
WiktorStarczewski wants to merge 9 commits intomainfrom
wiktor/migrate-2060-errorcode

Conversation

@WiktorStarczewski
Copy link
Copy Markdown
Collaborator

@WiktorStarczewski WiktorStarczewski commented Apr 28, 2026

Client PR: 0xMiden/miden-client#2059

Migrated from miden-client#2060 as part of the web-sdk split (web/WASM components moved out of miden-client into this dedicated repo — see miden-client 0xMiden/miden-client#1992 / 0xMiden/miden-client#2135).

Closes miden-client#2066.

Summary (per the original PR)

  • Adds a stable errorCode string property to JS errors thrown by the WebClient.
  • Consumers can dispatch on err.errorCode === 'ApplyTransactionAfterSubmitFailed' instead of parsing error message strings.
  • Stability contract: code strings never change once added.

Currently exposed codes:

  • ApplyTransactionAfterSubmitFailed — tx on chain, apply failed locally
  • AccountLocked — account state out of sync
  • NoteNotFoundOnChain — note not committed yet
  • RpcError — network/node issue

The CHANGELOG and other miden-client-side changes from the original PR stay on miden-client#2060. Note: the marker points at miden-client 0xMiden/miden-client#2059 (not 0xMiden/miden-client#2060) because the ApplyTransactionAfterSubmitFailed ClientError variant lives on 0xMiden/miden-client#20590xMiden/miden-client#2060 stacks on top of it.

…iant dispatch

Migrated from 0xMiden/miden-client#2060 (author: WiktorStarczewski) as
part of the web-sdk split. Original PR: 0xMiden/miden-client#2060

Depends on the ApplyTransactionAfterSubmitFailed error variant added by
miden-client #2059 — landing this requires the upstream miden-client
dep on web-sdk's main to include that change first.
@WiktorStarczewski WiktorStarczewski force-pushed the wiktor/migrate-2060-errorcode branch from 475991d to 0235262 Compare April 28, 2026 19:03
…mit-failed)

This web-sdk PR was migrated from miden-client#2060, but the Rust
ApplyTransactionAfterSubmitFailed ClientError variant it dispatches on
lives on miden-client#2059 (which #2060 stacks on). Repointing the
workspace dep at #2059's branch so CI can compile.

Revert before merge — see PR description for the merge sequence.
@WiktorStarczewski WiktorStarczewski added the no changelog PR doesn't need a CHANGELOG entry (trivial / non-user-visible) label Apr 30, 2026
WiktorStarczewski added a commit that referenced this pull request Apr 30, 2026
Now that miden-client#1835's wiktor-storekeys branch has been merged
with miden-client@dab6cf7b (the same snapshot of next that web-sdk
currently pins), the dep retarget that #23/#25/#26/#31 use works for
this PR too.

Local 'cargo check --workspace --target wasm32-unknown-unknown' is clean
(was 23 errors before the upstream merge, due to the alpha-protocol
mismatch the PR description mentions).

Revert before merge — see PR description merge gate.
…dep retarget

Brings in the auto-patch infrastructure landed in #65 (composite action,
mergeability gate, lefthook guard, dev script, docs). Drops the manual
[patch]-style retarget block we'd added to Cargo.toml: with the linked
'Client PR: #2059' marker in this PR's description, the CI workflow
auto-injects an equivalent in-place rewrite at run time.

This commit is the verification that the auto-patch system works
end-to-end on a real migration PR. Expectations:
  - Cargo.toml diff vs main is now empty (no manual retarget).
  - The Inject linked miden-client PR step reads 'Client PR: #2059' from
    this PR's body, resolves miden-client#2059's head, rewrites the dep
    in place on the runner, and posts a sticky comment summarizing the
    patch (single comment per run, deduped via the linked-client-pr
    sticky header).
  - Build/Test runs against miden-client@wiktor/apply-tx-after-submit-failed
    just like before — but the retarget is implicit, not committed.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 30, 2026

🔗 Linked client PR: 0xMiden/miden-client#2059

Field Value
Patched at 0xMiden/miden-client@wiktor/apply-tx-after-submit-failed
Pin (head sha) 3ec08c7ad3954a7b2daae939d76cf9ba0e7eba6d
Upstream state open (merged: false)

This run is testing against the linked PR's head. The published artifact will use the canonical miden-client source — CI on main/next does not auto-patch.

Local-dev parity:

scripts/dev-with-client-pr.sh 2059    # apply the same patch locally
scripts/dev-with-client-pr.sh --clear                            # remove it before commit

WiktorStarczewski added a commit that referenced this pull request Apr 30, 2026
PR #25's verification run surfaced a coverage gap: my initial wiring
in #65 only patched build.yml's build-wasm and test.yml's
build-web-client-dist-folder + verify-release-build. But Clippy WASM
(in lint.yml) and publint + attw (in check-publish.yml) ALSO compile
cargo against the workspace's miden-client dep — without the patch,
they hit canonical crates.io `miden-client = "0.14.5"` and fail
with `error[E0599]: no variant named `ApplyTransactionAfterSubmitFailed``
when the PR depends on an unreleased upstream variant.

Add the action call after checkout in both jobs. Both run with
comment=false (the default); build-wasm remains the single sticky-
comment poster.
WiktorStarczewski added a commit that referenced this pull request Apr 30, 2026
PR #25's verification run surfaced a coverage gap: my initial wiring
in #65 only patched build.yml's build-wasm and test.yml's
build-web-client-dist-folder + verify-release-build. But Clippy WASM
(in lint.yml) and publint + attw (in check-publish.yml) ALSO compile
cargo against the workspace's miden-client dep — without the patch,
they hit canonical crates.io `miden-client = "0.14.5"` and fail
with `error[E0599]: no variant named `ApplyTransactionAfterSubmitFailed``
when the PR depends on an unreleased upstream variant.

Add the action call after checkout in both jobs. Both run with
comment=false (the default); build-wasm remains the single sticky-
comment poster.
WiktorStarczewski added a commit that referenced this pull request Apr 30, 2026
…#73)

Two issues from PR #25's verification run:

  1. The 'linked-client-pr-ready' custom commit status the gate posts
     never landed. Cause: the workflow's permissions block has
     'checks: write' (for check-runs) but not 'statuses: write' (which
     the POST /repos/.../statuses/$sha endpoint requires). The gh api
     POST 403'd silently — and #2 below ate the error.

  2. set_status() redirected gh's stdout to /dev/null. With no error
     visible, the silent 403 looked like 'job ran successfully' even
     though the readiness verdict never reached the commit.

This commit:
  - adds 'statuses: write' to the workflow permissions
  - drops the >/dev/null redirect so any future API failure is loud
WiktorStarczewski added a commit that referenced this pull request Apr 30, 2026
…#74)

Two issues from PR #25's verification run:

  1. The 'linked-client-pr-ready' custom commit status the gate posts
     never landed. Cause: the workflow's permissions block has
     'checks: write' (for check-runs) but not 'statuses: write' (which
     the POST /repos/.../statuses/$sha endpoint requires). The gh api
     POST 403'd silently — and #2 below ate the error.

  2. set_status() redirected gh's stdout to /dev/null. With no error
     visible, the silent 403 looked like 'job ran successfully' even
     though the readiness verdict never reached the commit.

This commit:
  - adds 'statuses: write' to the workflow permissions
  - drops the >/dev/null redirect so any future API failure is loud
WiktorStarczewski added a commit that referenced this pull request Apr 30, 2026
#75)

Previous form:
  read -r body base_ref state <<<"$(gh api ... --jq '"\(.body // "")\t\(.base.ref)\t\(.state)"')"

PR bodies are multi-line and the marker is itself space-separated. read
defaults to whitespace IFS and only consumes through the first newline,
so a body starting with 'Client PR: #2059\n...' assigned:
  body  = 'Client'
  base_ref = 'PR:'
  state = '#2059'

The gate then hit the early-return:
  if [ "$state" != "open" ] && [ "$state" != "OPEN" ]; then
    echo "PR #$PR_NUM is $state — skipping."
    exit 0
  fi

…and exited with the visible-in-the-job 'PR #25 is #2059 — skipping.',
never posting the linked-client-pr-ready custom status. The job logged
'success' because exit 0 is what the early-return does, but the
readiness verdict never reached the commit.

Fix:
  - body = separate gh api call (multi-line tolerated naturally)
  - base_ref + state packed into a tab-separated single-line, read with
    IFS=$'\t' so a hypothetical future whitespace in either field
    wouldn't repeat the bug
  - Same IFS=$'\t' added to the second read of (merged, merge_commit_sha)
    for consistency, even though neither field can contain whitespace
    today
WiktorStarczewski added a commit that referenced this pull request Apr 30, 2026
#76)

Previous form:
  read -r body base_ref state <<<"$(gh api ... --jq '"\(.body // "")\t\(.base.ref)\t\(.state)"')"

PR bodies are multi-line and the marker is itself space-separated. read
defaults to whitespace IFS and only consumes through the first newline,
so a body starting with 'Client PR: #2059\n...' assigned:
  body  = 'Client'
  base_ref = 'PR:'
  state = '#2059'

The gate then hit the early-return:
  if [ "$state" != "open" ] && [ "$state" != "OPEN" ]; then
    echo "PR #$PR_NUM is $state — skipping."
    exit 0
  fi

…and exited with the visible-in-the-job 'PR #25 is #2059 — skipping.',
never posting the linked-client-pr-ready custom status. The job logged
'success' because exit 0 is what the early-return does, but the
readiness verdict never reached the commit.

Fix:
  - body = separate gh api call (multi-line tolerated naturally)
  - base_ref + state packed into a tab-separated single-line, read with
    IFS=$'\t' so a hypothetical future whitespace in either field
    wouldn't repeat the bug
  - Same IFS=$'\t' added to the second read of (merged, merge_commit_sha)
    for consistency, even though neither field can contain whitespace
    today
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog PR doesn't need a CHANGELOG entry (trivial / non-user-visible)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose stable errorCode on thrown JS errors for variant dispatch

1 participant