Skip to content

fix(path): add ERR_INVALID_ARG_TYPE code to path polyfill errors#65

Open
atharvasingh7007 wants to merge 1 commit intorivet-dev:mainfrom
atharvasingh7007:fix/issue-28-path-err-codes
Open

fix(path): add ERR_INVALID_ARG_TYPE code to path polyfill errors#65
atharvasingh7007 wants to merge 1 commit intorivet-dev:mainfrom
atharvasingh7007:fix/issue-28-path-err-codes

Conversation

@atharvasingh7007
Copy link
Copy Markdown

Summary

Fixes #28 (partially - path module only)

Upstream Node.js errors from built-in modules carry a .code property (e.g., ERR_INVALID_ARG_TYPE). The path module polyfill (backed by path-browserify) throws plain TypeError without this code property, causing conformance test failures.

This PR adds a custom path polyfill wrapper that intercepts TypeError exceptions from path-browserify and attaches the missing error.code = "ERR_INVALID_ARG_TYPE" before re-throwing.

Changes

  • New: packages/nodejs/src/polyfills/path.js - Custom path polyfill wrapper (follows the same pattern as the existing crypto.js custom polyfill)
  • Modified: packages/nodejs/src/polyfills.ts - Registered the custom path polyfill + added secure_exec_path_browserify esbuild alias

How it works

  1. Imports the original path-browserify via a build-time alias (secure_exec_path_browserify)
  2. Wraps every exported function in a try/catch
  3. When a TypeError is caught without a .code property, attaches err.code = "ERR_INVALID_ARG_TYPE"
  4. Also wraps path.posix.* functions for consistency

Testing

  • Build passes (pnpm build)
  • Type checks pass (pnpm check-types)
  • Manual verification confirms all path functions (join, resolve, normalize, basename, dirname, extname, relative) now throw errors with the correct .code property

Scope

This PR addresses Issue #28 for the path module only. The remaining affected modules (assert, buffer, url, querystring, util, fs) can be handled in follow-up PRs using the same wrapper pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conformance: Error code properties (ERR_*) missing from polyfill errors

1 participant