hyperbrew / bolt-uxp

A lightning-fast boilerplate for building Adobe UXP Plugins in React, Svelte or Vue built on Vite + TypeScript + Sass
MIT License
40 stars 6 forks source link

execSync crash on Windows with invalid paths #19

Open justintaylor-dev opened 3 months ago

justintaylor-dev commented 3 months ago

Any invalid path with an exe extension will cause PS to show an error Uncaught class std::runtime_error while executing UXP TaskQueue item: Failed to create process and then PS itself will immediately crash.

Code to repro:

const cmdCrash =`anyInvalidPath.exe`;
(await require('bolt-uxp-hybrid.uxpaddon')).execSync(cmdCrash)

If the string doesn't end in ".exe", it will reject the command with a normal error message and PS will not crash.

Also, if I correctly point to a valid command line exe like ExifTool, I am getting crashes with strings that work in Terminal.

But I can run simple non-executable commands like:

const cmd1=`set n1=100 && set n2=200 && set /A sum=n1+n2`;
(await require('bolt-uxp-hybrid.uxpaddon')).execSync(cmd1) // returns 300

As a bonus, it would be great to have Bolt return the console output for the last command / all commands and the exit code.

On MacOS, you can wrap your command in a final echo to return JSON with the exit code and the terminal output of the last command.

On Windows, it's trickier as the return string includes all commands in the same string, not just the last one.

jardicc commented 3 months ago

Isn't there any ready to use code for command line in C++ that already handles common pitfalls? E.g. how NodeJS is doing that? https://github.com/nodejs/node/blob/main/src/process_wrap.cc

justintaylor-dev commented 1 month ago

@jardicc For sure, I was looking at going that route, but then I'd need to include a bunch of Node.js dependencies to get stuff working. Feel free to open a PR anytime though.

As a general update, got some progress on validating paths, but launching Windows processes this way still isn't working yet: