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: catch import map lookup error properly in ResolvingIssue #7167

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
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
24 changes: 16 additions & 8 deletions crates/turbopack-core/src/issue/resolve.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use std::fmt::Write;

use anyhow::Result;
use turbo_tasks::{ValueToString, Vc};
use turbo_tasks::{ReadRef, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;

use super::{Issue, IssueSource, OptionIssueSource, OptionStyledString, StyledString};
use crate::{
error::PrettyPrintError,
issue::IssueSeverity,
resolve::{options::ResolveOptions, parse::Request},
resolve::{
options::{ImportMap, ResolveOptions},
parse::Request,
},
};

#[turbo_tasks::value(shared)]
Expand Down Expand Up @@ -81,12 +84,7 @@ impl Issue for ResolvingIssue {
request_type = self.request_type,
)?;
if let Some(import_map) = &self.resolve_options.await?.import_map {
let result = import_map
.await?
.lookup(self.file_path, self.request)
.await?;

match result.cell().to_string().await {
match lookup_import_map(*import_map, self.file_path, self.request).await {
Ok(str) => writeln!(detail, "Import map: {}", str)?,
Err(err) => {
writeln!(
Expand All @@ -108,3 +106,13 @@ impl Issue for ResolvingIssue {
// TODO add sub_issue for a description of resolve_options
// TODO add source link
}

async fn lookup_import_map(
import_map: Vc<ImportMap>,
file_path: Vc<FileSystemPath>,
request: Vc<Request>,
) -> Result<ReadRef<String>> {
let result = import_map.await?.lookup(file_path, request).await?;

result.cell().to_string().await
}
4 changes: 2 additions & 2 deletions crates/turbopack-core/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub use alias_map::{
};
pub use remap::{ResolveAliasMap, SubpathValue};

use crate::issue::IssueSeverity;
use crate::{error::PrettyPrintError, issue::IssueSeverity};

#[turbo_tasks::value(shared)]
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -2042,7 +2042,7 @@ pub async fn handle_resolve_error(
request_type: format!("{} request", reference_type.into_value()),
request,
resolve_options,
error_message: Some(err.to_string()),
error_message: Some(format!("{}", PrettyPrintError(&err))),
source,
}
.cell()
Expand Down
Loading