Skip to content

Structured Error Codes in Verifier #46

@AnkanMisra

Description

@AnkanMisra

Problem

Currently, the verifier returns generic "invalid signature" errors. Debugging is impossible.

flowchart LR
    A[Signature] --> B{Verify}
    B -->|Fail| C["invalid signature"]
    
    style C fill:#f66
Loading

Solution

Return specific error codes for each failure mode.

flowchart TD
    A[Signature] --> B{Parse Hex}
    B -->|Fail| E1["E002: Malformed signature"]
    B -->|Pass| C{Correct Length}
    C -->|Fail| E2["E002: Wrong length"]
    C -->|Pass| D{Recover Address}
    D -->|Fail| E3["E003: Recovery failed"]
    D -->|Pass| E{Match Expected}
    E -->|Fail| E4["E004: Address mismatch"]
    E -->|Pass| F["Valid"]
    
    style E1 fill:#f96
    style E2 fill:#f96
    style E3 fill:#f96
    style E4 fill:#f96
    style F fill:#6f6
Loading

Error Code Reference

Code Meaning When
E001 Missing signature No X-402-Signature header
E002 Malformed signature Not hex, wrong length
E003 Recovery failed crypto.Ecrecover failed
E004 Address mismatch Recovered != expected
E005 Invalid message Message format wrong
E006 Nonce reused Duplicate nonce

Implementation

File: verifier/src/main.rs

#[derive(Serialize)]
struct VerifyError {
    code: String,
    message: String,
    details: Option<String>,
}

impl VerifyError {
    fn malformed_signature(details: &str) -> Self {
        Self {
            code: "E002".into(),
            message: "Malformed signature".into(),
            details: Some(details.into()),
        }
    }
}

Acceptance Criteria

  • Define error code enum/constants
  • Return structured JSON errors with codes
  • Document all error codes in README
  • Each error path has unique code
  • Add tests for each error code
  • Update OpenAPI spec with error responses

Testing

cd verifier && cargo test

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions