Skip to content

Fix file argument detection when stdin is /dev/null#414

Merged
antonmedv merged 1 commit into
antonmedv:masterfrom
kimjune01:fix-398-non-tty-file-args
May 11, 2026
Merged

Fix file argument detection when stdin is /dev/null#414
antonmedv merged 1 commit into
antonmedv:masterfrom
kimjune01:fix-398-non-tty-file-args

Conversation

@kimjune01
Copy link
Copy Markdown
Contributor

When fx runs in non-TTY contexts (like macOS LaunchAgents) where stdin is redirected from /dev/null, it incorrectly assumes piped input. It then evaluates the first argument (a file path) as JavaScript, resulting in a SyntaxError (parsing /tmp/package.json as a RegExp literal /tmp/ with flags package.json).

Example:

fx /tmp/package.json 'x.name = x.name.toUpperCase(), x' save

Error:

SyntaxError: Invalid flags supplied to RegExp constructor 'package' at 7:14

Previously, we relied solely on isatty(stdin). This adds a device-type check using os.ModeCharDevice: character devices (TTY, /dev/null) route to file mode, while non-character devices (pipes, regular files) route to stdin-input mode.

Fixes #398

Fixes antonmedv#398 where fx incorrectly treats file paths as code arguments when
run in launch agents or other non-TTY contexts with stdin redirected to
/dev/null.

Root cause: The original code only checked isatty(stdin) to decide between
file mode and pipe mode. In launch agents, stdin is not a TTY but also not
a pipe (often /dev/null), causing fx to incorrectly assume piped input and
treat the file path as JS code.

Solution: Check if stdin is an actual input stream (pipe or regular file)
vs a character device (/dev/null, /dev/tty). Use os.ModeCharDevice to
distinguish:
- Character devices (TTY, /dev/null) → file mode
- Pipes and regular files → pipe mode

This preserves all existing behavior while fixing the launch agent case.
@antonmedv antonmedv merged commit bb2c344 into antonmedv:master May 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyntaxError: SyntaxError: Invalid flags supplied to RegExp constructor

2 participants