Skip to content

Give a ❌ error, not a stack trace, when a path can not be looked at #788

Closed

Description

@mathiasrw

Today

When the file system gives an error while the files are found, the run crashes with a stack trace and not a ❌ error.

> rexreplace foo bar "{a,$(printf 'x%.0s' {1..300})}.md"
node:fs:1746
  const stats = binding.stat(
                        ^

Error: ENAMETOOLONG: name too long, stat '{a,xxxx…}.md'
    at Object.statSync (node:fs:1746:25)
    …
> rexreplace foo bar a.md/x
Error: ENOTDIR: not a directory, scandir '…/a.md'

The exit code is 1. Seen on main (6ea7b83) with Node 22 and Bun on macOS.

There are two places it comes from:

  • fs.statSync(file, {throwIfNoEntry: false}) in findFiles (src/engine.ts:776). throwIfNoEntry only covers ENOENT, so ENAMETOOLONG, ENOTDIR (on Bun) and EACCES are thrown.
  • globs.sync() right after it. fast-glob throws on the same errors (ENAMETOOLONG from lstat, ENOTDIR from scandir on Node).

--glob-pipe makes this easier to hit, as each piped line goes through findFiles.

Change

  • A path that can not be looked at is not a file, so it goes on to be globbed.
  • An error from the glob gives a ❌ error (or a panic), like any other problem with the input, and not a stack trace.
  • Add a test for both.

Good to know

Reference

Activity

  1. added a commit that references this issue on Oct 23, 2026
    9fcd574
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions