-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
error handling in minimal dispatch #3176
Merged
ry
merged 8 commits into
denoland:master
from
bartlomieju:refactor-error_handling_in_dispatch
Oct 24, 2019
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9981aeb
error handling in minimal dispatch
bartlomieju c632551
fix panics
bartlomieju e0d3308
don't allocate Int32 array
bartlomieju f5e1fee
test, revert parsing little endian numbers
bartlomieju 31d94c8
reset CI
bartlomieju d8349af
Merge remote-tracking branch 'origin/master' into refactor-error_hand…
ry ccdb2b9
reset CI
bartlomieju d96516d
fix casting to Int32Array
bartlomieju File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
//! alternative to flatbuffers using a very simple list of int32s to lay out | ||
//! messages. The first i32 is used to determine if a message a flatbuffer | ||
//! message or a "minimal" message. | ||
use crate::deno_error::GetErrorKind; | ||
use byteorder::{LittleEndian, WriteBytesExt}; | ||
use deno::Buf; | ||
use deno::CoreOp; | ||
use deno::ErrBox; | ||
|
@@ -31,6 +33,44 @@ impl Into<Buf> for Record { | |
} | ||
} | ||
|
||
pub struct ErrorRecord { | ||
pub promise_id: i32, | ||
pub arg: i32, | ||
pub error_code: i32, | ||
pub error_message: Vec<u8>, | ||
} | ||
|
||
impl Into<Buf> for ErrorRecord { | ||
fn into(self) -> Buf { | ||
let v32: Vec<i32> = vec![self.promise_id, self.arg, self.error_code]; | ||
let mut v8: Vec<u8> = Vec::new(); | ||
for n in v32 { | ||
v8.write_i32::<LittleEndian>(n).unwrap(); | ||
} | ||
let mut message = self.error_message; | ||
// Align to 32bit word, padding with the space character. | ||
message.resize((message.len() + 3usize) & !3usize, b' '); | ||
v8.append(&mut message); | ||
v8.into_boxed_slice() | ||
} | ||
} | ||
bartlomieju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#[test] | ||
fn test_error_record() { | ||
let expected = vec![ | ||
1, 0, 0, 0, 255, 255, 255, 255, 10, 0, 0, 0, 69, 114, 114, 111, 114, 32, | ||
32, 32, | ||
]; | ||
let err_record = ErrorRecord { | ||
promise_id: 1, | ||
arg: -1, | ||
error_code: 10, | ||
error_message: "Error".to_string().as_bytes().to_owned(), | ||
}; | ||
let buf: Buf = err_record.into(); | ||
assert_eq!(buf, expected.into_boxed_slice()); | ||
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. 👍 |
||
} | ||
|
||
pub fn parse_min_record(bytes: &[u8]) -> Option<Record> { | ||
if bytes.len() % std::mem::size_of::<i32>() != 0 { | ||
return None; | ||
|
@@ -85,15 +125,18 @@ pub fn minimal_op( | |
match result { | ||
Ok(r) => { | ||
record.result = r; | ||
Ok(record.into()) | ||
} | ||
Err(err) => { | ||
// TODO(ry) The dispatch_minimal doesn't properly pipe errors back to | ||
// the caller. | ||
debug!("swallowed err {}", err); | ||
record.result = -1; | ||
let error_record = ErrorRecord { | ||
promise_id: record.promise_id, | ||
arg: -1, | ||
error_code: err.kind() as i32, | ||
error_message: err.to_string().as_bytes().to_owned(), | ||
}; | ||
Ok(error_record.into()) | ||
} | ||
} | ||
Ok(record.into()) | ||
})); | ||
|
||
if is_sync { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This code is very much in the hot path for our most important benchmark. I'm all for landing this to see what happens, but I will revert if it causes a noticeable slow down.
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.
Yes I agree completely. I will try to optimize it further, but we can't leave out proper error handling (which is long overdue anyway)