Skip to content

try catch not work if path include unicode #51802

Closed

Description

@Plumbiu

Version

v20.10.0

Platform

Microsoft Windows NT 10.0.22621.0 x64

Subsystem

node:internal/fs/promises

What steps will reproduce the bug?

run code:

import fsp from 'node:fs/promises'

async function run() {
  try {
    await fsp
      .readdir('中文-にほんご-한글-🌕🌖🌗', {
        withFileTypes: true,
        encoding: 'utf-16le',
      })
      .catch((error) => {})
  } catch (error) {}
}

run()

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

No Error in terminal

What do you see instead?

Error in terminal:

image

Additional information

No response

Activity

  1. changed the title [-]`try catch` not work if path include utf16 character[/-] [+]`try catch` not work if path include unicode[/+] on Feb 19, 2024
  2. added
    fsIssues and PRs related to file-system APIs and the fs module.
    errorsIssues and PRs related to JavaScript errors originating in Node.js core.
    on Feb 19, 2024
  3. targos commented on Feb 19, 2024

    @targos
    Member

    I can't reproduce on macOS.

  4. climba03003 commented on Feb 19, 2024

    @climba03003
    Contributor

    Reproducible on Windows.

    import fsp from 'node:fs/promises'
    
    try {
      await fsp
        .readdir('中文-にほんご-한글-🌕🌖🌗', {
          withFileTypes: true,
          encoding: 'utf-16le',
        })
        .catch((error) => {
          console.log('.catch', error)
        })
    } catch (error) {
      console.log('try catch')
    }

    It does catch some error but not the expected one.

    node index.mjs
    .catch TypeError: Cannot destructure property '0' of 'undefined' as it is undefined.
        at getDirents (node:internal/fs/utils:249:32)
        at node:internal/util:442:7
        at new Promise (<anonymous>)
        at getDirents (node:internal/util:428:12)
        at Object.readdir (node:internal/fs/promises:864:5)
        at async file:///<redact>/index.mjs:4:3
    node:internal/fs/promises:857
      const result = await binding.readdir(
                                   ^
    
    Error: ENOENT: no such file or directory, scandir
        at Object.readdir (node:internal/fs/promises:857:32)
        at file:///<redact>/index.mjs:5:6
        at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
        at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
        at async loadESM (node:internal/process/esm_loader:34:7)
        at async handleMainPromise (node:internal/modules/run_main:113:12) {
      errno: -4058,
      code: 'ENOENT',
      syscall: 'scandir'
    }
    
    Node.js v20.10.0
  5. added
    windowsIssues and PRs related to the Windows platform.
    on Feb 19, 2024
  6. kylo5aby commented on Feb 19, 2024

    @kylo5aby
    Contributor

    It can be reproduced on my Windows from v20.4.0. as mentioned in #48673 (comment), that maybe because that libuv introduced WTF-8. and as mentioned in #48673 (comment) , it has been fixed since v21.5.0

  7. AlttiRi commented on Feb 19, 2024

    @AlttiRi

    This breaking regression bug is still not fixed in 20.x "LTS" while it was fixed in "Current" 21.x in December, 2 months ago.

    I noted it in multiple issues and PRs.

  8. StefanStojanovic commented on Mar 27, 2025

    @StefanStojanovic
    Contributor

    Since this issue has not been active in over a year and there are currently LTS versions that have a fix, I'll close it. If needed, feel free to reopen.

  9. felipecrs commented on May 7, 2025

    @felipecrs

    Whatever was done here may have broken some other cases:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    errorsIssues and PRs related to JavaScript errors originating in Node.js core.fsIssues and PRs related to file-system APIs and the fs module.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions