summaryrefslogtreecommitdiff
path: root/cli/graph_util.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-09-26 12:31:03 -0400
committerGitHub <noreply@github.com>2024-09-26 12:31:03 -0400
commit7437f9d944175d7d62fa34c6a2a186c0cd1684a0 (patch)
treec3f2a080a730e549cf65cf6d93f4c988c0115c52 /cli/graph_util.rs
parentb80cf1f5e7a10567f2a39b2f3872735f951dd3a4 (diff)
fix(doc): surface graph errors as warnings (#25888)
Diffstat (limited to 'cli/graph_util.rs')
-rw-r--r--cli/graph_util.rs110
1 files changed, 54 insertions, 56 deletions
diff --git a/cli/graph_util.rs b/cli/graph_util.rs
index 8a6839919..17f7d6739 100644
--- a/cli/graph_util.rs
+++ b/cli/graph_util.rs
@@ -52,14 +52,14 @@ use std::ops::Deref;
use std::path::PathBuf;
use std::sync::Arc;
-#[derive(Clone, Copy)]
+#[derive(Clone)]
pub struct GraphValidOptions {
pub check_js: bool,
pub kind: GraphKind,
- pub is_vendoring: bool,
- /// Whether to exit the process for lockfile errors.
- /// Otherwise, surfaces lockfile errors as errors.
- pub exit_lockfile_errors: bool,
+ /// Whether to exit the process for integrity check errors such as
+ /// lockfile checksum mismatches and JSR integrity failures.
+ /// Otherwise, surfaces integrity errors as errors.
+ pub exit_integrity_errors: bool,
}
/// Check if `roots` and their deps are available. Returns `Ok(())` if
@@ -75,17 +75,54 @@ pub fn graph_valid(
roots: &[ModuleSpecifier],
options: GraphValidOptions,
) -> Result<(), AnyError> {
- if options.exit_lockfile_errors {
- graph_exit_lock_errors(graph);
+ if options.exit_integrity_errors {
+ graph_exit_integrity_errors(graph);
}
- let mut errors = graph
+ let mut errors = graph_walk_errors(
+ graph,
+ fs,
+ roots,
+ GraphWalkErrorsOptions {
+ check_js: options.check_js,
+ kind: options.kind,
+ },
+ );
+ if let Some(error) = errors.next() {
+ Err(error)
+ } else {
+ // finally surface the npm resolution result
+ if let Err(err) = &graph.npm_dep_graph_result {
+ return Err(custom_error(
+ get_error_class_name(err),
+ format_deno_graph_error(err.as_ref().deref()),
+ ));
+ }
+ Ok(())
+ }
+}
+
+#[derive(Clone)]
+pub struct GraphWalkErrorsOptions {
+ pub check_js: bool,
+ pub kind: GraphKind,
+}
+
+/// Walks the errors found in the module graph that should be surfaced to users
+/// and enhances them with CLI information.
+pub fn graph_walk_errors<'a>(
+ graph: &'a ModuleGraph,
+ fs: &'a Arc<dyn FileSystem>,
+ roots: &'a [ModuleSpecifier],
+ options: GraphWalkErrorsOptions,
+) -> impl Iterator<Item = AnyError> + 'a {
+ graph
.walk(
roots.iter(),
deno_graph::WalkOptions {
check_js: options.check_js,
kind: options.kind,
- follow_dynamic: options.is_vendoring,
+ follow_dynamic: false,
prefer_fast_check_graph: false,
},
)
@@ -109,7 +146,7 @@ pub fn graph_valid(
)
}
ModuleGraphError::ModuleError(error) => {
- enhanced_lockfile_error_message(error)
+ enhanced_integrity_error_message(error)
.or_else(|| enhanced_sloppy_imports_error_message(fs, error))
.unwrap_or_else(|| format_deno_graph_error(error))
}
@@ -132,56 +169,18 @@ pub fn graph_valid(
return None;
}
- if options.is_vendoring {
- // warn about failing dynamic imports when vendoring, but don't fail completely
- if matches!(
- error,
- ModuleGraphError::ModuleError(ModuleError::MissingDynamic(_, _))
- ) {
- log::warn!("Ignoring: {}", message);
- return None;
- }
-
- // ignore invalid downgrades and invalid local imports when vendoring
- match &error {
- ModuleGraphError::ResolutionError(err)
- | ModuleGraphError::TypesResolutionError(err) => {
- if matches!(
- err,
- ResolutionError::InvalidDowngrade { .. }
- | ResolutionError::InvalidLocalImport { .. }
- ) {
- return None;
- }
- }
- ModuleGraphError::ModuleError(_) => {}
- }
- }
-
Some(custom_error(get_error_class_name(&error.into()), message))
- });
- if let Some(error) = errors.next() {
- Err(error)
- } else {
- // finally surface the npm resolution result
- if let Err(err) = &graph.npm_dep_graph_result {
- return Err(custom_error(
- get_error_class_name(err),
- format_deno_graph_error(err.as_ref().deref()),
- ));
- }
- Ok(())
- }
+ })
}
-pub fn graph_exit_lock_errors(graph: &ModuleGraph) {
+pub fn graph_exit_integrity_errors(graph: &ModuleGraph) {
for error in graph.module_errors() {
- exit_for_lockfile_error(error);
+ exit_for_integrity_error(error);
}
}
-fn exit_for_lockfile_error(err: &ModuleError) {
- if let Some(err_message) = enhanced_lockfile_error_message(err) {
+fn exit_for_integrity_error(err: &ModuleError) {
+ if let Some(err_message) = enhanced_integrity_error_message(err) {
log::error!("{} {}", colors::red("error:"), err_message);
std::process::exit(10);
}
@@ -719,14 +718,13 @@ impl ModuleGraphBuilder {
&self.fs,
roots,
GraphValidOptions {
- is_vendoring: false,
kind: if self.options.type_check_mode().is_true() {
GraphKind::All
} else {
GraphKind::CodeOnly
},
check_js: self.options.check_js(),
- exit_lockfile_errors: true,
+ exit_integrity_errors: true,
},
)
}
@@ -780,7 +778,7 @@ fn enhanced_sloppy_imports_error_message(
}
}
-fn enhanced_lockfile_error_message(err: &ModuleError) -> Option<String> {
+fn enhanced_integrity_error_message(err: &ModuleError) -> Option<String> {
match err {
ModuleError::LoadingErr(
specifier,