summaryrefslogtreecommitdiff
path: root/cli/args
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-10-31 11:35:17 -0400
committerGitHub <noreply@github.com>2024-10-31 15:35:17 +0000
commit90edca21a26fd2decd0603fea37af10d1e11e454 (patch)
tree2b876c07709e1ad7f7343c96b2ebb2da7422458b /cli/args
parent50ea707b58dff85b479905ebbeef866c95bc3cad (diff)
fix: surface package.json location on dep parse failure (#26665)
Related: https://github.com/denoland/deno/issues/26653
Diffstat (limited to 'cli/args')
-rw-r--r--cli/args/mod.rs1
-rw-r--r--cli/args/package_json.rs25
2 files changed, 23 insertions, 3 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index 754cd38fa..d72526462 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -46,6 +46,7 @@ pub use flags::*;
pub use lockfile::CliLockfile;
pub use lockfile::CliLockfileReadFromPathOptions;
pub use package_json::NpmInstallDepsProvider;
+pub use package_json::PackageJsonDepValueParseWithLocationError;
use deno_ast::ModuleSpecifier;
use deno_core::anyhow::bail;
diff --git a/cli/args/package_json.rs b/cli/args/package_json.rs
index 2ef39a30d..7dc75550c 100644
--- a/cli/args/package_json.rs
+++ b/cli/args/package_json.rs
@@ -5,10 +5,12 @@ use std::sync::Arc;
use deno_config::workspace::Workspace;
use deno_core::serde_json;
+use deno_core::url::Url;
use deno_package_json::PackageJsonDepValue;
use deno_package_json::PackageJsonDepValueParseError;
use deno_semver::npm::NpmPackageReqReference;
use deno_semver::package::PackageReq;
+use thiserror::Error;
#[derive(Debug)]
pub struct InstallNpmRemotePkg {
@@ -23,11 +25,20 @@ pub struct InstallNpmWorkspacePkg {
pub target_dir: PathBuf,
}
+#[derive(Debug, Error, Clone)]
+#[error("Failed to install '{}'\n at {}", alias, location)]
+pub struct PackageJsonDepValueParseWithLocationError {
+ pub location: Url,
+ pub alias: String,
+ #[source]
+ pub source: PackageJsonDepValueParseError,
+}
+
#[derive(Debug, Default)]
pub struct NpmInstallDepsProvider {
remote_pkgs: Vec<InstallNpmRemotePkg>,
workspace_pkgs: Vec<InstallNpmWorkspacePkg>,
- pkg_json_dep_errors: Vec<PackageJsonDepValueParseError>,
+ pkg_json_dep_errors: Vec<PackageJsonDepValueParseWithLocationError>,
}
impl NpmInstallDepsProvider {
@@ -89,7 +100,13 @@ impl NpmInstallDepsProvider {
let dep = match dep {
Ok(dep) => dep,
Err(err) => {
- pkg_json_dep_errors.push(err);
+ pkg_json_dep_errors.push(
+ PackageJsonDepValueParseWithLocationError {
+ location: pkg_json.specifier(),
+ alias,
+ source: err,
+ },
+ );
continue;
}
};
@@ -150,7 +167,9 @@ impl NpmInstallDepsProvider {
&self.workspace_pkgs
}
- pub fn pkg_json_dep_errors(&self) -> &[PackageJsonDepValueParseError] {
+ pub fn pkg_json_dep_errors(
+ &self,
+ ) -> &[PackageJsonDepValueParseWithLocationError] {
&self.pkg_json_dep_errors
}
}