Skip to content

fix!: distinguish view function RPC errors - #272

Merged
r-near merged 4 commits into
mainfrom
fix/distinguish-view-call-errors
Aug 11, 2026
Merged

fix!: distinguish view function RPC errors#272
r-near merged 4 commits into
mainfrom
fix/distinguish-view-call-errors

Conversation

@r-near

@r-near r-near commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Closes #270

Summary

  • add RpcError::MethodNotFound for missing contract methods
  • surface view-method panics as the existing RpcError::ContractPanic
  • keep non-panic VM failures under RpcError::ContractExecution
  • preserve block_height and block_hash on applicable view RPC errors
  • expose RpcError::block_height() and RpcError::block_hash() accessors
  • parse both current info.vm_error and legacy info.error RPC payloads
  • use lowercase error messages and format methods as contract::method
  • remove the unused RpcError::FunctionCall variant and RpcError::function_call constructor
  • tighten the integration assertions for unknown accounts, accounts without code, missing methods, and contract panics

Why

NEP-641 falls back to NEP-413 only when w_resolve_auth is unavailable. A missing method (or no contract code) therefore needs to be distinguishable from a method that exists but panics; treating both as one generic execution error makes a safe fallback decision impossible.

The RPC also returns the block hash and height for these failures. Preserving that context lets resolvers associate failure and fallback decisions with the exact queried state.

The removed FunctionCall API had no client construction path and overlapped with the typed errors above. Transaction function-call failures remain available as types::FunctionCallError in transaction outcomes.

Compatibility

This is a breaking pre-1.0 API change and should ship in 0.15.0. AccountNotFound and ContractNotDeployed are now struct variants, while the view-call error variants include optional block_height and block_hash fields. The fields remain optional so legacy or string-only RPC errors can retain their typed classification without fabricated block context.

Downstream code that manually constructed or matched these variants must migrate to the new fields. Unknown or newly introduced VM error shapes continue to fall back to RpcError::ContractExecution.

Validation

  • cargo fmt --all -- --check
  • cargo test --workspace
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo clippy -p near-kit --all-targets --no-default-features --features sandbox -- -D warnings
  • cargo check -p near-kit --all-targets --no-default-features
  • cargo test -p near-kit --no-default-features --doc
  • cargo +1.88 check --workspace --all-targets
  • browser WASM and WASI feature checks
  • cargo package -p near-kit --allow-dirty

Copilot AI review requested due to automatic review settings July 30, 2026 17:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Greptile Summary

This PR refines view-function RPC error classification and preserves queried block context.

  • Adds typed errors for missing methods and view-method panics.
  • Keeps other VM failures under ContractExecution.
  • Parses current and legacy structured error payloads.
  • Adds block-height and block-hash accessors to applicable errors.
  • Removes the unused function-call RPC error API and updates integration assertions.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[View-function RPC response] --> B{Structured RPC error?}
    B -->|No| C[Deserialize ViewFunctionResult]
    B -->|Yes| D[Read block height and hash]
    D --> E[Parse info.vm_error or legacy info.error]
    E --> F{FunctionCallError kind}
    F -->|CodeDoesNotExist| G[ContractNotDeployed]
    F -->|MethodNotFound| H[MethodNotFound]
    F -->|Guest panic| I[ContractPanic]
    F -->|Other VM failure| J[ContractExecution]
Loading

Reviews (4): Last reviewed commit: "test: pin panic-prefix stripping and err..." | Re-trigger Greptile

Comment thread crates/near-kit/src/error.rs Outdated
Comment thread crates/near-kit/src/error.rs Outdated
@r-near r-near changed the title fix: distinguish view function RPC errors fix!: distinguish view function RPC errors Jul 30, 2026
r-near added 2 commits August 9, 2026 18:28
Covers the panic-prefix helper directly and asserts the source message's
casing survives, using a verbatim testnet call_function payload.
@r-near
r-near merged commit cdb029a into main Aug 11, 2026
5 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 27, 2026
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.

refactor: clarify contract-related RpcError variants

3 participants