Skip to content

Commit

Permalink
Cleanup of some errors. (linera-io#2915)
Browse files Browse the repository at this point in the history
* Unify BcsError / JsonError / IoError.
* Make all the data show up in the error statements.
* Unify the treatment of `ArithmeticError`/ `ViewError`.
  • Loading branch information
MathieuDutSik authored Nov 19, 2024
1 parent 0d7ba39 commit c7fa7e8
Show file tree
Hide file tree
Showing 29 changed files with 66 additions and 69 deletions.
4 changes: 2 additions & 2 deletions linera-base/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub enum CryptoError {
InvalidSignature { error: String, type_name: String },
#[error("Signature for object {type_name} is missing")]
MissingSignature { type_name: String },
#[error("String contains non-hexadecimal digits")]
#[error(transparent)]
NonHexDigits(#[from] hex::FromHexError),
#[error(
"Byte slice has length {0} but a `CryptoHash` requires exactly {expected} bytes",
Expand All @@ -65,7 +65,7 @@ pub enum CryptoError {
expected = dalek::PUBLIC_KEY_LENGTH,
)]
IncorrectPublicKeySize(usize),
#[error("Could not parse integer")]
#[error("Could not parse integer: {0}")]
ParseIntError(#[from] ParseIntError),
}

Expand Down
2 changes: 1 addition & 1 deletion linera-base/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ impl CompressedBytecode {
while !decoder.get_ref().is_empty() {
decoder
.read_to_end(&mut bytes)
.expect("Reading from a slice in memory should not result in IO errors");
.expect("Reading from a slice in memory should not result in I/O errors");
}

Ok(Bytecode { bytes })
Expand Down
4 changes: 2 additions & 2 deletions linera-base/src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ macro_rules! doc_scalar {
#[derive(thiserror::Error, Debug)]
#[allow(missing_docs)]
pub enum BcsHexParseError {
#[error("Invalid BCS: {0}")]
Bcs(#[from] bcs::Error),
#[error(transparent)]
BcsError(#[from] bcs::Error),
#[error("Invalid hexadecimal: {0}")]
Hex(#[from] hex::FromHexError),
}
Expand Down
4 changes: 2 additions & 2 deletions linera-chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ use thiserror::Error;
pub enum ChainError {
#[error("Cryptographic error: {0}")]
CryptoError(#[from] CryptoError),
#[error("Arithmetic error: {0}")]
#[error(transparent)]
ArithmeticError(#[from] ArithmeticError),
#[error("Error in view operation: {0}")]
#[error(transparent)]
ViewError(ViewError),
#[error("Execution error: {0} during {1:?}")]
ExecutionError(Box<ExecutionError>, ChainExecutionContext),
Expand Down
2 changes: 1 addition & 1 deletion linera-client/src/client_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::{
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
IoError(#[from] std::io::Error),
#[error("a storage option must be provided")]
NoStorageOption,
#[error("wallet already exists at {0}")]
Expand Down
2 changes: 1 addition & 1 deletion linera-client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
IoError(#[from] std::io::Error),
#[error("chain error: {0}")]
Chain(#[from] linera_chain::ChainError),
#[error("persistence error: {0}")]
Expand Down
4 changes: 2 additions & 2 deletions linera-client/src/persistent/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ struct Lock(fs_err::File);
#[derive(Debug, thiserror::Error)]
enum ErrorInner {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
IoError(#[from] std::io::Error),
#[error("JSON error: {0}")]
Serde(#[from] serde_json::Error),
JsonError(#[from] serde_json::Error),
}

thiserror_context::impl_context!(Error(ErrorInner));
Expand Down
2 changes: 1 addition & 1 deletion linera-core/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub enum WorkerError {
#[error("Block was not signed by an authorized owner")]
InvalidOwner,

#[error("Operations in the block are not authenticated by the proper signer")]
#[error("Operations in the block are not authenticated by the proper signer: {0}")]
InvalidSigner(Owner),

// Chaining
Expand Down
5 changes: 1 addition & 4 deletions linera-ethereum/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ pub enum EthereumServiceError {
#[error("Failed to deploy the smart contract")]
DeployError,

#[error("Json error occurred")]
JsonError,

#[error("Unsupported Ethereum type")]
UnsupportedEthereumTypeError,

Expand All @@ -65,7 +62,7 @@ pub enum EthereumServiceError {

/// `serde_json` error
#[error(transparent)]
SerdeJsonError(#[from] serde_json::Error),
JsonError(#[from] serde_json::Error),

/// RPC error
#[error(transparent)]
Expand Down
10 changes: 5 additions & 5 deletions linera-execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,16 @@ pub enum ExecutionError {
OwnerIsNone,
#[error("Application is not authorized to perform system operations on this chain: {0:}")]
UnauthorizedApplication(UserApplicationId),
#[error("Failed to make network reqwest")]
#[error("Failed to make network reqwest: {0}")]
ReqwestError(#[from] reqwest::Error),
#[error("Encountered IO error")]
#[error("Encountered I/O error: {0}")]
IoError(#[from] std::io::Error),
#[error("More recorded oracle responses than expected")]
UnexpectedOracleResponse,
#[error("Invalid JSON: {}", .0)]
Json(#[from] serde_json::Error),
#[error("Invalid JSON: {0}")]
JsonError(#[from] serde_json::Error),
#[error(transparent)]
Bcs(#[from] bcs::Error),
BcsError(#[from] bcs::Error),
#[error("Recorded response for oracle query has the wrong type")]
OracleResponseMismatch,
#[error("Assertion failed: local time {local_time} is not earlier than {timestamp}")]
Expand Down
2 changes: 1 addition & 1 deletion linera-execution/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub enum WasmExecutionError {
#[error("Failed to instantiate Wasm module: {_0}")]
InstantiateModuleWithWasmer(#[from] Box<::wasmer::InstantiationError>),
#[cfg(with_wasmtime)]
#[error("Failed to create and configure Wasmtime runtime")]
#[error("Failed to create and configure Wasmtime runtime: {_0}")]
CreateWasmtimeEngine(#[source] anyhow::Error),
#[cfg(with_wasmer)]
#[error(
Expand Down
2 changes: 1 addition & 1 deletion linera-rpc/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum GrpcError {
#[error("failed to communicate cross-chain queries: {0}")]
CrossChain(#[from] tonic::Status),

#[error("failed to execute task to completion")]
#[error("failed to execute task to completion: {0}")]
Join(#[from] futures::channel::oneshot::Canceled),

#[error("failed to parse socket address: {0}")]
Expand Down
2 changes: 1 addition & 1 deletion linera-rpc/src/mass_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::RpcMessage;
#[derive(Error, Debug)]
pub enum MassClientError {
#[error("io error: {0}")]
Io(#[from] std::io::Error),
IoError(#[from] std::io::Error),
#[error("tonic transport: {0}")]
TonicTransport(#[from] crate::grpc::transport::Error),
#[error("conversion error: {0}")]
Expand Down
6 changes: 3 additions & 3 deletions linera-rpc/src/simple/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ impl SimpleClient {
// Send message
timer::timeout(self.send_timeout, stream.send(message))
.await
.map_err(|timeout| codec::Error::Io(timeout.into()))??;
.map_err(|timeout| codec::Error::IoError(timeout.into()))??;
// Wait for reply
timer::timeout(self.recv_timeout, stream.next())
.await
.map_err(|timeout| codec::Error::Io(timeout.into()))?
.map_err(|timeout| codec::Error::IoError(timeout.into()))?
.transpose()?
.ok_or_else(|| codec::Error::Io(std::io::ErrorKind::UnexpectedEof.into()))
.ok_or_else(|| codec::Error::IoError(std::io::ErrorKind::UnexpectedEof.into()))
}

async fn query<Response>(&self, query: RpcMessage) -> Result<Response, Response::Error>
Expand Down
10 changes: 5 additions & 5 deletions linera-rpc/src/simple/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ impl Decoder for Codec {
/// Errors that can arise during transmission or reception of [`RpcMessage`]s.
#[derive(Debug, Error)]
pub enum Error {
#[error("IO error in the underlying transport")]
Io(#[from] io::Error),
#[error("I/O error in the underlying transport: {0}")]
IoError(#[from] io::Error),

#[error("Failed to deserialize an incoming message")]
#[error("Failed to deserialize an incoming message: {0}")]
Deserialization(#[source] bincode::ErrorKind),

#[error("Failed to serialize outgoing message")]
#[error("Failed to serialize outgoing message: {0}")]
Serialization(#[source] bincode::ErrorKind),

#[error("RpcMessage is too big to fit in a protocol frame: \
Expand All @@ -104,7 +104,7 @@ pub enum Error {
impl From<Error> for NodeError {
fn from(error: Error) -> NodeError {
match error {
Error::Io(io_error) => NodeError::ClientIoError {
Error::IoError(io_error) => NodeError::ClientIoError {
error: format!("{}", io_error),
},
err => {
Expand Down
6 changes: 3 additions & 3 deletions linera-rpc/src/simple/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ where
/// Handles an error while receiving a message.
async fn handle_error(&mut self, error: codec::Error) -> Result<(), std::io::Error> {
match error {
codec::Error::Io(io_error) => {
error!("IO error in UDP server: {io_error}");
codec::Error::IoError(io_error) => {
error!("I/O error in UDP server: {io_error}");
self.shutdown().await;
Err(io_error)
}
Expand Down Expand Up @@ -485,7 +485,7 @@ where
fn handle_error(&self, error: codec::Error) {
if !matches!(
&error,
codec::Error::Io(error)
codec::Error::IoError(error)
if error.kind() == io::ErrorKind::UnexpectedEof
|| error.kind() == io::ErrorKind::ConnectionReset
) {
Expand Down
4 changes: 2 additions & 2 deletions linera-sdk/src/views/system_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ pub enum KeyValueStoreError {
KeyTooLong,

/// BCS serialization error.
#[error("BCS error: {0}")]
Bcs(#[from] bcs::Error),
#[error(transparent)]
BcsError(#[from] bcs::Error),
}

impl linera_views::store::KeyValueStoreError for KeyValueStoreError {
Expand Down
8 changes: 4 additions & 4 deletions linera-service/src/node_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ enum NodeServiceError {
ChainClientError(#[from] ChainClientError),
#[error(transparent)]
BcsHexError(#[from] BcsHexParseError),
#[error("could not decode query string")]
#[error("could not decode query string: {0}")]
QueryStringError(#[from] hex::FromHexError),
#[error(transparent)]
BcsError(#[from] bcs::Error),
Expand All @@ -96,11 +96,11 @@ enum NodeServiceError {
GraphQLParseError { error: String },
#[error("malformed application response")]
MalformedApplicationResponse,
#[error("application service error")]
#[error("application service error: {errors:?}")]
ApplicationServiceError { errors: Vec<String> },
#[error("chain ID not found")]
#[error("chain ID not found: {chain_id}")]
UnknownChainId { chain_id: String },
#[error("malformed chain ID")]
#[error("malformed chain ID: {0}")]
InvalidChainId(CryptoError),
}

Expand Down
4 changes: 2 additions & 2 deletions linera-storage-service/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ pub enum ServiceStoreError {
VarError(#[from] std::env::VarError),

/// An error occurred during BCS serialization
#[error("An error occurred during BCS serialization")]
Serialization(#[from] bcs::Error),
#[error(transparent)]
BcsError(#[from] bcs::Error),
}

impl KeyValueStoreError for ServiceStoreError {
Expand Down
4 changes: 2 additions & 2 deletions linera-version/src/version_info/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ pub enum Error {
#[error("no such package: {0}")]
NoSuchPackage(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
IoError(#[from] std::io::Error),
#[error("glob error: {0}")]
Glob(#[from] glob::GlobError),
#[error("pattern error: {0}")]
Pattern(#[from] glob::PatternError),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
JsonError(#[from] serde_json::Error),
}

struct Outcome {
Expand Down
4 changes: 2 additions & 2 deletions linera-views/src/backends/dual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ where
#[derive(Error, Debug)]
pub enum DualStoreError<E1, E2> {
/// Serialization error with BCS.
#[error("BCS error: {0}")]
Bcs(#[from] bcs::Error),
#[error(transparent)]
BcsError(#[from] bcs::Error),

/// First store.
#[error("Error in first store: {0}")]
Expand Down
2 changes: 1 addition & 1 deletion linera-views/src/backends/dynamo_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ pub enum DynamoDbStoreInternalError {
JournalConsistencyError(#[from] JournalConsistencyError),

/// Missing database
#[error("Missing database")]
#[error("Missing database: {0}")]
MissingDatabase(String),

/// Already existing database
Expand Down
4 changes: 2 additions & 2 deletions linera-views/src/backends/indexed_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ pub use testing::*;
#[derive(Error, Debug)]
pub enum IndexedDbStoreError {
/// Serialization error with BCS.
#[error("BCS error: {0}")]
Bcs(#[from] bcs::Error),
#[error(transparent)]
BcsError(#[from] bcs::Error),

/// The value is too large for the IndexedDbStore
#[error("The value is too large for the IndexedDbStore")]
Expand Down
4 changes: 2 additions & 2 deletions linera-views/src/backends/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ pub fn create_test_memory_store() -> MemoryStore {
#[derive(Error, Debug)]
pub enum MemoryStoreError {
/// Serialization error with BCS.
#[error("BCS error: {0}")]
Bcs(#[from] bcs::Error),
#[error(transparent)]
BcsError(#[from] bcs::Error),

/// The value is too large for the MemoryStore
#[error("The value is too large for the MemoryStore")]
Expand Down
8 changes: 4 additions & 4 deletions linera-views/src/backends/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,15 +557,15 @@ pub enum RocksDbStoreInternalError {
NonDirectoryNamespace,

/// Error converting `OsString` to `String`
#[error("error in the conversion from OsString")]
#[error("error in the conversion from OsString: {0:?}")]
IntoStringError(OsString),

/// The key must have at most 8M
#[error("The key must have at most 8M")]
KeyTooLong,

/// Missing database
#[error("Missing database")]
#[error("Missing database: {0}")]
MissingDatabase(String),

/// Invalid namespace
Expand All @@ -581,8 +581,8 @@ pub enum RocksDbStoreInternalError {
FsError(#[from] std::io::Error),

/// BCS serialization error.
#[error("BCS error: {0}")]
Bcs(#[from] bcs::Error),
#[error(transparent)]
BcsError(#[from] bcs::Error),
}

/// A path and the guard for the temporary directory if needed
Expand Down
6 changes: 3 additions & 3 deletions linera-views/src/backends/scylla_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ pub struct ScyllaDbStoreInternal {
#[derive(Error, Debug)]
pub enum ScyllaDbStoreError {
/// BCS serialization error.
#[error("BCS error: {0}")]
Bcs(#[from] bcs::Error),
#[error(transparent)]
BcsError(#[from] bcs::Error),

/// The key must have at most 1M bytes
#[error("The key must have at most 1M")]
Expand All @@ -409,7 +409,7 @@ pub enum ScyllaDbStoreError {
InvalidTableName,

/// Missing database
#[error("Missing database")]
#[error("Missing database: {0}")]
MissingDatabase(String),

/// Already existing database
Expand Down
4 changes: 2 additions & 2 deletions linera-views/src/views/key_value_store_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,8 @@ pub enum ViewContainerError {
ViewError(#[from] ViewError),

/// BCS serialization error.
#[error("BCS error: {0}")]
Bcs(#[from] bcs::Error),
#[error(transparent)]
BcsError(#[from] bcs::Error),
}

#[cfg(with_testing)]
Expand Down
Loading

0 comments on commit c7fa7e8

Please sign in to comment.