Rust implementation of NextGraph, a Decentralized and local-first web 3.0 ecosystem
https://nextgraph.org
byzantine-fault-tolerancecrdtsdappsdecentralizede2eeeventual-consistencyjson-ldlocal-firstmarkdownocapoffline-firstp2pp2p-networkprivacy-protectionrdfrich-text-editorself-hostedsemantic-websparqlweb3collaboration
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.8 KiB
110 lines
2.8 KiB
9 months ago
|
// Copyright (c) 2022-2024 Niko Bonnieure, Par le Peuple, NextGraph.org developers
|
||
2 years ago
|
// All rights reserved.
|
||
|
// Licensed under the Apache License, Version 2.0
|
||
2 years ago
|
// <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
|
||
2 years ago
|
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
|
||
|
// at your option. All files in the project carrying such
|
||
|
// notice may not be copied, modified, or distributed except
|
||
|
// according to those terms.
|
||
|
|
||
|
//! Errors
|
||
|
|
||
8 months ago
|
use crate::commit::{CommitLoadError, CommitVerifyError};
|
||
|
use crate::store::StorageError;
|
||
8 months ago
|
use crate::types::BlockId;
|
||
1 year ago
|
use core::fmt;
|
||
|
use std::error::Error;
|
||
|
|
||
2 years ago
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||
|
#[repr(u16)]
|
||
2 years ago
|
pub enum NgError {
|
||
|
InvalidSignature,
|
||
7 months ago
|
IncompleteSignature,
|
||
2 years ago
|
SerializationError,
|
||
7 months ago
|
EncryptionError,
|
||
1 year ago
|
InvalidKey,
|
||
1 year ago
|
InvalidInvitation,
|
||
|
InvalidCreateAccount,
|
||
1 year ago
|
InvalidFileFormat,
|
||
8 months ago
|
InvalidArgument,
|
||
|
PermissionDenied,
|
||
8 months ago
|
CommitLoadError(CommitLoadError),
|
||
|
StorageError(StorageError),
|
||
|
NotFound,
|
||
7 months ago
|
IoError,
|
||
8 months ago
|
CommitVerifyError(CommitVerifyError),
|
||
7 months ago
|
LocalBrokerNotInitialized,
|
||
|
JsStorageReadError,
|
||
|
JsStorageWriteError(String),
|
||
|
CannotSaveWhenInMemoryConfig,
|
||
|
WalletNotFound,
|
||
|
WalletAlreadyAdded,
|
||
|
WalletAlreadyOpened,
|
||
|
WalletError(String),
|
||
|
BrokerError,
|
||
|
LockError,
|
||
|
SessionNotFound,
|
||
1 year ago
|
}
|
||
|
|
||
|
impl Error for NgError {}
|
||
|
|
||
|
impl fmt::Display for NgError {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||
7 months ago
|
match self {
|
||
|
Self::WalletError(string) => write!(f, "WalletError: {}", string),
|
||
|
_ => write!(f, "{:?}", self),
|
||
|
}
|
||
1 year ago
|
}
|
||
2 years ago
|
}
|
||
|
|
||
|
impl From<serde_bare::error::Error> for NgError {
|
||
8 months ago
|
fn from(_e: serde_bare::error::Error) -> Self {
|
||
2 years ago
|
NgError::SerializationError
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<ed25519_dalek::ed25519::Error> for NgError {
|
||
8 months ago
|
fn from(_e: ed25519_dalek::ed25519::Error) -> Self {
|
||
2 years ago
|
NgError::InvalidSignature
|
||
|
}
|
||
|
}
|
||
8 months ago
|
|
||
|
impl From<CommitLoadError> for NgError {
|
||
8 months ago
|
fn from(e: CommitLoadError) -> Self {
|
||
|
NgError::CommitLoadError(e)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<CommitVerifyError> for NgError {
|
||
|
fn from(e: CommitVerifyError) -> Self {
|
||
|
NgError::CommitVerifyError(e)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<StorageError> for NgError {
|
||
|
fn from(e: StorageError) -> Self {
|
||
|
NgError::StorageError(e)
|
||
8 months ago
|
}
|
||
|
}
|
||
8 months ago
|
|
||
|
/// Object parsing errors
|
||
|
#[derive(Debug)]
|
||
|
pub enum ObjectParseError {
|
||
|
/// Missing blocks
|
||
|
MissingBlocks(Vec<BlockId>),
|
||
|
/// 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,
|
||
|
}
|