error.rs (2126B)
1 use thiserror::Error; 2 3 #[cfg(not(feature = "std"))] 4 use alloc::string::String; 5 6 #[cfg(all(feature = "std", feature = "json-file"))] 7 use radroots_runtime::RuntimeJsonError; 8 #[cfg(feature = "std")] 9 use std::{io, path::PathBuf}; 10 11 #[derive(Debug, Error)] 12 pub enum IdentityError { 13 #[cfg(feature = "std")] 14 #[error("identity file missing at {0}")] 15 NotFound(PathBuf), 16 17 #[cfg(feature = "std")] 18 #[error( 19 "identity file missing at {0} and generation is not permitted \ 20 (pass --allow-generate-identity)" 21 )] 22 GenerationNotAllowed(PathBuf), 23 24 #[cfg(feature = "std")] 25 #[error("failed to read identity file at {0}: {1}")] 26 Read(PathBuf, #[source] io::Error), 27 28 #[cfg(feature = "std")] 29 #[error("failed to create identity directory {0}: {1}")] 30 CreateDir(PathBuf, #[source] io::Error), 31 32 #[cfg(feature = "std")] 33 #[error("failed to write identity file at {0}: {1}")] 34 Write(PathBuf, #[source] io::Error), 35 36 #[error("invalid identity JSON: {0}")] 37 InvalidJson(#[from] serde_json::Error), 38 39 #[error("invalid secret key: {0}")] 40 InvalidSecretKey(#[from] nostr::key::Error), 41 42 #[cfg(feature = "nip49")] 43 #[error("failed to encrypt secret key: {0}")] 44 EncryptSecretKey(String), 45 46 #[cfg(feature = "nip49")] 47 #[error("invalid encrypted secret key: {0}")] 48 InvalidEncryptedSecretKey(String), 49 50 #[cfg(feature = "nip49")] 51 #[error("failed to decrypt encrypted secret key: {0}")] 52 DecryptEncryptedSecretKey(String), 53 54 #[error("invalid public key: {0}")] 55 InvalidPublicKey(String), 56 57 #[error("public key does not match secret key")] 58 PublicKeyMismatch, 59 60 #[error("unsupported identity file format")] 61 InvalidIdentityFormat, 62 63 #[cfg(all(feature = "std", feature = "json-file"))] 64 #[error(transparent)] 65 Store(#[from] RuntimeJsonError), 66 67 #[cfg(feature = "std")] 68 #[error(transparent)] 69 Paths(#[from] radroots_runtime_paths::RadrootsRuntimePathsError), 70 71 #[cfg(feature = "std")] 72 #[error("protected identity storage error at {path}: {message}")] 73 ProtectedStorage { path: PathBuf, message: String }, 74 }