Skip to content

Commit 99ffdd7

Browse files
authored
fix: json parse error handle (#124)
1 parent a8e2142 commit 99ffdd7

File tree

10 files changed

+193
-228
lines changed

10 files changed

+193
-228
lines changed

Cargo.lock

Lines changed: 45 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ json-strip-comments = "1.0.2"
9191
rustc-hash = { version = "2.0.0", default-features = false, features = ["std"] }
9292
thiserror = "2.0.17"
9393

94-
pnp = { version = "0.12.4", optional = true }
94+
pnp = { version = "0.12.5", optional = true }
9595

9696
async-trait = "0.1.84"
9797
document-features = { version = "0.2.8", optional = true }

fixtures/pnpm-workspace/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"author": "",
1010
"license": "MIT",
1111
"dependencies": {
12-
"enhanced-resolve": "^5.17.1",
13-
"oxc-resolver": "latest"
12+
"enhanced-resolve": "^5.17.1"
1413
}
1514
}

lint-staged.config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
export default {
2-
"*.rs": () => "cargo fmt",
2+
"*.rs": [
3+
() => "cargo fmt",
4+
() => "cargo clippy --all-features -- -D warnings"
5+
],
36
"*.{ts,tsx,js,mjs,yml,yaml}": "pnpm exec prettier --write",
47
"package.json": "pnpm exec prettier --write",
58
"*.toml": "pnpm exec taplo format"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
"packageManager": "pnpm@9.11.0",
4040
"repository": {
4141
"type": "git",
42-
"url": "git+https://github.com/oxc-project/oxc-resolver.git"
42+
"url": "git+https://web-infra-dev/rspack-resolver.git"
4343
}
4444
}

pnpm-lock.yaml

Lines changed: 0 additions & 190 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cache.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,25 @@ impl CachedPathImpl {
331331
return Err(ResolveError::from(io_err));
332332
}
333333
};
334-
335-
let (line, column) = off_to_location(&package_json_string, parse_err.index());
336-
337-
Err(ResolveError::JSON(JSONError {
338-
path: package_json_path,
339-
message: format!("Parsing error: {:?}", parse_err.error()),
340-
line,
341-
column,
342-
content: Some(package_json_string),
343-
}))
334+
let serde_err = serde_json::from_str::<serde_json::Value>(&package_json_string).err();
335+
336+
if let Some(err) = serde_err {
337+
Err(ResolveError::from_serde_json_error(
338+
package_json_path,
339+
&err,
340+
Some(package_json_string),
341+
))
342+
} else {
343+
let (line, column) = off_to_location(&package_json_string, parse_err.index());
344+
345+
Err(ResolveError::JSON(JSONError {
346+
path: package_json_path,
347+
message: parse_err.error().to_string(),
348+
line,
349+
column,
350+
content: Some(package_json_string),
351+
}))
352+
}
344353
}
345354
}
346355
})

0 commit comments

Comments
 (0)