summaryrefslogtreecommitdiff
path: root/cli/import_map.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2021-08-03 15:29:12 -0400
committerGitHub <noreply@github.com>2021-08-03 15:29:12 -0400
commit1cd95dd8b5046484ea79b1849e420d1c085d1e5b (patch)
treef7f74e9c1b059184b621b895ad380e81416b29c3 /cli/import_map.rs
parent86f89f922296c3c9e082268d01044f2e04a2e210 (diff)
chore: surface import map JSON parse error to user (#11573)
Diffstat (limited to 'cli/import_map.rs')
-rw-r--r--cli/import_map.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/cli/import_map.rs b/cli/import_map.rs
index 17ac3727e..aa76d8d76 100644
--- a/cli/import_map.rs
+++ b/cli/import_map.rs
@@ -65,10 +65,11 @@ impl ImportMap {
) -> Result<Self, ImportMapError> {
let v: Value = match serde_json::from_str(json_string) {
Ok(v) => v,
- Err(_) => {
- return Err(ImportMapError::Other(
- "Unable to parse import map JSON".to_string(),
- ));
+ Err(err) => {
+ return Err(ImportMapError::Other(format!(
+ "Unable to parse import map JSON: {}",
+ err.to_string()
+ )));
}
};
@@ -742,6 +743,14 @@ mod tests {
assert!(ImportMap::from_json(base_url, non_object).is_err());
}
+ // invalid JSON message test
+ assert_eq!(
+ ImportMap::from_json(base_url, "{\"a\":1,}")
+ .unwrap_err()
+ .to_string(),
+ "Unable to parse import map JSON: trailing comma at line 1 column 8",
+ );
+
// invalid schema: 'imports' is non-object
for non_object in non_object_strings.to_vec() {
assert!(ImportMap::from_json(