Skip to content

Commit 8eba8c0

Browse files
committed
feat: return proper errors when failed to find or read yarn pnp manifest (#590)
1 parent 705f8c6 commit 8eba8c0

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/cache.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,22 @@ impl<Fs: FileSystem> Cache<Fs> {
192192
cwd: Option<&Path>,
193193
) -> Result<&pnp::Manifest, ResolveError> {
194194
self.yarn_pnp_manifest.get_or_try_init(|| {
195-
// TODO: map to proper error
196-
let cwd =
197-
cwd.map_or_else(|| Cow::Owned(std::env::current_dir().unwrap()), Cow::Borrowed);
198-
// TODO: map to proper error
199-
let manifest = pnp::find_pnp_manifest(&cwd).unwrap().unwrap();
195+
let cwd = match cwd {
196+
Some(path) => Cow::Borrowed(path),
197+
None => match std::env::current_dir() {
198+
Ok(path) => Cow::Owned(path),
199+
Err(err) => return Err(ResolveError::from(err)),
200+
},
201+
};
202+
let manifest = match pnp::find_pnp_manifest(&cwd) {
203+
Ok(manifest) => match manifest {
204+
Some(manifest) => manifest,
205+
None => {
206+
return Err(ResolveError::FailedToFindYarnPnpManifest(cwd.to_path_buf()));
207+
}
208+
},
209+
Err(err) => return Err(ResolveError::YarnPnpError(err)),
210+
};
200211
Ok(manifest)
201212
})
202213
}

src/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ pub enum ResolveError {
112112
/// Occurs when alias paths reference each other.
113113
#[error("Recursion in resolving")]
114114
Recursion,
115+
116+
#[cfg(feature = "yarn_pnp")]
117+
#[error("Failed to find yarn pnp manifest in {0}.")]
118+
FailedToFindYarnPnpManifest(PathBuf),
119+
120+
#[cfg(feature = "yarn_pnp")]
121+
#[error("{0}")]
122+
YarnPnpError(pnp::Error),
115123
}
116124

117125
impl ResolveError {

0 commit comments

Comments
 (0)