-
Notifications
You must be signed in to change notification settings - Fork 16
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: return undefined from FetchCacher#load on NotFound #64
fix: return undefined from FetchCacher#load on NotFound #64
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test? That said, it looks like the code already handles this, but you are encountering an error. Where is this error surfacing from?
return this.#fileFetcher.fetchOnce(url, { cacheSetting, checksum }); | ||
return this.#fileFetcher.fetchOnce(url, { cacheSetting, checksum }) | ||
.catch((e) => { | ||
if (e instanceof Deno.errors.NotFound) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this code down into fileFetcher.fetchOnce instead? It looks like it's already handled for 404. Actually, it looks like the code is handled in fetchLocal too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put this here, because in Deno CLI the same kind of error handling is performed in load
method, instead of in file_fetcher. See https://github.com/denoland/deno/blob/1a0cb5b5312941521ab021cfe9eaed498f35900b/cli/cache/mod.rs#L372-L426, which is Loader
trait impl for FetchCacher
, where file_fetcher.fetch_no_follow_with_options
is called, followed by the error handling in unwrap_or_else
checking if the error is NotFound
.
So I think that putting e instanceof Deno.errors.NotFound
here would be more consistent.
Done 74da9e6
Not sure exactly, but the approach I took to finding where to fix is as follows:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I had to look into this a bit. LGTM!
This makes
FetchCacher#load
return undefined when the file fetcher returns NotFound error in order to align it with Deno CLI's implementation:With this patch, deno_emit can bundle source code containing imports from JSR.
Let's say we have a bundle target script as follows:
Without this patch, running
bundle
function from deno_emit on this script gives:With this patch, it can generate:
Ref denoland/deno_emit#167