-
Notifications
You must be signed in to change notification settings - Fork 5.8k
fix(types): add missing code property to Deno.errors.NotFoundfix(types): add missing code property to Deno.errors.NotFound #31495
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
base: main
Are you sure you want to change the base?
Conversation
The NotFound error class has a code property at runtime (typically 'ENOENT'), but this property was missing from the TypeScript type definition. This caused TypeScript errors when developers tried to access the code property. This change adds the code property to the type definition to match the runtime behavior and provide proper type safety. Fixes denoland#22807
WalkthroughThe type declaration for Deno.errors.NotFound in Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
test_error_code.ts (1)
1-12: Consider making this a proper test with assertions.This file demonstrates that
e.codeis type-checkable, but it doesn't verify the runtime behavior. Consider using the Deno test framework and adding assertions:-// Test file to verify the code property is accessible on Deno.errors.NotFound -try { - Deno.readTextFileSync("doesnt-exist"); -} catch (e) { - if (e instanceof Deno.errors.NotFound) { - // This should now compile without TypeScript errors - console.log("Error code:", e.code); - console.log("Error message:", e.message); - } else { - throw e; - } -} +import { assertEquals, assertInstanceOf } from "jsr:@std/assert"; + +Deno.test("NotFound error has code property", () => { + try { + Deno.readTextFileSync("doesnt-exist"); + } catch (e) { + assertInstanceOf(e, Deno.errors.NotFound); + assertEquals(e.code, "ENOENT"); + } +});This ensures the
codeproperty exists, is accessible, and has the expected value at runtime.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
cli/tsc/dts/lib.deno.ns.d.ts(1 hunks)test_error_code.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx,js}: For JavaScript runtime debugging, enable V8 inspector with--inspect-brkflag and connect Chrome DevTools tochrome://inspect
Useconsole.log()for debug prints in JavaScript runtime code
Files:
cli/tsc/dts/lib.deno.ns.d.tstest_error_code.ts
🔇 Additional comments (1)
cli/tsc/dts/lib.deno.ns.d.ts (1)
174-176: Reconsider addingcodeproperty to other Deno error classes—it may not align with Deno's error handling approach.Based on Deno's official documentation, the built-in error classes (
Deno.errors.NotFound,Deno.errors.PermissionDenied,Deno.errors.ConnectionRefused, etc.) do not expose acodeproperty at runtime. Deno's error handling pattern relies oninstanceofchecks rather than the Node.js-styleerror.codeproperty (e.g., "ENOENT", "EACCES").Before adding
code: stringto other error classes, verify whetherNotFoundactually has this property at runtime or if this is intended as a compatibility/interop layer specific to this PR. If it is runtime behavior, document that context in the PR. If this is an intentional compatibility addition for this PR alone, addingcodeto other errors without the same justification would be inconsistent.If
codeis being added for Node.js compatibility, consider documenting the rationale and scope. Thereadonlysuggestion remains reasonable if the property is immutable at runtime.
|
@nathanwhit please review this when you are free ,Thank You. |
Description
This PR adds the missing
codeproperty to theDeno.errors.NotFoundtype definition.Problem
The
NotFounderror class has acodeproperty at runtime (typically'ENOENT'), but this property was missing from the TypeScript type definition. This caused TypeScript errors when developers tried to access thecodeproperty.Example from issue #22807:
Solution
Added
code: stringproperty to theDeno.errors.NotFoundclass definition incli/tsc/dts/lib.deno.ns.d.ts.Changes
code: stringproperty toDeno.errors.NotFoundclassTesting
This is a type-only change that adds the missing property to match runtime behavior. The change enables TypeScript to correctly type-check code that accesses the
codeproperty onNotFounderrors.Fixes #22807The NotFound error class has a code property at runtime (typically 'ENOENT'), but this property was missing from the TypeScript type definition. This caused TypeScript errors when developers tried to access the code property.
This change adds the code property to the type definition to match the runtime behavior and provide proper type safety.
Fixes #22807