-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
improve error reporting of JSON parsing #3676
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
6 Ignored Deployments
|
68a3e46
to
bfc4c84
Compare
|
Benchmark for d409965Click to view benchmark
|
Benchmark for 23c75b8
Click to view full benchmark
|
let de = &mut serde_json::Deserializer::from_reader(file.read()); | ||
match serde_path_to_error::deserialize(de) { | ||
Ok(data) => FileJsonContent::Content(data), | ||
Err(e) => FileJsonContent::Unparseable( | ||
box UnparseableJson::from_serde_path_to_error(e), | ||
), | ||
} |
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.
Should this be using parse_json_rope_with_source_context
?
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.
No, since we don't want it wrapped in an anyhow error here, but return a structured error.
make source context generation more reusable
more visible marker spacing, marker, make it prettier
d4c1fbe
to
74b823c
Compare
Benchmark for 3ea0f81
Click to view full benchmark
|
pub fn write_with_content(&self, writer: &mut impl Write, text: &str) -> std::fmt::Result { | ||
writeln!(writer, "{}", self.message)?; | ||
if let Some(path) = &self.path { | ||
writeln!(writer, " at {}", path)?; |
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.
I think the at
is redundant here. We can remove it and the error would read more easily.
FileJsonContent::Content(data) => { | ||
let js_str_content = serde_json::to_string(data)?; | ||
let inner_code = | ||
format!("__turbopack_export_value__(JSON.parse({js_str_content}));"); |
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 is broken, it no longer "stringifies the string" and just puts the raw JSON into the file
…49736102+kodiakhq[bot]@users.noreply.github.com> # New Features - vercel/turborepo#3540 - vercel/turborepo#3549 - vercel/turborepo#3465 - vercel/turborepo#3550 - vercel/turborepo#3495 - vercel/turborepo#3624 - vercel/turborepo#3600 - vercel/turborepo#3676 - vercel/turborepo#3689 # Fixes - vercel/turborepo#3437 - vercel/turborepo#3542 - vercel/turborepo#3531 - vercel/turborepo#3552 - vercel/turborepo#3551 - vercel/turborepo#3597 - vercel/turborepo#3644 - vercel/turborepo#3623 - vercel/turborepo#3634 - vercel/turborepo#3574 - vercel/turborepo#3673 - vercel/turborepo#3675 - vercel/turborepo#3723 - vercel/turborepo#3677 - vercel/turborepo#3717 - vercel/turborepo#3701 # Performance Improvements - vercel/turborepo#3361 - vercel/turborepo#3619 --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
also make source context generation more reusable This adds a source context snippet of the JSON that failed parsing and the json path to the error. ``` An error occurred while generating the chunk item [project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json) at Execution of module_factory failed at Execution of JsonChunkItem::content failed at Unable to make a module from invalid JSON: expected `,` or `}` at line 3 column 26 at nested.? 1 | { 2 | "nested": { | v 3 | "this-is": "invalid" // lint-staged will remove trailing commas, so here's a comment | ^ 4 | } 5 | } ```
also make source context generation more reusable This adds a source context snippet of the JSON that failed parsing and the json path to the error. ``` An error occurred while generating the chunk item [project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json) at Execution of module_factory failed at Execution of JsonChunkItem::content failed at Unable to make a module from invalid JSON: expected `,` or `}` at line 3 column 26 at nested.? 1 | { 2 | "nested": { | v 3 | "this-is": "invalid" // lint-staged will remove trailing commas, so here's a comment | ^ 4 | } 5 | } ```
also make source context generation more reusable This adds a source context snippet of the JSON that failed parsing and the json path to the error. ``` An error occurred while generating the chunk item [project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json) at Execution of module_factory failed at Execution of JsonChunkItem::content failed at Unable to make a module from invalid JSON: expected `,` or `}` at line 3 column 26 at nested.? 1 | { 2 | "nested": { | v 3 | "this-is": "invalid" // lint-staged will remove trailing commas, so here's a comment | ^ 4 | } 5 | } ```
also make source context generation more reusable This adds a source context snippet of the JSON that failed parsing and the json path to the error. ``` An error occurred while generating the chunk item [project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json) at Execution of module_factory failed at Execution of JsonChunkItem::content failed at Unable to make a module from invalid JSON: expected `,` or `}` at line 3 column 26 at nested.? 1 | { 2 | "nested": { | v 3 | "this-is": "invalid" // lint-staged will remove trailing commas, so here's a comment | ^ 4 | } 5 | } ```
also make source context generation more reusable This adds a source context snippet of the JSON that failed parsing and the json path to the error. ``` An error occurred while generating the chunk item [project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json) at Execution of module_factory failed at Execution of JsonChunkItem::content failed at Unable to make a module from invalid JSON: expected `,` or `}` at line 3 column 26 at nested.? 1 | { 2 | "nested": { | v 3 | "this-is": "invalid" // lint-staged will remove trailing commas, so here's a comment | ^ 4 | } 5 | } ```
also make source context generation more reusable
This adds a source context snippet of the JSON that failed parsing and the json path to the error.