diff --git a/src/cli/error.rs b/src/cli/error.rs index 77b48bf25f..c7b921b7ff 100644 --- a/src/cli/error.rs +++ b/src/cli/error.rs @@ -7,8 +7,8 @@ use opentelemetry::metrics::MetricsError; use opentelemetry::trace::TraceError; use tokio::task::JoinError; -use crate::core::rest; use crate::core::valid::ValidationError; +use crate::core::{error, rest}; #[derive(From, thiserror::Error, Debug)] pub enum Error { @@ -24,7 +24,7 @@ pub enum Error { #[error("IO Error")] IO(std::io::Error), - #[error("Telemetry Trace Error : {0}")] + #[error("Telemetry Trace Error : {}", _0)] TelemetryTrace(String), #[error("Failed to send message")] @@ -93,8 +93,11 @@ pub enum Error { #[error("Reqwest error")] Reqwest(reqwest::Error), - #[error("Validation Error : {0}")] + #[error("Validation Error : {}", _0)] Validation(ValidationError), + + #[error("Core Error")] + CoreError(error::Error), } pub type Result = std::result::Result; diff --git a/src/cli/generator/generator.rs b/src/cli/generator/generator.rs index 8c4c884ece..dc7c29d738 100644 --- a/src/cli/generator/generator.rs +++ b/src/cli/generator/generator.rs @@ -61,7 +61,8 @@ impl Generator { .as_str(), ) .with_default(false) - .prompt()?; + .prompt() + .map_err(|e| Error::Inquire(e.to_string()))?; if !should_overwrite { return Ok(false); } @@ -71,7 +72,7 @@ impl Generator { async fn read(&self) -> Result, Error> { let config_path = &self.config_path; - let source = ConfigSource::detect(config_path)?; + let source = ConfigSource::detect(config_path).map_err(|_| Error::UnsupportedFileFormat)?; let config_content = self.runtime.file.read(config_path).await?; let config: Config = match source { diff --git a/src/cli/javascript/runtime.rs b/src/cli/javascript/runtime.rs index 3f8d6d8b57..c0fde15c87 100644 --- a/src/cli/javascript/runtime.rs +++ b/src/cli/javascript/runtime.rs @@ -94,8 +94,8 @@ impl WorkerIO for Runtime { if let Some(runtime) = &self.tokio_runtime { runtime .spawn(async move { - init_rt(script)?; - call(name, event).map_err(worker::Error::from) + let _ = init_rt(script).map_err(|e| worker::Error::CLI(e.to_string())); + call(name, event).map_err(|e| worker::Error::CLI(e.to_string())) }) .await .map_err(|_| worker::Error::ExecutionFailed)? @@ -118,10 +118,10 @@ impl WorkerIO for Runtime { if let Some(runtime) = &self.tokio_runtime { runtime .spawn(async move { - init_rt(script)?; + let _ = init_rt(script).map_err(|e| worker::Error::CLI(e.to_string())); execute_inner(name, value) .map(Some) - .map_err(worker::Error::from) + .map_err(|e| worker::Error::CLI(e.to_string())) }) .await .map_err(|_| worker::Error::ExecutionFailed)? diff --git a/src/cli/runtime/mod.rs b/src/cli/runtime/mod.rs index 70a97100f4..f2721be5e4 100644 --- a/src/cli/runtime/mod.rs +++ b/src/cli/runtime/mod.rs @@ -95,7 +95,8 @@ pub async fn confirm_and_write( if file_exists { let confirm = Confirm::new(&format!("Do you want to overwrite the file {path}?")) .with_default(false) - .prompt()?; + .prompt() + .map_err(|e| error::file::Error::Inquire(e.to_string()))?; if !confirm { return Ok(()); @@ -116,7 +117,8 @@ pub async fn create_directory(folder_path: &str) -> Result<(), error::file::Erro folder_path )) .with_default(false) - .prompt()?; + .prompt() + .map_err(|e| error::file::Error::Inquire(e.to_string()))?; if confirm { fs::create_dir_all(folder_path)?; @@ -132,5 +134,7 @@ pub fn select_prompt( message: &str, options: Vec, ) -> Result { - Ok(Select::new(message, options).prompt()?) + Select::new(message, options) + .prompt() + .map_err(|e| error::file::Error::Inquire(e.to_string())) } diff --git a/src/cli/tc/run.rs b/src/cli/tc/run.rs index 0b4cf8fb4c..7e6414808c 100644 --- a/src/cli/tc/run.rs +++ b/src/cli/tc/run.rs @@ -5,10 +5,10 @@ use dotenvy::dotenv; use super::helpers::TRACKER; use super::{check, gen, init, start}; use crate::cli::command::{Cli, Command}; +use crate::cli::error::Error; use crate::cli::{self, update_checker}; use crate::core::blueprint::Blueprint; use crate::core::config::reader::ConfigReader; -use crate::core::error::Error; use crate::core::runtime::TargetRuntime; pub async fn run() -> Result<(), Error> { diff --git a/src/cli/tc/start.rs b/src/cli/tc/start.rs index 27bc0f2a0e..57ad8cbfb9 100644 --- a/src/cli/tc/start.rs +++ b/src/cli/tc/start.rs @@ -1,8 +1,8 @@ use super::helpers::log_endpoint_set; +use crate::cli::error::Error; use crate::cli::fmt::Fmt; use crate::cli::server::Server; use crate::core::config::reader::ConfigReader; -use crate::core::error::Error; pub(super) async fn start_command( file_paths: Vec, diff --git a/src/core/error.rs b/src/core/error.rs index b45c73fc72..06f48205d1 100644 --- a/src/core/error.rs +++ b/src/core/error.rs @@ -1,8 +1,8 @@ +use std::fmt::Display; use std::str::Utf8Error; use std::string::FromUtf8Error; use derive_more::From; -use inquire::InquireError; use opentelemetry::metrics::MetricsError; use opentelemetry::trace::TraceError; use prost_reflect::DescriptorError; @@ -13,8 +13,6 @@ use super::grpc::error::Error as GrpcError; use super::ir; use super::rest::error::Error as RestError; use super::valid::ValidationError; -use crate::cli::error::Error as CLIError; -use crate::cli::generator::source::UnsupportedFileFormat; #[derive(From, thiserror::Error, Debug)] pub enum Error { @@ -24,7 +22,7 @@ pub enum Error { #[error("Utf8 Error")] FromUtf8(FromUtf8Error), - #[error("Validation Error : {0}")] + #[error("Validation Error : {}", _0)] Validation(ValidationError), #[error("Serde Json Error")] @@ -36,7 +34,7 @@ pub enum Error { #[error("Descriptor Error")] Descriptor(DescriptorError), - #[error("Expected fully-qualified name for reference type but got {0}")] + #[error("Expected fully-qualified name for reference type but got {}", _0)] InvalidReferenceTypeName(String), #[error("Package name is required")] @@ -105,7 +103,7 @@ pub enum Error { #[error("Failed to execute request")] RequestExecutionFailed, - #[error("File Error: {0}")] + #[error("File Error: {}", _0)] File(file::Error), #[error("Http Error")] @@ -114,13 +112,7 @@ pub enum Error { #[error("Worker Error")] Worker(worker::Error), - #[error("CLI Error")] - CLI(CLIError), - - #[error("Inquire Error")] - Inquire(InquireError), - - #[error("IRError {0}")] + #[error("IRError {}", _0)] IRError(ir::Error), #[error("Serde URL Encoded Error")] @@ -169,7 +161,7 @@ pub enum Error { Headers(headers::Error), #[error("Unsupported File Format")] - UnsupportedFileFormat(UnsupportedFileFormat), + UnsupportedFileFormat, #[error("Failed to match type_name")] TypenameMatchFailed, @@ -179,61 +171,69 @@ pub enum Error { #[error("Failed to find corresponding type for value")] MissingTypeForValue, + + #[error("CLI Error : {}", _0)] + #[from(ignore)] + CLI(String), + + #[error("Inquire Error : {}", _0)] + #[from(ignore)] + Inquire(String), } pub mod file { use std::string::FromUtf8Error; - use derive_more::From; - use inquire::InquireError; + use derive_more::{DebugCustom, From}; - #[derive(From, thiserror::Error, Debug)] + #[derive(From, DebugCustom)] pub enum Error { - #[error("No such file or directory (os error 2)")] + #[debug(fmt = "No such file or directory (os error 2)")] NotFound, - #[error("No permission to access the file")] + #[debug(fmt = "No permission to access the file")] NoPermission, - #[error("Access denied")] + #[debug(fmt = "Access denied")] AccessDenied, - #[error("Invalid file format")] + #[debug(fmt = "Invalid file format")] InvalidFormat, - #[error("Invalid file path")] + #[debug(fmt = "Invalid file path")] InvalidFilePath, - #[error("Invalid OS string")] + #[debug(fmt = "Invalid OS string")] InvalidOsString, - #[error("Failed to read file : {0}")] + #[debug(fmt = "Failed to read file : {}", _0)] FileReadFailed(String), - #[error("Failed to write file : {0}")] + #[debug(fmt = "Failed to write file : {}", _0)] #[from(ignore)] FileWriteFailed(String), - #[error("Std IO Error")] + #[debug(fmt = "Std IO Error")] StdIO(std::io::Error), - #[error("Utf8 Error")] + #[debug(fmt = "Utf8 Error")] Utf8(FromUtf8Error), - #[error("File writing not supported on Lambda.")] + #[debug(fmt = "File writing not supported on Lambda.")] LambdaFileWriteNotSupported, - #[error("Cannot write to a file in an execution spec")] + #[debug(fmt = "Cannot write to a file in an execution spec")] ExecutionSpecFileWriteFailed, - #[error("Cloudflare Worker Execution Error : {0}")] + #[debug(fmt = "Cloudflare Worker Execution Error : {}", _0)] #[from(ignore)] Cloudflare(String), - #[error("Inquire Error")] - Inquire(InquireError), + #[debug(fmt = "Inquire Error : {}", _0)] + #[from(ignore)] + Inquire(String), - #[error("Serde yaml Error")] + #[debug(fmt = "Serde yaml Error")] SerdeYaml(serde_yaml::Error), } } @@ -269,7 +269,7 @@ pub mod http { #[error("Serde Json Error")] SerdeJson(serde_json::Error), - #[error("Unable to find key {0} in query params")] + #[error("Unable to find key {} in query params", _0)] #[from(ignore)] KeyNotFound(String), @@ -307,66 +307,128 @@ pub mod http { } pub mod worker { - use derive_more::From; + use derive_more::{DebugCustom, From}; - #[derive(From, thiserror::Error, Debug)] + #[derive(From, DebugCustom)] pub enum Error { - #[error("Failed to initialize worker")] + #[debug(fmt = "Failed to initialize worker")] InitializationFailed, - #[error("Worker execution error")] + #[debug(fmt = "Worker execution error")] ExecutionFailed, - #[error("Worker communication error")] + #[debug(fmt = "Worker communication error")] Communication, - #[error("Serde Json Error")] + #[debug(fmt = "Serde Json Error")] SerdeJson(serde_json::Error), - #[error("Request Clone Failed")] + #[debug(fmt = "Request Clone Failed")] RequestCloneFailed, - #[error("Hyper Header To Str Error")] + #[debug(fmt = "Hyper Header To Str Error")] HyperHeaderStr(hyper::header::ToStrError), - #[error("CLI Error")] - CLI(crate::cli::error::Error), - - #[error("JS Runtime Stopped Error")] + #[debug(fmt = "JS Runtime Stopped Error")] JsRuntimeStopped, + + #[debug(fmt = "CLI Error : {}", _0)] + CLI(String), } } pub mod graphql { - use derive_more::From; + use derive_more::{DebugCustom, From}; use super::http; - #[derive(From, thiserror::Error, Debug)] + #[derive(From, DebugCustom)] pub enum Error { - #[error("Serde Json Error")] + #[debug(fmt = "Serde Json Error")] SerdeJson(serde_json::Error), - #[error("HTTP Error")] + #[debug(fmt = "HTTP Error")] Http(http::Error), } } pub mod cache { - use derive_more::From; + use derive_more::{DebugCustom, From}; - #[derive(From, thiserror::Error, Debug)] + #[derive(From, DebugCustom)] pub enum Error { - #[error("Serde Json Error")] + #[debug(fmt = "Serde Json Error")] SerdeJson(serde_json::Error), - #[error("Worker Error : {0}")] + #[debug(fmt = "Worker Error : {}", _0)] Worker(String), - #[error("Kv Error : {0}")] + #[debug(fmt = "Kv Error : {}", _0)] #[from(ignore)] Kv(String), } } +impl Display for file::Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + file::Error::NotFound => write!(f, "No such file or directory (os error 2)"), + file::Error::NoPermission => write!(f, "No permission to access the file"), + file::Error::AccessDenied => write!(f, "Access denied"), + file::Error::InvalidFormat => write!(f, "Invalid file format"), + file::Error::InvalidFilePath => write!(f, "Invalid file path"), + file::Error::InvalidOsString => write!(f, "Invalid OS string"), + file::Error::FileReadFailed(path) => write!(f, "Failed to read file: {}", path), + file::Error::FileWriteFailed(path) => write!(f, "Failed to write file: {}", path), + file::Error::StdIO(_) => write!(f, "Std IO Error"), + file::Error::Utf8(_) => write!(f, "Utf8 Error"), + file::Error::LambdaFileWriteNotSupported => { + write!(f, "File writing not supported on Lambda.") + } + file::Error::ExecutionSpecFileWriteFailed => { + write!(f, "Cannot write to a file in an execution spec") + } + file::Error::Cloudflare(error) => { + write!(f, "Cloudflare Worker Execution Error: {}", error) + } + file::Error::Inquire(error) => write!(f, "Inquire Error: {}", error), + file::Error::SerdeYaml(_) => write!(f, "Serde yaml Error"), + } + } +} + +impl Display for worker::Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + worker::Error::InitializationFailed => write!(f, "Failed to initialize worker"), + worker::Error::ExecutionFailed => write!(f, "Worker execution error"), + worker::Error::Communication => write!(f, "Worker communication error"), + worker::Error::SerdeJson(_) => write!(f, "Serde Json Error"), + worker::Error::RequestCloneFailed => write!(f, "Request Clone Failed"), + worker::Error::HyperHeaderStr(_) => write!(f, "Hyper Header To Str Error"), + worker::Error::JsRuntimeStopped => write!(f, "JS Runtime Stopped Error"), + worker::Error::CLI(msg) => write!(f, "CLI Error: {}", msg), + } + } +} + +impl Display for graphql::Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + graphql::Error::SerdeJson(_) => write!(f, "Serde Json Error"), + graphql::Error::Http(_) => write!(f, "HTTP Error"), + } + } +} + +impl Display for cache::Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + cache::Error::SerdeJson(_) => write!(f, "Serde Json Error"), + cache::Error::Worker(error) => write!(f, "Worker Error: {}", error), + cache::Error::Kv(error) => write!(f, "Kv Error: {}", error), + } + } +} + pub type Result = std::result::Result; diff --git a/src/core/grpc/error.rs b/src/core/grpc/error.rs index 4b642e2417..68660f5371 100644 --- a/src/core/grpc/error.rs +++ b/src/core/grpc/error.rs @@ -1,49 +1,74 @@ -use derive_more::From; +use std::fmt::Display; + +use derive_more::{DebugCustom, From}; use prost_reflect::DescriptorError; use serde_json; use crate::core::blueprint::GrpcMethod; -#[derive(From, thiserror::Error, Debug)] +#[derive(From, DebugCustom)] pub enum Error { - #[error("Serde Json Error : {0}")] + #[debug(fmt = "Serde Json Error : {}", _0)] SerdeJsonError(serde_json::Error), - #[error("Prost Encode Error")] + #[debug(fmt = "Prost Encode Error")] ProstEncodeError(prost::EncodeError), - #[error("Prost Decode Error")] + #[debug(fmt = "Prost Decode Error")] ProstDecodeError(prost::DecodeError), - #[error("Empty Response")] + #[debug(fmt = "Empty Response")] EmptyResponse, - #[error("Couldn't resolve message")] + #[debug(fmt = "Couldn't resolve message")] MessageNotResolved, - #[error("Descriptor pool error")] + #[debug(fmt = "Descriptor pool error")] DescriptorPoolError(DescriptorError), - #[error("Protox Parse Error")] + #[debug(fmt = "Protox Parse Error")] ProtoxParseError(protox_parse::ParseError), - #[error("Couldn't find method {}", ._0.name)] + #[debug(fmt = "Couldn't find method {}", ._0.name)] MissingMethod(GrpcMethod), - #[error("Unable to find list field on type")] + #[debug(fmt = "Unable to find list field on type")] MissingListField, - #[error("Field not found : {0}")] + #[debug(fmt = "Field not found : {}", _0)] #[from(ignore)] MissingField(String), - #[error("Couldn't find definitions for service {0}")] + #[debug(fmt = "Couldn't find definitions for service {}", _0)] #[from(ignore)] MissingService(String), - #[error("Failed to parse input according to type {0}")] + #[debug(fmt = "Failed to parse input according to type {}", _0)] #[from(ignore)] InputParsingFailed(String), } +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::SerdeJsonError(e) => write!(f, "Serde Json Error: {}", e), + Error::ProstEncodeError(_) => write!(f, "Prost Encode Error"), + Error::ProstDecodeError(_) => write!(f, "Prost Decode Error"), + Error::EmptyResponse => write!(f, "Empty Response"), + Error::MessageNotResolved => write!(f, "Couldn't resolve message"), + Error::DescriptorPoolError(_) => write!(f, "Descriptor pool error"), + Error::ProtoxParseError(_) => write!(f, "Protox Parse Error"), + Error::MissingMethod(method) => write!(f, "Couldn't find method {}", method.name), + Error::MissingListField => write!(f, "Unable to find list field on type"), + Error::MissingField(field) => write!(f, "Field not found : {}", field), + Error::MissingService(service) => { + write!(f, "Couldn't find definitions for service {}", service) + } + Error::InputParsingFailed(input_type) => { + write!(f, "Failed to parse input according to type {}", input_type) + } + } + } +} + pub type Result = std::result::Result; diff --git a/src/core/rest/directive.rs b/src/core/rest/directive.rs index f489a960db..d7992438d8 100644 --- a/src/core/rest/directive.rs +++ b/src/core/rest/directive.rs @@ -215,7 +215,10 @@ mod tests { let query = generate_query_with_directive(&query, DEFAULT_QUERY_PARAM); let directive = query_to_directive(&query); // Will panic - Rest::try_from(&directive).unwrap(); + match Rest::try_from(&directive) { + Ok(_) => panic!("Test should have failed but it succeeded"), + Err(e) => panic!("{}", e), + } } #[test] @@ -226,6 +229,9 @@ mod tests { let query = generate_query_with_directive(&query, DEFAULT_QUERY_PARAM); let directive = query_to_directive(&query); // Will panic - Rest::try_from(&directive).unwrap(); + match Rest::try_from(&directive) { + Ok(_) => panic!("Test should have failed but it succeeded"), + Err(e) => panic!("{}", e), + } } } diff --git a/src/core/rest/error.rs b/src/core/rest/error.rs index 2404cbe248..a55fdce0e0 100644 --- a/src/core/rest/error.rs +++ b/src/core/rest/error.rs @@ -3,12 +3,12 @@ use std::str::ParseBoolError; use async_graphql::parser::types::{Directive, Type}; use async_graphql::Name; -use derive_more::{DebugCustom, From}; +use derive_more::From; use serde_json; use crate::core::valid::ValidationError; -#[derive(From, thiserror::Error, DebugCustom)] +#[derive(From, thiserror::Error, Debug)] pub enum Error { #[error("Unexpected Named Type: {}", 0.to_string())] #[from(ignore)] @@ -21,18 +21,15 @@ pub enum Error { SerdeJsonError(serde_json::Error), #[error("{msg}: {directive:?}")] - #[debug(fmt = "{msg}: {directive:?}")] Missing { msg: String, directive: Directive }, #[error("Method not provided in the directive")] - #[debug(fmt = "Method not provided in the directive")] MissingMethod, #[error("Path not provided in the directive")] - #[debug(fmt = "Path not provided in the directive")] MissingPath, - #[error("Undefined query param: {0}")] + #[error("Undefined query param: {}", _0)] UndefinedQueryParam(String), #[error("Parse Integer Error")] @@ -45,10 +42,9 @@ pub enum Error { ParseBooleanError(ParseBoolError), #[error("Undefined param : {key} in {input}")] - #[debug(fmt = "Undefined param : {key} in {input}")] UndefinedParam { key: String, input: String }, - #[error("Validation Error : {0}")] + #[error("Validation Error : {}", _0)] ValidationError(ValidationError), #[error("Async Graphql Parser Error")] diff --git a/src/main.rs b/src/main.rs index 0f832973f5..1ee6d3f799 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,7 @@ fn run_blocking() -> Result<(), Error> { .enable_all() .build()?; rt.block_on(async { tailcall::cli::run().await }) + .map_err(|e| Error::CLI(e.to_string())) } fn main() -> Result<(), Error> { diff --git a/tailcall-cloudflare/src/error.rs b/tailcall-cloudflare/src/error.rs index 626ad51ccd..40252c4056 100644 --- a/tailcall-cloudflare/src/error.rs +++ b/tailcall-cloudflare/src/error.rs @@ -8,7 +8,7 @@ pub enum Error { #[error("Worker Error")] Worker(worker::Error), - #[error("File {0} was not found in bucket")] + #[error("File {} was not found in bucket", _0)] MissingFileInBucket(String), #[error("BUCKET var is not set")] @@ -20,7 +20,7 @@ pub enum Error { #[error("FromUtf8 Error")] FromUtf8(FromUtf8Error), - #[error("Unsupported HTTP method: {0}")] + #[error("Unsupported HTTP method: {}", _0)] #[from(ignore)] UnsupportedHttpMethod(String), diff --git a/tailcall-fixtures/error.rs b/tailcall-fixtures/error.rs index 826aee4059..763e4392a1 100644 --- a/tailcall-fixtures/error.rs +++ b/tailcall-fixtures/error.rs @@ -1,15 +1,27 @@ -use derive_more::From; +use std::fmt::Display; -#[derive(From, thiserror::Error, Debug)] +use derive_more::{DebugCustom, From}; + +#[derive(From, DebugCustom)] pub enum Error { - #[error("Std Fmt Error")] + #[debug(fmt = "Std Fmt Error")] StdFmt(std::fmt::Error), - #[error("Std IO Error")] + #[debug(fmt = "Std IO Error")] IO(std::io::Error), - #[error("Failed to resolve filename")] + #[debug(fmt = "Failed to resolve filename")] FilenameNotResolved, } +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::StdFmt(_) => write!(f, "Std Fmt Error"), + Error::IO(_) => write!(f, "Std IO Error"), + Error::FilenameNotResolved => write!(f, "Failed to resolve filename"), + } + } +} + pub type Result = std::result::Result; diff --git a/tailcall-prettier/src/error.rs b/tailcall-prettier/src/error.rs index 51017c9026..87d8591951 100644 --- a/tailcall-prettier/src/error.rs +++ b/tailcall-prettier/src/error.rs @@ -1,27 +1,43 @@ +use std::fmt::Display; use std::string::FromUtf8Error; -use derive_more::From; +use derive_more::{DebugCustom, From}; use tokio::task::JoinError; -#[derive(From, thiserror::Error, Debug)] +#[derive(From, DebugCustom)] pub enum Error { - #[error("Std IO Error")] + #[debug(fmt = "Std IO Error")] IO(std::io::Error), - #[error("Join Error")] + #[debug(fmt = "Join Error")] Join(JoinError), - #[error("From Utf8 Error")] + #[debug(fmt = "From Utf8 Error")] FromUtf8(FromUtf8Error), - #[error("Prettier formatting failed: {0}")] + #[debug(fmt = "Prettier formatting failed: {}", _0)] PrettierFormattingFailed(String), - #[error("No file extension found")] + #[debug(fmt = "No file extension found")] FileExtensionNotFound, - #[error("Unsupported file type")] + #[debug(fmt = "Unsupported file type")] UnsupportedFiletype, } +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::IO(_) => write!(f, "Std IO Error"), + Error::Join(_) => write!(f, "Join Error"), + Error::FromUtf8(_) => write!(f, "From Utf8 Error"), + Error::PrettierFormattingFailed(msg) => { + write!(f, "Prettier formatting failed: {}", msg) + } + Error::FileExtensionNotFound => write!(f, "No file extension found"), + Error::UnsupportedFiletype => write!(f, "Unsupported file type"), + } + } +} + pub type Result = std::result::Result; diff --git a/tailcall-tracker/src/error.rs b/tailcall-tracker/src/error.rs index 2b06930378..c41cec9f39 100644 --- a/tailcall-tracker/src/error.rs +++ b/tailcall-tracker/src/error.rs @@ -1,19 +1,32 @@ -use derive_more::From; +use std::fmt::Display; + +use derive_more::{DebugCustom, From}; use reqwest::header::InvalidHeaderValue; -#[derive(From, thiserror::Error, Debug)] +#[derive(From, DebugCustom)] pub enum Error { - #[error("Reqwest Error")] + #[debug(fmt = "Reqwest Error")] Reqwest(reqwest::Error), - #[error("Invalid Header Value")] + #[debug(fmt = "Invalid Header Value")] InvalidHeaderValue(InvalidHeaderValue), - #[error("Serde JSON Error")] + #[debug(fmt = "Serde JSON Error")] SerdeJson(serde_json::Error), - #[error("Url Parser Error")] + #[debug(fmt = "Url Parser Error")] UrlParser(url::ParseError), } +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::Reqwest(_) => write!(f, "Reqwest Error"), + Error::InvalidHeaderValue(_) => write!(f, "Invalid Header Value"), + Error::SerdeJson(_) => write!(f, "Serde JSON Error"), + Error::UrlParser(_) => write!(f, "Url Parser Error"), + } + } +} + pub type Result = std::result::Result;