// Copyright (c) 2022-2024 Niko Bonnieure, Par le Peuple, NextGraph.org developers // All rights reserved. // Licensed under the Apache License, Version 2.0 // // or the MIT license , // at your option. All files in the project carrying such // notice may not be copied, modified, or distributed except // according to those terms. //! Errors use crate::commit::{CommitLoadError, CommitVerifyError}; use crate::store::StorageError; use crate::types::BlockId; use core::fmt; use std::error::Error; #[derive(Debug, Eq, PartialEq, Clone)] #[repr(u16)] pub enum NgError { InvalidSignature, IncompleteSignature, SerializationError, EncryptionError, InvalidKey, InvalidInvitation, InvalidCreateAccount, InvalidFileFormat, InvalidArgument, PermissionDenied, CommitLoadError(CommitLoadError), StorageError(StorageError), NotFound, IoError, CommitVerifyError(CommitVerifyError), LocalBrokerNotInitialized, JsStorageReadError, JsStorageWriteError(String), CannotSaveWhenInMemoryConfig, WalletNotFound, WalletAlreadyAdded, WalletAlreadyOpened, WalletError(String), BrokerError, LockError, SessionNotFound, } impl Error for NgError {} impl fmt::Display for NgError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::WalletError(string) => write!(f, "WalletError: {}", string), _ => write!(f, "{:?}", self), } } } impl From for NgError { fn from(_e: serde_bare::error::Error) -> Self { NgError::SerializationError } } impl From for NgError { fn from(_e: ed25519_dalek::ed25519::Error) -> Self { NgError::InvalidSignature } } impl From for NgError { fn from(e: CommitLoadError) -> Self { NgError::CommitLoadError(e) } } impl From for NgError { fn from(e: CommitVerifyError) -> Self { NgError::CommitVerifyError(e) } } impl From for NgError { fn from(e: StorageError) -> Self { NgError::StorageError(e) } } /// Object parsing errors #[derive(Debug)] pub enum ObjectParseError { /// Missing blocks MissingBlocks(Vec), /// Missing root key MissingRootKey, /// Invalid BlockId encountered in the tree InvalidBlockId, /// Too many or too few children of a block InvalidChildren, /// Number of keys does not match number of children of a block InvalidKeys, /// Invalid CommitHeader object content InvalidHeader, /// Error deserializing content of a block BlockDeserializeError, /// Error deserializing content of the object ObjectDeserializeError, }