feat: show warning on pkg fetch error#28
Conversation
📝 WalkthroughWalkthroughThe pull request refactors the hover provider for npmx packages by fixing a typo in the package URL function name ( Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
9romise
left a comment
There was a problem hiding this comment.
Good job! I think we could also prompt users to visit https://jsr.io when a jsr:‑style specifier is detected.
|
@9romise wdyt?
|
a053267 to
9d877e0
Compare
40cf049 to
8f5fdd9
Compare
# Conflicts: # src/providers/hover/npmx.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/providers/hover/npmx.ts (1)
46-47: Consider showing feedback for other unsupported protocols.The PR objectives mention aligning UX with tools like Version Lens that display "not supported" for unsupported registries. Currently, JSR gets explicit feedback, but other unsupported protocols result in no hover at all. For consistency, you might want to show a similar warning for other unsupported protocols.
💡 Optional: Add feedback for unsupported protocols
- if (!isSupportedProtocol(protocol)) - return + if (!isSupportedProtocol(protocol)) { + const unsupportedMd = new MarkdownString('', true) + unsupportedMd.isTrusted = true + unsupportedMd.appendMarkdown(`$(warning) Protocol "${protocol}" is not supported`) + return new Hover(unsupportedMd) + }
| const pkg = await getPackageInfo(name) | ||
| if (!pkg) { | ||
| const errorMd = new MarkdownString('', true) | ||
|
|
||
| errorMd.isTrusted = true | ||
| errorMd.appendMarkdown('$(warning) Unable to fetch package information') | ||
|
|
||
| return new Hover(errorMd) | ||
| } |
There was a problem hiding this comment.
Good error handling for fetch failures, but consider wrapping in try-catch.
This correctly addresses the PR objective of showing feedback when package lookup fails. However, looking at getPackageInfo in the relevant snippets, it returns null for 404 errors but throws for other error types. If a non-404 error occurs (e.g., network timeout, 500), this could result in an unhandled promise rejection.
🛡️ Proposed fix to handle all error cases
- const pkg = await getPackageInfo(name)
- if (!pkg) {
+ let pkg: Awaited<ReturnType<typeof getPackageInfo>> = null
+ try {
+ pkg = await getPackageInfo(name)
+ }
+ catch {
+ // Fall through to show error message
+ }
+
+ if (!pkg) {
const errorMd = new MarkdownString('', true)
errorMd.isTrusted = true
errorMd.appendMarkdown('$(warning) Unable to fetch package information')
return new Hover(errorMd)
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const pkg = await getPackageInfo(name) | |
| if (!pkg) { | |
| const errorMd = new MarkdownString('', true) | |
| errorMd.isTrusted = true | |
| errorMd.appendMarkdown('$(warning) Unable to fetch package information') | |
| return new Hover(errorMd) | |
| } | |
| let pkg: Awaited<ReturnType<typeof getPackageInfo>> = null | |
| try { | |
| pkg = await getPackageInfo(name) | |
| } | |
| catch { | |
| // Fall through to show error message | |
| } | |
| if (!pkg) { | |
| const errorMd = new MarkdownString('', true) | |
| errorMd.isTrusted = true | |
| errorMd.appendMarkdown('$(warning) Unable to fetch package information') | |
| return new Hover(errorMd) | |
| } |

Resolves #19.
Shows warning when package can't be found:
