Skip to content

Commit

Permalink
chore(bun): properly handle invalid JSON parsing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-olszewski committed Jan 24, 2025
1 parent d750a02 commit d3a0b51
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion crates/turborepo-lockfiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ workspace = true
biome_formatter = { workspace = true }
biome_json_formatter = { workspace = true }
biome_json_parser = { workspace = true }
itertools = { workspace = true }
nom = "7"
pest = "2.7.9"
pest_derive = "2.7.9"
Expand All @@ -25,8 +26,8 @@ serde_yaml = "0.9.27"
thiserror = "1.0.38"
tracing.workspace = true
turbopath = { path = "../turborepo-paths" }
turborepo-errors = { workspace = true }

[dev-dependencies]
itertools = { workspace = true }
pretty_assertions = "1.3"
test-case = "3.1.0"
9 changes: 8 additions & 1 deletion crates/turborepo-lockfiles/src/bun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use std::{any::Any, collections::HashMap, str::FromStr};
use biome_json_formatter::context::JsonFormatOptions;
use biome_json_parser::JsonParserOptions;
use id::PossibleKeyIter;
use itertools::Itertools as _;
use serde::Deserialize;
use serde_json::Value;
use turborepo_errors::ParseDiagnostic;

use crate::Lockfile;

Expand Down Expand Up @@ -200,7 +202,12 @@ impl FromStr for BunLockfile {
JsonParserOptions::default().with_allow_trailing_commas(),
);
if parsed_json.has_errors() {
// TODO
let diags = parsed_json
.into_diagnostics()
.into_iter()
.map(|diagnostic| ParseDiagnostic::from(&diagnostic).to_string())
.join("\n");
return Err(super::Error::BiomeJsonError(diags));
}
let syntax_tree = parsed_json.syntax();
let format = biome_json_formatter::format_node(
Expand Down
2 changes: 2 additions & 0 deletions crates/turborepo-lockfiles/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub enum Error {
MissingVersion(String),
#[error("Unable to convert from json: {0}")]
JsonError(#[from] serde_json::Error),
#[error("Unable to convert from json: {0}")]
BiomeJsonError(String),
#[error("Unable to convert to yaml: {0}")]
Yaml(#[from] serde_yaml::Error),
#[error("Turborepo doesn't support npm lockfiles without a 'packages' field")]
Expand Down

0 comments on commit d3a0b51

Please sign in to comment.