Skip to content

CLI crashes with an uncaught exception when the input file is missing #894

Closed

Description

@troclaux
  • Are you running the latest version?
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool?
  • Have you checked the docs for helpful APIs and examples?

Description

The built-in CLI (src/cli/cli.js, fxparser) crashes with an uncaught exception and a stack trace when the input file doesn't exist. It's supposed to print its Seems an invalid file or stream. message. The same happens when the -o output file can't be written.

The try/catch around fs.readFile can't catch the throw err inside the callback, because the callback runs after the try block has already returned. The fs.writeFile callback in writeToFile and the ReadToEnd.readToEnd stdin callback have the same problem.

Version: 5.11.2 (master at 80e88a8), Node.js v22.18.0

Input

node src/cli/cli.js /nonexistent/missing.xml
echo '<a>1</a>' > in.xml && node src/cli/cli.js in.xml -o /nonexistent/dir/out.json

Code

fs.readFile(fileName, function(err, data) {
  if (err) {
    throw err; // not caught by the surrounding try/catch
  }
  callback(data.toString());
});

Output

file:///.../src/cli/cli.js:80
          throw err;
          ^

[Error: ENOENT: no such file or directory, open '/nonexistent/missing.xml'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/nonexistent/missing.xml'
}

expected data

Seems an invalid file or stream.Error: ENOENT: no such file or directory, open '/nonexistent/missing.xml'

The process should also exit with a non-zero code.

Would you like to work on this issue?

  • Yes
  • No

Activity

  1. github-actions commented on Oct 22, 2026

    @github-actions

    We're glad you find this project helpful. We'll try to address this issue ASAP. You can join Discord channel(https://discord.gg/X4Qp9u6Vz) for anonucements and pre release discussions. Don't forget to star this repo.

  2. amitguptagwl commented on Oct 27, 2026

    @amitguptagwl
    Member

    CLI has been separated and released as a separated package. What you see in this package an old version remained for the projects who have not transferred yet. Do you this bug on new package? If yes, then I can transfer this issue to that repository..

  3. troclaux commented on Oct 27, 2026

    @troclaux
    Author

    Thanks for the pointer. I checked fxp-cli and it doesn't have this crash, since processSingle awaits the read/write inside try/catch and exits with code 1. So there's no need to transfer the issue. I'll leave it to you whether #895 is worth merging for projects still on the built-in fxparser CLI; feel free to close both if not.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions