Skip to content
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

try catch not work if path include unicode #51802

Open
Plumbiu opened this issue Feb 19, 2024 · 4 comments
Open

try catch not work if path include unicode #51802

Plumbiu opened this issue Feb 19, 2024 · 4 comments
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.

Comments

@Plumbiu
Copy link

Plumbiu commented Feb 19, 2024

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

@Plumbiu Plumbiu changed the title try catch not work if path include utf16 character try catch not work if path include unicode Feb 19, 2024
@targos targos added fs Issues and PRs related to the fs subsystem / file system. errors Issues and PRs related to JavaScript errors originated in Node.js core. labels Feb 19, 2024
@targos
Copy link
Member

targos commented Feb 19, 2024

I can't reproduce on macOS.

@climba03003
Copy link
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

@targos targos added the windows Issues and PRs related to the Windows platform. label Feb 19, 2024
@kylo5aby
Copy link
Contributor

kylo5aby commented Feb 19, 2024

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

@AlttiRi
Copy link

AlttiRi commented Feb 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

5 participants