Skip to content

feat: add codemod for DEP0159 ERR_INVALID_CALLBACK replacement#417

Open
syhstanley wants to merge 2 commits intonodejs:mainfrom
syhstanley:feat/err-invalid-callback-codemod
Open

feat: add codemod for DEP0159 ERR_INVALID_CALLBACK replacement#417
syhstanley wants to merge 2 commits intonodejs:mainfrom
syhstanley:feat/err-invalid-callback-codemod

Conversation

@syhstanley
Copy link
Copy Markdown

Summary

Adds a codemod for DEP0159 — replaces the deprecated ERR_INVALID_CALLBACK error code with ERR_INVALID_ARG_TYPE.

  • Replaces all string literal occurrences of ERR_INVALID_CALLBACK with ERR_INVALID_ARG_TYPE
  • Handles error code comparisons (err.code === "ERR_INVALID_CALLBACK")
  • Handles switch case labels, assert.throws expectations, .includes() checks
  • Deduplicates redundant || conditions after replacement (e.g., a === "X" || a === "X"a === "X")
  • No-change behavior when file has no references to the deprecated code

Test plan

  • 6 test cases covering all examples from ERR_INVALID_CALLBACK error code #411
  • Error code comparison in catch block
  • Test assertion with error code
  • Switch statement with error codes
  • String includes check
  • Duplicate condition deduplication
  • No-change test (no ERR_INVALID_CALLBACK references)

Closes #411

🤖 Generated with Claude Code

stanleyshen2003 and others added 2 commits March 30, 2026 03:46
…ement

Replace deprecated ERR_INVALID_CALLBACK with ERR_INVALID_ARG_TYPE
in string literals. Handles error code comparisons, switch cases,
test assertions, and string includes checks. Also deduplicates
redundant || conditions that arise after replacement.

Closes nodejs#411

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add missing README.md (required per CONTRIBUTING.md)
- Add yaml-language-server schema comment to workflow.yaml
- Sort include file patterns alphabetically
- Rename Js type alias to JS (codebase convention)
- Reorder imports alphabetically (Edit, SgRoot)
- Tighten deduplication regex: use [\w.[\]"']+ instead of \S+
- Add single-quote test case (file-7.js)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not too bad but:

for you info you have to use this structure of testing

Codemod leverages a before ("input") + after ("expected") snapshot comparison. Codemod supports 2 options:

  • 👍 Single-file fixtures
    tests/
      some-test-case-description/
        input.ts
        expected.ts
      another-test-case-description/
        input.ts
        expected.ts
    
  • 👎 Directory snapshot fixtures
    tests/
      input/
        some-test-case-description.ts
        another-test-case-description.ts
      expected
        some-test-case-description.ts
        another-test-case-description.ts
    

Use the Single-file fixtures option.

with this approach what if we have a code like that:

const myUtility = (file) => {
  // do something
  
  file.methode()
  
  if(file.empty) {
    console.warn("ERR_INVALID_CALLBACK");
  }
} 

I think it's will be catch we need to catch string fragment node which is on certain node idk know like that need to deep-dive

@AugustinMauroy AugustinMauroy added the awaiting author Reviewer has requested something from the author label Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting author Reviewer has requested something from the author ⚠️ fully-AI-generated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERR_INVALID_CALLBACK error code

3 participants