-
Notifications
You must be signed in to change notification settings - Fork 2
fix: fix some edge cases for HTTP integration #465
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actual bug fix: try to peak into the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| //! Interfaces for HTTP interactions of the guest. | ||
|
|
||
| use std::sync::Arc; | ||
| use std::{io::ErrorKind, sync::Arc}; | ||
|
|
||
| use datafusion_common::{DataFusionError, error::Result as DataFusionResult}; | ||
| use http::HeaderName; | ||
|
|
@@ -235,5 +235,57 @@ fn assemble_response( | |
|
|
||
| /// Map [`reqwest::Error`] to [`HttpErrorCode`]. | ||
| fn map_reqwest_err(e: reqwest::Error) -> HttpErrorCode { | ||
| // try to find an IO error first, since this is potentially the most low-level information | ||
| if let Some(e) = extract_error_type::<std::io::Error>(&e) { | ||
| match e.kind() { | ||
| ErrorKind::ConnectionRefused => { | ||
| return HttpErrorCode::ConnectionRefused; | ||
| } | ||
| ErrorKind::ConnectionReset => { | ||
| return HttpErrorCode::ConnectionTerminated; | ||
| } | ||
| ErrorKind::TimedOut => { | ||
| return HttpErrorCode::ConnectionTimeout; | ||
| } | ||
| _ => {} | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that you CANNOT match all kinds because that enum is non-exhaustive. |
||
| } | ||
| } | ||
|
|
||
| // hyper might have some hints for us | ||
| if let Some(e) = extract_error_type::<hyper::Error>(&e) { | ||
| if e.is_incomplete_message() { | ||
| return HttpErrorCode::HttpResponseIncomplete; | ||
| } else if e.is_parse() { | ||
| return HttpErrorCode::HttpProtocolError; | ||
| } else if e.is_timeout() { | ||
| return HttpErrorCode::ConnectionTimeout; | ||
| } | ||
| } | ||
|
|
||
| // cannot really extract anything meaningful, fall back to "internal error" ("internal" as in "in our stack", not | ||
| // as in "internal server error") | ||
| HttpErrorCode::InternalError(Some(e.to_string())) | ||
| } | ||
|
|
||
| /// Extract concrete error type from error chain. | ||
| fn extract_error_type<'a, E>(e: &'a (dyn std::error::Error + 'static)) -> Option<&'a E> | ||
| where | ||
| E: std::error::Error + 'static, | ||
| { | ||
| let mut current = e; | ||
|
|
||
| loop { | ||
| if let Some(concrete) = current.downcast_ref::<E>() { | ||
| return Some(concrete); | ||
| } | ||
|
|
||
| match current.source() { | ||
| Some(next) => { | ||
| current = next; | ||
| } | ||
| None => { | ||
| return None; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change here looks bigger than it is due to a changed indentation. It really just introduces:
Both is now possible due to #453, showing that this "use home-grown test harness" approach pays off. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some improvements to the error mapping here. This is on the guest side, mapping from WASI to Python.
I was debugging #464 and only got error messages a la
Err { value: () }"because some of the respective WASI methods returnResult<..., ()>. While you can get the Python backtrace to find out which method was called, it still seemed rather bad as a debugging experience. So I've improved these error messages.