antonmedv / fx

Terminal JSON viewer & processor
https://fx.wtf
MIT License
19.01k stars 441 forks source link

Wordy transformations cause `fx` to crash with piped data #313

Closed plurry closed 4 months ago

plurry commented 5 months ago

fx tries to open the first argument as a file even when the JSON data comes from stdin. This causes it to crash when a single transformation command is too long.

On my ext4 system, this:

echo "{}" | fx "x => {
    const thisVariableNameEatsUpPreciousCharacters = {
        hereAreMoreCharacters: '💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀'
    };

    return {...x, ...thisVariableNameEatsUpPreciousCharacters};
}"

crashes with this:

error: Uncaught (in promise) Error: ENAMETOOLONG: name too long, stat
  const stat = fs.statSync(path, {throwIfNoEntry: false})
                  ^
    at __node_internal_captureLargerStackTrace (ext:deno_node/internal/errors.ts:91:9)
    at __node_internal_uvException (ext:deno_node/internal/errors.ts:184:10)
    at denoErrorToNodeError (ext:deno_node/internal/errors.ts:1871:14)
    at Module.statSync (ext:deno_node/_fs/_fs_stat.ts:166:13)
    at isFile (file:///tmp/fx-34.0.0.js:275:19)
    at main (file:///tmp/fx-34.0.0.js:35:7)

I guess it can usually be worked around by splitting the commands up into multiple arguments, but it's still annoying.

antonmedv commented 5 months ago

This is a bug. Fx should check if file exists first.

antonmedv commented 5 months ago

On macos it works:

image
antonmedv commented 5 months ago

Got the error:

}'
    at Module.statSync (node:fs:1659:25)
    at isFile (/private/var/folders/2j/0x_1mj9j4tz5hzqghjckptj80000gn/T/fx-34.0.0.js:275:19)
    at main (/private/var/folders/2j/0x_1mj9j4tz5hzqghjckptj80000gn/T/fx-34.0.0.js:35:7) {
  errno: -63,
  code: 'ENAMETOOLONG',
  syscall: 'stat',
  path: 'x => {\n' +
    '    const thisVariableNameEatsUpPreciousCharacters = {\n' +
    "        hereAreMoreCharacters: '💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀dsasdfaskjdfhaskldjfhgaslkdjfhasdlkfjhasdlkfjhasdlfkjhasdflkjasdhflkjasdhflacnskdcfhalsdkfjhasldkfjhcasdlckfajhdsflbkasjdhfclnaskdjhfalskdfgjhsdflkfjhasdlfkahjsdflkasjhdflkafdggrhdfggsdfghsdghadfgsdfgsdfglhadshfglaksjdfhalskjdfhasldkfjhaldfkjhasdlfkjhasdflkjhadflkhasdlkfjhdfkhjasdlfkjhasdflkhaflkcansdfhvlkvajhfgvbalergtcqwaleifhavslbkfchasdblkfhldsfhasdfasfasdfdfdddddddadlakfjhas;dlkfa💀'\n" +
antonmedv commented 4 months ago

Fixed.