-
Notifications
You must be signed in to change notification settings - Fork 0
Polishing #9
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
Merged
Merged
Polishing #9
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| use napi::{bindgen_prelude::Error, Status}; | ||
| use sdk_core::errors::{HttpKind, SdkError}; | ||
|
|
||
| // napi-rs can only throw plain napi::Error with a status + message. To give | ||
| // callers a typed class hierarchy in JS, we encode the variant as a structured | ||
| // prefix in the message; the JS-side wrapper (npm/sdk.js) parses the prefix | ||
| // and rethrows as the matching typed class (ApiError / TimeoutError / ...). | ||
| // | ||
| // Wire format: "[<kind>|<status>|<body_len>]<original_message>" | ||
| // - kind: one of Config | Http | Timeout | Connect | Api | Decode | ||
| // - status: u16 for Api, "-" otherwise | ||
| // - body_len: byte length of body blob appended after message (for Api/Decode), "-" otherwise | ||
| // The body bytes are appended after a "\x1f" (unit separator) so JS can split cleanly. | ||
| #[allow(clippy::needless_pass_by_value)] | ||
| pub fn map_sdk_err(e: SdkError) -> Error { | ||
| let msg = e.to_string(); | ||
| let (kind, status, body) = match &e { | ||
| SdkError::Config(_) | SdkError::UrlParse(_) => ("Config", None, None), | ||
| SdkError::Api { status, body } => ("Api", Some(status.as_u16()), Some(body.clone())), | ||
| SdkError::Decode { body, .. } => ("Decode", None, Some(body.clone())), | ||
| SdkError::Http(_) => match e.http_kind() { | ||
| Some(HttpKind::Timeout) => ("Timeout", None, None), | ||
| Some(HttpKind::Connect) => ("Connect", None, None), | ||
| _ => ("Http", None, None), | ||
| }, | ||
| }; | ||
| let status_s = status.map_or("-".to_string(), |s| s.to_string()); | ||
| let body_s = body.as_deref().unwrap_or(""); | ||
| let body_len = if body.is_some() { | ||
| body_s.len().to_string() | ||
| } else { | ||
| "-".to_string() | ||
| }; | ||
| let tagged = format!("[{kind}|{status_s}|{body_len}]{msg}\u{001f}{body_s}"); | ||
| Error::new(Status::GenericFailure, tagged) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Trailing \x1f control character in Node.js error messages
Medium Severity
The Rust
format!on line 34 unconditionally appends\u{001f}(unit separator) even whenbody_sis empty (for Config, Http, Timeout, Connect variants). On the JS side,fromNapiErroronly strips the separator whenbodyLenStr !== "-", so non-body error variants end up with a trailing\x1fcontrol character in their.message. This pollutes user-facing error messages and can break string comparisons, JSON serialization, and log output.Additional Locations (1)
npm/errors.js#L66-L77Reviewed by Cursor Bugbot for commit fb4e06a. Configure here.