Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): add exit code for deno info ci #21952

Merged
merged 7 commits into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions cli/tools/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::fmt;
use std::fmt::Write;

use deno_ast::ModuleSpecifier;
use deno_core::anyhow::bail;
use deno_core::error::AnyError;
use deno_core::resolve_url_or_path;
use deno_core::serde_json;
Expand Down Expand Up @@ -405,7 +406,7 @@ impl<'a> GraphDisplayContext<'a> {
graph: &'a ModuleGraph,
npm_resolver: &'a dyn CliNpmResolver,
writer: &mut TWrite,
) -> fmt::Result {
) -> Result<(), AnyError> {
let npm_info = match npm_resolver.as_managed() {
Some(npm_resolver) => {
let npm_snapshot = npm_resolver.snapshot();
Expand All @@ -421,13 +422,12 @@ impl<'a> GraphDisplayContext<'a> {
.into_writer(writer)
}

fn into_writer<TWrite: Write>(mut self, writer: &mut TWrite) -> fmt::Result {
fn into_writer<TWrite: Write>(
mut self,
writer: &mut TWrite,
) -> Result<(), AnyError> {
if self.graph.roots.is_empty() || self.graph.roots.len() > 1 {
return writeln!(
writer,
"{} displaying graphs that have multiple roots is not supported.",
colors::red("error:")
);
bail!("displaying graphs that have multiple roots is not supported.");
}

let root_specifier = self.graph.resolve(&self.graph.roots[0]);
Expand Down Expand Up @@ -508,21 +508,13 @@ impl<'a> GraphDisplayContext<'a> {
}
Err(err) => {
if let ModuleError::Missing(_, _) = *err {
writeln!(
writer,
"{} module could not be found",
colors::red("error:")
)
bail!("module could not be found");
} else {
writeln!(writer, "{} {:#}", colors::red("error:"), err)
bail!("{:#}", err);
}
}
Ok(None) => {
writeln!(
writer,
"{} an internal error occurred",
colors::red("error:")
)
bail!("an internal error occurred");
}
}
}
Expand Down