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 - 1: drop anyhow #2155

Merged
merged 34 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c710c31
refactor(cli): drop anyhow (#2154)
mehulmathur001 Jun 9, 2024
0530489
progress
mehulmathur16 Jun 10, 2024
6e0414f
progress
mehulmathur16 Jun 10, 2024
2b56b46
solved some errors
mehulmathur16 Jun 10, 2024
33c627a
Merge branch 'error-re-design' into drop-anyhow-1
tusharmath Jun 11, 2024
f317eda
modules error impl [File, http, worker] [38 err]
mehulmathur16 Jun 11, 2024
4438945
progress [dummy impl in ir for WorkerError, HttpError]
mehulmathur16 Jun 11, 2024
e8fce29
fixes
mehulmathur16 Jun 11, 2024
2033eb9
http-response fixes
mehulmathur16 Jun 11, 2024
0e290fb
lint
mehulmathur16 Jun 11, 2024
13092ab
loader types fixes
mehulmathur16 Jun 12, 2024
d4f4035
remove anyhow::Result
mehulmathur16 Jun 12, 2024
d638b1f
anyhow removal - core/confg
mehulmathur16 Jun 12, 2024
68d58dd
error fixes
mehulmathur16 Jun 12, 2024
62ef8e7
lint
mehulmathur16 Jun 12, 2024
156358a
anyhow cleanup [auth -> graphql mod.]
mehulmathur16 Jun 12, 2024
4f1aae0
build fixes
mehulmathur16 Jun 13, 2024
12193c4
lint
mehulmathur16 Jun 13, 2024
8681d2d
lint
mehulmathur16 Jun 13, 2024
1aefcc6
lambda build fix
mehulmathur16 Jun 13, 2024
9868b5f
cloudfare fixes
mehulmathur16 Jun 13, 2024
8f50e7b
src build fixes
mehulmathur16 Jun 13, 2024
fbaac3d
benches & tests errors fix
mehulmathur16 Jun 13, 2024
3f45da3
tailcall-cloudflare build fix
mehulmathur16 Jun 13, 2024
b4f5798
chore: remove postfix Error
mehulmathur16 Jun 15, 2024
133b6c6
rename WorkerError to Error
mehulmathur16 Jun 15, 2024
3733e4c
rename HttpError to Error
mehulmathur16 Jun 15, 2024
9445a25
rename FileError to Error
mehulmathur16 Jun 15, 2024
72cac4b
removed Error type from HttpIO
mehulmathur16 Jun 15, 2024
2134dd2
rmeove type Error from FileIO
mehulmathur16 Jun 15, 2024
7242223
remove type Error from WorkerIO
mehulmathur16 Jun 15, 2024
04aab0c
lint
mehulmathur16 Jun 15, 2024
7d9f95b
removed Errata from enum variants
mehulmathur16 Jun 15, 2024
2af0d11
Merge branch 'error-re-design' into drop-anyhow-1
tusharmath Jun 15, 2024
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: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions benches/data_loader_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use criterion::Criterion;
use hyper::body::Bytes;
use reqwest::Request;
use tailcall::core::config::Batch;
use tailcall::core::error::{file, http};
use tailcall::core::http::{DataLoaderRequest, HttpDataLoader, Response};
use tailcall::core::ir::IoId;
use tailcall::core::runtime::TargetRuntime;
Expand All @@ -23,7 +24,7 @@ struct MockHttpClient {

#[async_trait::async_trait]
impl HttpIO for MockHttpClient {
async fn execute(&self, _req: Request) -> anyhow::Result<Response<Bytes>> {
async fn execute(&self, _req: Request) -> Result<Response<Bytes>, http::Error> {
Ok(Response::empty())
}
}
Expand All @@ -39,11 +40,11 @@ struct File;

#[async_trait::async_trait]
impl FileIO for File {
async fn write<'a>(&'a self, _: &'a str, _: &'a [u8]) -> anyhow::Result<()> {
async fn write<'a>(&'a self, _: &'a str, _: &'a [u8]) -> Result<(), file::Error> {
unimplemented!("Not needed for this bench")
}

async fn read<'a>(&'a self, _: &'a str) -> anyhow::Result<String> {
async fn read<'a>(&'a self, _: &'a str) -> Result<String, file::Error> {
unimplemented!("Not needed for this bench")
}
}
Expand Down
7 changes: 4 additions & 3 deletions benches/impl_path_string_for_evaluation_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use reqwest::{Client, Request};
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use tailcall::core::blueprint::{Server, Upstream};
use tailcall::core::cache::InMemoryCache;
use tailcall::core::error::{file, http};
use tailcall::core::http::{RequestContext, Response};
use tailcall::core::ir::{EvaluationContext, ResolverContextLike};
use tailcall::core::path::PathString;
Expand Down Expand Up @@ -70,7 +71,7 @@ impl Http {

#[async_trait]
impl HttpIO for Http {
async fn execute(&self, mut request: Request) -> anyhow::Result<Response<Bytes>> {
async fn execute(&self, mut request: Request) -> Result<Response<Bytes>, http::Error> {
if self.http2_only {
*request.version_mut() = reqwest::Version::HTTP_2;
}
Expand All @@ -90,11 +91,11 @@ impl EnvIO for Env {
struct File;
#[async_trait]
impl FileIO for File {
async fn write<'a>(&'a self, _: &'a str, _: &'a [u8]) -> anyhow::Result<()> {
async fn write<'a>(&'a self, _: &'a str, _: &'a [u8]) -> Result<(), file::Error> {
unimplemented!("Not needed for this bench")
}

async fn read<'a>(&'a self, _: &'a str) -> anyhow::Result<String> {
async fn read<'a>(&'a self, _: &'a str) -> Result<String, file::Error> {
unimplemented!("Not needed for this bench")
}
}
Expand Down
104 changes: 97 additions & 7 deletions src/cli/error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,100 @@
use crate::core::Errata;
use std::string::FromUtf8Error;

impl From<rustls::Error> for Errata {
fn from(error: rustls::Error) -> Self {
let cli_error = Errata::new("Failed to create TLS Acceptor");
let message = error.to_string();
use derive_more::From;
use inquire::InquireError;
use opentelemetry::logs::LogError;
use opentelemetry::metrics::MetricsError;
use opentelemetry::trace::TraceError;
use tokio::task::JoinError;

cli_error.description(message)
}
use crate::core::rest;
use crate::core::valid::ValidationError;

#[derive(From, thiserror::Error, Debug)]
pub enum Error {
#[error("Metrics Error")]
Metrics(MetricsError),

#[error("Rest Error")]
Rest(rest::error::Error),

#[error("Serde Json Error")]
SerdeJson(serde_json::Error),

#[error("IO Error")]
IO(std::io::Error),

#[error("Telemetry Trace Error : {0}")]
TelemetryTrace(String),

#[error("Failed to send message")]
MessageSendFailure,

#[error("Hyper Error")]
Hyper(hyper::Error),

#[error("Rustls Error")]
Rustls(rustls::Error),

#[error("Join Error")]
Join(JoinError),

#[error("Opentelemetry Global Error")]
OpentelemetryGlobal(opentelemetry::global::Error),

#[error("Trace Error")]
Trace(TraceError),

#[error("Log Error")]
Log(LogError),

#[error("Utf8 Error")]
Utf8(FromUtf8Error),

#[error("Inquire Error")]
Inquire(InquireError),

#[error("Serde Yaml Error")]
SerdeYaml(serde_yaml::Error),

#[error("Invalid Header Name")]
InvalidHeaderName(hyper::header::InvalidHeaderName),

#[error("Invalid Header Value")]
InvalidHeaderValue(hyper::header::InvalidHeaderValue),

#[error("rquickjs Error")]
RQuickjs(rquickjs::Error),

#[error("Trying to reinitialize an already initialized QuickJS runtime")]
ReinitializeQuickjsRuntime,

#[error("Runtime not initialized")]
RuntimeNotInitialized,

#[error("Deserialize Failed")]
DeserializeFailed,

#[error("Not a function error")]
InvalidFunction,

#[error("Init Process Observer Error")]
InitProcessObserver,

#[error("JS Runtime is stopped")]
JsRuntimeStopped,

#[error("Rustls internal error")]
RustlsInternal,

#[error("Reqwest middleware error")]
ReqwestMiddleware(reqwest_middleware::Error),

#[error("Reqwest error")]
Reqwest(reqwest::Error),

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

pub type Result<A> = std::result::Result<A, Error>;
9 changes: 5 additions & 4 deletions src/cli/javascript/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ impl<'js> FromJs<'js> for WorkerResponse {
mod test {
use std::collections::BTreeMap;

use anyhow::Result;
use headers::{HeaderName, HeaderValue};
use hyper::body::Bytes;
use pretty_assertions::assert_eq;
Expand All @@ -214,18 +213,19 @@ mod test {
use rquickjs::{Context, FromJs, IntoJs, Object, Runtime, String as JsString};

use super::*;
use crate::core::error::worker;
use crate::core::http::Response;
use crate::core::worker::{Command, WorkerRequest, WorkerResponse};

fn create_test_response() -> Result<WorkerResponse> {
fn create_test_response() -> Result<WorkerResponse, worker::Error> {
let mut headers = HeaderMap::new();
headers.insert("content-type", "application/json".parse().unwrap());
let response = crate::core::http::Response {
status: reqwest::StatusCode::OK,
headers,
body: Bytes::from("Hello, World!"),
};
let js_response: Result<WorkerResponse> = response.try_into();
let js_response: Result<WorkerResponse, worker::Error> = response.try_into();
js_response
}

Expand All @@ -245,7 +245,8 @@ mod test {
#[test]
fn test_from_js_response() {
let js_response = create_test_response().unwrap();
let response: Result<crate::core::http::Response<Bytes>> = js_response.try_into();
let response: Result<crate::core::http::Response<Bytes>, worker::Error> =
js_response.try_into();
assert!(response.is_ok());
let response = response.unwrap();
assert_eq!(response.status, reqwest::StatusCode::OK);
Expand Down
5 changes: 2 additions & 3 deletions src/cli/javascript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod runtime;

pub use runtime::Runtime;

use crate::cli::Result;
use crate::core::{blueprint, WorkerIO};

pub fn init_worker_io<T, V>(script: blueprint::Script) -> Arc<dyn WorkerIO<T, V> + Send + Sync>
Expand All @@ -18,9 +19,7 @@ where
(Arc::new(Runtime::new(script))) as _
}

fn create_header_map(
headers: BTreeMap<String, String>,
) -> anyhow::Result<reqwest::header::HeaderMap> {
fn create_header_map(headers: BTreeMap<String, String>) -> Result<reqwest::header::HeaderMap> {
let mut header_map = reqwest::header::HeaderMap::new();
for (key, value) in headers.iter() {
let key = HeaderName::from_bytes(key.as_bytes())?;
Expand Down
Loading
Loading