Skip to main content

web4_core/
error.rs

1// Copyright (c) 2026 MetaLINXX Inc.
2// SPDX-License-Identifier: AGPL-3.0-or-later
3//
4// This software is covered by US Patents 11,477,027 and 12,278,913,
5// and pending application 19/178,619. See PATENTS.md for details.
6
7//! Error types for web4-core
8//!
9//! Provides structured error handling across the library.
10
11use thiserror::Error;
12
13/// Primary error type for web4-core operations
14#[derive(Error, Debug)]
15pub enum Web4Error {
16    /// Cryptographic operation failed
17    #[error("Cryptographic error: {0}")]
18    Crypto(String),
19
20    /// Signature verification failed
21    #[error("Signature verification failed: {0}")]
22    SignatureInvalid(String),
23
24    /// LCT-related error
25    #[error("LCT error: {0}")]
26    Lct(String),
27
28    /// Identity coherence below threshold
29    #[error("Coherence threshold not met: {score:.3} < {threshold:.3}")]
30    CoherenceBelowThreshold { score: f64, threshold: f64 },
31
32    /// Serialization/deserialization error
33    #[error("Serialization error: {0}")]
34    Serialization(#[from] serde_json::Error),
35
36    /// Invalid input provided
37    #[error("Invalid input: {0}")]
38    InvalidInput(String),
39
40    /// Entity not found
41    #[error("Entity not found: {0}")]
42    NotFound(String),
43
44    /// Operation not authorized
45    #[error("Not authorized: {0}")]
46    Unauthorized(String),
47
48    /// LCT has been voided or slashed
49    #[error("LCT voided: {0}")]
50    LctVoided(String),
51
52    /// Invalid state transition
53    #[error("Invalid state: {0}")]
54    InvalidState(String),
55
56    /// Ledger operation failed (mint, lookup, anchor, verify)
57    #[error("Ledger error: {0}")]
58    Ledger(String),
59
60    /// Vault storage error (corrupt file, wrong magic/version, IO)
61    #[error("Vault error: {0}")]
62    Vault(String),
63
64    /// Decryption failed — wrong passphrase/credential or tampered ciphertext
65    #[error("Decryption failed")]
66    DecryptionFailed,
67}
68
69/// Result type alias for web4-core operations
70pub type Result<T> = std::result::Result<T, Web4Error>;