httptoolkit/mac-system-proxy

Error: spawn scutil ENOENT

Closed this issue · 10 comments

Hello, I am a newbie in js, I get an error when I get the system agent via node code getMacSystemProxy(), but if I execute the command directly in the terminal it works fine, which is strange. Has anyone encountered this problem?

My computer system environment is: Apple M1 Pro, macOS 12.5

Error: spawn scutil ENOENT

__node_internal_captureLargerStackTrace:errors:464:5
__node_internal_errnoException:errors:594:12
Process.ChildProcess._handle.onexit:child_process:282:19
onErrorNT:child_process:477:16

image

Hmm, very interesting. What version of Node are you using?

I guess this might be something to do with Rosetta emulation for the M1 Macs maybe... Or maybe there's just something odd about the $PATH that's used to find this binary on your system.

If you run where scutil on the command line, what path does it give you?

If you run console.log(process.env.PATH) in Node.js, what does it output?

 ~/Documents/Code  node -v                                                    
v18.0.0
 ~/Documents/Code  where scutil                                               
/usr/sbin/scutil
 ~/Documents/Code  node                                 
Welcome to Node.js v18.0.0.
Type ".help" for more information.
> console.log(process.env.PATH)
/Users/tisfeng/.rvm/gems/ruby-3.0.0/bin:/Users/tisfeng/.rvm/gems/ruby-3.0.0@global/bin:/Users/tisfeng/.rvm/rubies/ruby-3.0.0/bin:/Users/tisfeng/.poetry/bin:/Users/tisfeng/.local/share/zinit/polaris/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/tisfeng/.rvm/bin

I am actually using it in a raycast extension, run console.log(process.env.PATH), the result is undefined 😓

Aha, that sounds promising.

If you add process.env.PATH = '/usr/sbin' to your raycast extension, does that work?

Sorry, can you tell me the exact steps to do this? Because I am a newbie and I don't know how to change the environment variables, I'm also new to raycast.

I've also never used Raycast 😄. It depends how you're running this module I guess, but you need to change your code so that before you call getMacSystemProxy() you run that line of code above: process.env.PATH = '/usr/sbin'.

That code it changes the PATH (the location that is searched when looking for commands) just for the current process, so that it will look in /usr/sbin when trying to run scutil.

Ok, thank you very much for your reply, I will try it later.

@pimterry Thank you very much, I think I have solved the problem, it is caused by raycast design, they did not set env.PATH env.PATH is undefined, combined with your advice, I quickly found the problem.

One last question, is the path /usr/sbin work for all Mac? Because I want to implement the ability to automatically get the proxy on the mac, not just my own mac.

image

One last question, is the path /usr/sbin work for all Mac?

I don't know, sorry! I guess you'd need to do some testing with lots of old & new Mac OS versions to find out for sure.

If you find out the answer, do let me know. If it is definitely always that same path then I could update this module to handle that automatically.

Ok, thank you again for your patience. I will tell you if I find it. That may be a long process 😓.