Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stack]: redesign errors - 4 #2363

Closed
wants to merge 12 commits into from
9 changes: 6 additions & 3 deletions src/cli/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")]
Expand Down Expand Up @@ -93,8 +93,11 @@ pub enum Error {
#[error("Reqwest error")]
Reqwest(reqwest::Error),

#[error("Validation Error : {0}")]
#[error("Validation Error : {}", _0)]
Validation(ValidationError<std::string::String>),

#[error("Core Error")]
CoreError(error::Error),
}

pub type Result<A> = std::result::Result<A, Error>;
5 changes: 3 additions & 2 deletions src/cli/generator/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -71,7 +72,7 @@ impl Generator {

async fn read(&self) -> Result<Config<Resolved>, 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 {
Expand Down
8 changes: 4 additions & 4 deletions src/cli/javascript/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ impl WorkerIO<Event, Command> 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)?
Expand All @@ -118,10 +118,10 @@ impl WorkerIO<ConstValue, ConstValue> 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)?
Expand Down
10 changes: 7 additions & 3 deletions src/cli/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand All @@ -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)?;
Expand All @@ -132,5 +134,7 @@ pub fn select_prompt<T: std::fmt::Display>(
message: &str,
options: Vec<T>,
) -> Result<T, error::file::Error> {
Ok(Select::new(message, options).prompt()?)
Select::new(message, options)
.prompt()
.map_err(|e| error::file::Error::Inquire(e.to_string()))
}
2 changes: 1 addition & 1 deletion src/cli/tc/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/tc/start.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
Expand Down
Loading
Loading