Rust and WASM did-method-plc tools and structures
at main 3.4 kB view raw
1//! Error types for atproto-plc operations 2 3use thiserror::Error; 4 5/// The main error type for all atproto-plc operations 6#[derive(Error, Debug)] 7pub enum PlcError { 8 /// Invalid DID format 9 #[error("Invalid DID format: {0}")] 10 InvalidDidFormat(String), 11 12 /// Invalid base32 encoding 13 #[error("Invalid base32 encoding: {0}")] 14 InvalidBase32(String), 15 16 /// Invalid base64url encoding 17 #[error("Invalid base64url encoding: {0}")] 18 InvalidBase64Url(String), 19 20 /// Signature verification failed 21 #[error("Signature verification failed")] 22 SignatureVerificationFailed, 23 24 /// Operation exceeds the 7500 byte limit 25 #[error("Operation exceeds 7500 byte limit: {0} bytes")] 26 OperationTooLarge(usize), 27 28 /// Invalid rotation keys 29 #[error("Invalid rotation keys: {0}")] 30 InvalidRotationKeys(String), 31 32 /// Invalid verification methods 33 #[error("Invalid verification methods: {0}")] 34 InvalidVerificationMethods(String), 35 36 /// Invalid service endpoint 37 #[error("Invalid service endpoint: {0}")] 38 InvalidService(String), 39 40 /// Operation chain validation failed 41 #[error("Operation chain validation failed: {0}")] 42 ChainValidationFailed(String), 43 44 /// DAG-CBOR encoding error 45 #[error("DAG-CBOR encoding error: {0}")] 46 DagCborError(String), 47 48 /// DAG-CBOR decoding error 49 #[error("DAG-CBOR decoding error: {0}")] 50 DagCborDecodeError(String), 51 52 /// Invalid did:key format 53 #[error("Invalid did:key format: {0}")] 54 InvalidDidKey(String), 55 56 /// Unsupported key type 57 #[error("Unsupported key type: {0}")] 58 UnsupportedKeyType(String), 59 60 /// Invalid CID format 61 #[error("Invalid CID format: {0}")] 62 InvalidCid(String), 63 64 /// Missing required field 65 #[error("Missing required field: {0}")] 66 MissingField(String), 67 68 /// Invalid operation type 69 #[error("Invalid operation type: {0}")] 70 InvalidOperationType(String), 71 72 /// No valid operations in chain 73 #[error("No valid operations in chain")] 74 EmptyChain, 75 76 /// First operation must be genesis 77 #[error("First operation must be genesis (prev must be null)")] 78 FirstOperationNotGenesis, 79 80 /// Invalid prev field 81 #[error("Invalid prev field: {0}")] 82 InvalidPrev(String), 83 84 /// Cryptographic error 85 #[error("Cryptographic error: {0}")] 86 CryptoError(String), 87 88 /// JSON serialization error 89 #[error("JSON error: {0}")] 90 JsonError(#[from] serde_json::Error), 91 92 /// Invalid also-known-as URI 93 #[error("Invalid also-known-as URI: {0}")] 94 InvalidAlsoKnownAs(String), 95 96 /// Too many entries 97 #[error("Too many {field}: maximum is {max}, got {actual}")] 98 TooManyEntries { 99 /// Name of the field with too many entries 100 field: String, 101 /// Maximum allowed entries 102 max: usize, 103 /// Actual number of entries 104 actual: usize, 105 }, 106 107 /// Duplicate entry 108 #[error("Duplicate {field}: {value}")] 109 DuplicateEntry { 110 /// Name of the field with duplicate entry 111 field: String, 112 /// Value of the duplicate entry 113 value: String, 114 }, 115 116 /// Invalid timestamp 117 #[error("Invalid timestamp: {0}")] 118 InvalidTimestamp(String), 119 120 /// Fork resolution error 121 #[error("Fork resolution error: {0}")] 122 ForkResolutionError(String), 123} 124 125/// Result type alias for atproto-plc operations 126pub type Result<T> = std::result::Result<T, PlcError>;