Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

run-wrangler.js exits 0 if wrangler binary not found #848

Closed
jaredmcdonald opened this issue Nov 5, 2019 · 3 comments Β· Fixed by #857
Closed

run-wrangler.js exits 0 if wrangler binary not found #848

jaredmcdonald opened this issue Nov 5, 2019 · 3 comments Β· Fixed by #857

Comments

@jaredmcdonald
Copy link
Contributor

πŸ› Bug Report

Environment

  • operating system: osx mojave
  • output of node -v: v8.11.3
  • output of wrangler -V: πŸ‘· ✨ wrangler 1.5.0

Steps to reproduce

  • install wrangler (npm i -g @cloudflare/wrangler)
  • remove the binary that was installed (in our specific case, this happened because the CI user could not write to the directory where it was trying to install)
  • try to run any wrangler command, e.g. wrangler --help
  • get no output and an exit code of 0

this appears to be due to spawnSync returning a status of null in this case:

> const {spawnSync} = require('child_process')
undefined
> spawnSync('x_x').status
null

What did you expect to see?

an error message or at least a nonzero exit code. seems that null-checking the error property on the return value of spawnSync would be enough (and maybe also sending error to stderr)

> const { spawnSync } = require('child_process')
> spawnSync('x_x').error
{ Error: spawnSync x_x ENOENT
    at _errnoException (util.js:992:11)
    at spawnSync (child_process.js:579:20)
    at repl:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:468:10)
    at emitOne (events.js:121:20)
    at REPLServer.emit (events.js:211:7)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawnSync x_x',
  path: 'x_x',
  spawnargs: [] }

What did you see instead?

exit code 0 and no output

@jaredmcdonald
Copy link
Contributor Author

i can take a crack at fixing this if it seems worthwhile--it might be that our usage was a bit too nonstandard (we were trying to install in our project as a dev dependency, instead of installing globally as recommended in the docs, which is why it couldn't install at ~/.wrangler; see also #240)

@EverlastingBugstopper
Copy link
Contributor

@jaredmcdonald we would absolutely love it if you'd take a crack at fixing this, thanks for the report! 😊

@whereisaaron
Copy link

This error still occur as at 6 Sep 2021 just trying to install wrangler into the official node container. How to recreate:

Dockerfile

FROM node:14-bullseye-slim
RUN npm install -g @cloudflare/wrangler

Command: docker build .

Error:

[+] Building 8.9s (6/6) FINISHED
 => [internal] load build definition from Dockerfile-foo                                                                                                  0.0s
 => => transferring dockerfile: 114B                                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                                         0.0s
 => => transferring context: 2B                                                                                                                           0.0s
 => [internal] load metadata for docker.io/library/node:14-bullseye-slim                                                                                  4.0s
 => [auth] library/node:pull token for registry-1.docker.io                                                                                               0.0s
 => CACHED [1/2] FROM docker.io/library/node:14-bullseye-slim@sha256:1b2caf980f422bf707f9dc64879a0a4f9f748d6d3a4e504d8485aa71884c9ec8                     0.0s
 => ERROR [2/2] RUN npm install -g @cloudflare/wrangler                                                                                                   4.7s
------
 > [2/2] RUN npm install -g @cloudflare/wrangler:
#6 4.341 /usr/local/bin/wrangler -> /usr/local/lib/node_modules/@cloudflare/wrangler/run-wrangler.js
#6 4.353
#6 4.353 > @cloudflare/[email protected] postinstall /usr/local/lib/node_modules/@cloudflare/wrangler
#6 4.353 > node ./install-wrangler.js
#6 4.353
#6 4.515 internal/fs/utils.js:314
#6 4.515     throw err;
#6 4.515     ^
#6 4.515
#6 4.515 Error: EACCES: permission denied, mkdir '/root/.wrangler'
#6 4.515     at mkdirSync (fs.js:1009:3)
#6 4.515     at Binary._getInstallDirectory (/usr/local/lib/node_modules/@cloudflare/wrangler/binary-install.js:52:13)
#6 4.515     at Binary.install (/usr/local/lib/node_modules/@cloudflare/wrangler/binary-install.js:78:26)
#6 4.515     at install (/usr/local/lib/node_modules/@cloudflare/wrangler/binary.js:50:10)
#6 4.515     at Object.<anonymous> (/usr/local/lib/node_modules/@cloudflare/wrangler/install-wrangler.js:4:1)
#6 4.515     at Module._compile (internal/modules/cjs/loader.js:1072:14)
#6 4.515     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
#6 4.515     at Module.load (internal/modules/cjs/loader.js:937:32)
#6 4.515     at Function.Module._load (internal/modules/cjs/loader.js:778:12)
#6 4.515     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
#6 4.515   errno: -13,
#6 4.515   syscall: 'mkdir',
#6 4.515   code: 'EACCES',
#6 4.515   path: '/root/.wrangler'
#6 4.515 }
#6 4.585 npm ERR! code ELIFECYCLE
#6 4.585 npm ERR! errno 1
#6 4.589 npm ERR! @cloudflare/[email protected] postinstall: `node ./install-wrangler.js`
#6 4.589 npm ERR! Exit status 1
#6 4.589 npm ERR!
#6 4.589 npm ERR! Failed at the @cloudflare/[email protected] postinstall script.
#6 4.589 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#6 4.602
#6 4.602 npm ERR! A complete log of this run can be found in:
#6 4.602 npm ERR!     /root/.npm/_logs/2021-09-06T07_01_31_977Z-debug.log
------
executor failed running [/bin/sh -c npm install -g @cloudflare/wrangler]: exit code: 1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants