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

refactor: move cli error to core #2708

Merged
merged 8 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod command;
mod error;
mod fmt;
pub mod generator;
#[cfg(feature = "js")]
Expand All @@ -11,5 +10,4 @@ pub mod server;
mod tc;
pub mod telemetry;
pub(crate) mod update_checker;
pub use error::CLIError;
pub use tc::run::run;
7 changes: 3 additions & 4 deletions src/cli/runtime/file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use tokio::io::{AsyncReadExt, AsyncWriteExt};

use crate::cli::CLIError;
use crate::core::FileIO;
use crate::core::{Errata, FileIO};

#[derive(Clone)]
pub struct NativeFileIO {}
Expand Down Expand Up @@ -29,7 +28,7 @@ async fn write<'a>(path: &'a str, content: &'a [u8]) -> anyhow::Result<()> {
impl FileIO for NativeFileIO {
async fn write<'a>(&'a self, path: &'a str, content: &'a [u8]) -> anyhow::Result<()> {
write(path, content).await.map_err(|err| {
CLIError::new(format!("Failed to write file: {}", path).as_str())
Errata::new(format!("Failed to write file: {}", path).as_str())
.description(err.to_string())
})?;
tracing::info!("File write: {} ... ok", path);
Expand All @@ -38,7 +37,7 @@ impl FileIO for NativeFileIO {

async fn read<'a>(&'a self, path: &'a str) -> anyhow::Result<String> {
let content = read(path).await.map_err(|err| {
CLIError::new(format!("Failed to read file: {}", path).as_str())
Errata::new(format!("Failed to read file: {}", path).as_str())
.description(err.to_string())
})?;
tracing::info!("File read: {} ... ok", path);
Expand Down
6 changes: 3 additions & 3 deletions src/cli/server/http_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use tokio::sync::oneshot;

use super::server_config::ServerConfig;
use crate::cli::CLIError;
use crate::core::async_graphql_hyper::{GraphQLBatchRequest, GraphQLRequest};
use crate::core::http::handle_request;
use crate::core::Errata;

pub async fn start_http_1(
sc: Arc<ServerConfig>,
Expand All @@ -31,7 +31,7 @@
}
});
let builder = hyper::Server::try_bind(&addr)
.map_err(CLIError::from)?
.map_err(Errata::from)?
.http1_pipeline_flush(sc.app_ctx.blueprint.server.pipeline_flush);
super::log_launch(sc.as_ref());

Expand All @@ -48,7 +48,7 @@
builder.serve(make_svc_single_req).await
};

let result = server.map_err(CLIError::from);
let result = server.map_err(Errata::from);

Check warning on line 51 in src/cli/server/http_1.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/server/http_1.rs#L51

Added line #L51 was not covered by tests

Ok(result?)
}
4 changes: 2 additions & 2 deletions src/cli/server/http_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use tokio::sync::oneshot;

use super::server_config::ServerConfig;
use crate::cli::CLIError;
use crate::core::async_graphql_hyper::{GraphQLBatchRequest, GraphQLRequest};
use crate::core::http::handle_request;
use crate::core::Errata;

pub async fn start_http_2(
sc: Arc<ServerConfig>,
Expand Down Expand Up @@ -60,7 +60,7 @@
builder.serve(make_svc_single_req).await
};

let result = server.map_err(CLIError::from);
let result = server.map_err(Errata::from);

Check warning on line 63 in src/cli/server/http_2.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/server/http_2.rs#L63

Added line #L63 was not covered by tests

Ok(result?)
}
4 changes: 2 additions & 2 deletions src/cli/server/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use super::http_1::start_http_1;
use super::http_2::start_http_2;
use super::server_config::ServerConfig;
use crate::cli::telemetry::init_opentelemetry;
use crate::cli::CLIError;
use crate::core::blueprint::{Blueprint, Http};
use crate::core::config::ConfigModule;
use crate::core::Errata;

pub struct Server {
config_module: ConfigModule,
Expand All @@ -32,7 +32,7 @@ impl Server {

/// Starts the server in the current Runtime
pub async fn start(self) -> Result<()> {
let blueprint = Blueprint::try_from(&self.config_module).map_err(CLIError::from)?;
let blueprint = Blueprint::try_from(&self.config_module).map_err(Errata::from)?;
let endpoints = self.config_module.extensions().endpoint_set.clone();
let server_config = Arc::new(ServerConfig::new(blueprint.clone(), endpoints).await?);

Expand Down
4 changes: 2 additions & 2 deletions src/cli/tc/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

use super::helpers::{display_schema, log_endpoint_set};
use crate::cli::fmt::Fmt;
use crate::cli::CLIError;
use crate::core::blueprint::Blueprint;
use crate::core::config::reader::ConfigReader;
use crate::core::config::Source;
use crate::core::runtime::TargetRuntime;
use crate::core::Errata;

pub(super) struct CheckParams {
pub(super) file_paths: Vec<String>,
Expand All @@ -24,7 +24,7 @@
if let Some(format) = format {
Fmt::display(format.encode(&config_module)?);
}
let blueprint = Blueprint::try_from(&config_module).map_err(CLIError::from);
let blueprint = Blueprint::try_from(&config_module).map_err(Errata::from);

Check warning on line 27 in src/cli/tc/check.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/tc/check.rs#L27

Added line #L27 was not covered by tests

match blueprint {
Ok(blueprint) => {
Expand Down
6 changes: 3 additions & 3 deletions src/cli/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
use tracing_subscriber::{Layer, Registry};

use super::metrics::init_metrics;
use crate::cli::CLIError;
use crate::core::blueprint::telemetry::{OtlpExporter, Telemetry, TelemetryExporter};
use crate::core::runtime::TargetRuntime;
use crate::core::tracing::{
default_tracing, default_tracing_tailcall, get_log_level, tailcall_filter_target,
};
use crate::core::Errata;

static RESOURCE: Lazy<Resource> = Lazy::new(|| {
Resource::default().merge(&Resource::new(vec![
Expand Down Expand Up @@ -206,8 +206,8 @@
| global::Error::Log(LogError::Other(_)),
) {
tracing::subscriber::with_default(default_tracing_tailcall(), || {
let cli = crate::cli::CLIError::new("Open Telemetry Error")
.caused_by(vec![CLIError::new(error.to_string().as_str())])
let cli = crate::core::Errata::new("Open Telemetry Error")
.caused_by(vec![Errata::new(error.to_string().as_str())])

Check warning on line 210 in src/cli/telemetry.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/telemetry.rs#L209-L210

Added lines #L209 - L210 were not covered by tests
.trace(vec!["schema".to_string(), "@telemetry".to_string()]);
tracing::error!("{}", cli.color(true));
});
Expand Down
Loading
Loading