From a5ef75a9c2cfa7191c328fa6fccfed897db89f49 Mon Sep 17 00:00:00 2001 From: Neven Villani Date: Wed, 11 Jun 2025 22:00:20 +0200 Subject: [PATCH] I want to get all of this working --- crates/typst-kit/src/package.rs | 2 +- crates/typst-library/src/diag.rs | 9 +++++++-- pending/import1.typ | 1 + pending/import2.typ | 1 + pending/import3.typ | 1 + pending/import4.typ | 1 + pending/import5.typ | 1 + pending/runall.sh | 5 +++++ tests/suite/scripting/import.typ | 13 +++++++++++++ 9 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 pending/import1.typ create mode 100644 pending/import2.typ create mode 100644 pending/import3.typ create mode 100644 pending/import4.typ create mode 100644 pending/import5.typ create mode 100755 pending/runall.sh diff --git a/crates/typst-kit/src/package.rs b/crates/typst-kit/src/package.rs index 584ec83c0..f08eb897c 100644 --- a/crates/typst-kit/src/package.rs +++ b/crates/typst-kit/src/package.rs @@ -185,7 +185,7 @@ impl PackageStorage { if let Ok(version) = self.determine_latest_version(&spec.versionless()) { return Err(PackageError::VersionNotFound(spec.clone(), version)); } else { - return Err(PackageError::NotFound(spec.clone())); + return Err(PackageError::NotFound(spec.clone(), Some(eco_format!("attempted to download")))); } } Err(err) => { diff --git a/crates/typst-library/src/diag.rs b/crates/typst-library/src/diag.rs index 41b92ed65..6a55a21da 100644 --- a/crates/typst-library/src/diag.rs +++ b/crates/typst-library/src/diag.rs @@ -523,7 +523,9 @@ pub type PackageResult = Result; #[derive(Debug, Clone, Eq, PartialEq, Hash)] pub enum PackageError { /// The specified package does not exist. - NotFound(PackageSpec), + /// Optionally provides information on where we tried to find the package, + /// defaults to simply "searched for" if absent. + NotFound(PackageSpec, Option), /// The specified package found, but the version does not exist. VersionNotFound(PackageSpec, PackageVersion), /// Failed to retrieve the package through the network. @@ -539,9 +541,12 @@ impl std::error::Error for PackageError {} impl Display for PackageError { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { - Self::NotFound(spec) => { + Self::NotFound(spec, None) => { write!(f, "package not found (searched for {spec})",) } + Self::NotFound(spec, Some(attempted)) => { + write!(f, "package not found ({attempted} {spec})",) + } Self::VersionNotFound(spec, latest) => { write!( f, diff --git a/pending/import1.typ b/pending/import1.typ new file mode 100644 index 000000000..36894382d --- /dev/null +++ b/pending/import1.typ @@ -0,0 +1 @@ +#import "@local/mypkg:0.0.1" diff --git a/pending/import2.typ b/pending/import2.typ new file mode 100644 index 000000000..7d1515e1a --- /dev/null +++ b/pending/import2.typ @@ -0,0 +1 @@ +#import "@nope/mypkg:0.0.1" diff --git a/pending/import3.typ b/pending/import3.typ new file mode 100644 index 000000000..5010e4daa --- /dev/null +++ b/pending/import3.typ @@ -0,0 +1 @@ +#import "@local/penpo:5.0.0" diff --git a/pending/import4.typ b/pending/import4.typ new file mode 100644 index 000000000..cdd6c755a --- /dev/null +++ b/pending/import4.typ @@ -0,0 +1 @@ +#import "@local/noperm:0.0.1" diff --git a/pending/import5.typ b/pending/import5.typ new file mode 100644 index 000000000..f354b64e3 --- /dev/null +++ b/pending/import5.typ @@ -0,0 +1 @@ +#import "@preview/nope:0.0.1" diff --git a/pending/runall.sh b/pending/runall.sh new file mode 100755 index 000000000..bfe75c63d --- /dev/null +++ b/pending/runall.sh @@ -0,0 +1,5 @@ +#! /usr/bin/env bash + +for file in $(ls pending/*.typ); do + cargo run -- compile $file +done diff --git a/tests/suite/scripting/import.typ b/tests/suite/scripting/import.typ index 382e444cc..1866af3d6 100644 --- a/tests/suite/scripting/import.typ +++ b/tests/suite/scripting/import.typ @@ -483,3 +483,16 @@ This is never reached. --- import-from-file-package-lookalike --- // Error: 9-28 file not found (searched at tests/suite/scripting/#test/mypkg:1.0.0) #import "#test/mypkg:1.0.0": * + +--- import-from-package-namespace-not-found --- +// Error: todo +#import "@missingdir/test:0.0.0": * + +--- import-from-package-not-found --- +// Error: todo +#import "@test/missingpkg:0.0.0": * + +--- import-from-package-version-not-found --- +// Error: todo +#import "@test/mypkg:5.0.0": * +