ionic-cli icon indicating copy to clipboard operation
ionic-cli copied to clipboard

Call to os.userInfo can lead to uncaught SystemError

Open jurgenf opened this issue 5 years ago • 3 comments

Description: Somewhere during releases the following code has been introduced in a release: https://github.com/ionic-team/ionic-cli/commit/53d0afaea8966f7742220896a98da570c706fb63#diff-7c6997f05d0c3a730c4dd717afb61024 The problem I encounter is that in some cases the call to os.userInfo(); can lead to a SystemError if the username or homedirectory is not returned by the OS as described here: https://nodejs.org/api/os.html#os_os_userinfo_options For me this is the case when running the ionic-cli in a Docker container using the --user parameter to specify a custom UID.

Steps to Reproduce: Run the command npx ionic build --prod --verbose inside a docker container using the --user Docker argument to specify a specific UID.

Output:

ionic:utils-terminal Environment variables for CI detected: BUILD_ID, BUILD_NUMBER
SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_os_get_passwd returned ENOENT (no such file or directory)

My ionic info: Command can not run due to the aforementioned error. This was tested with the @ionic/cli latest package and is reproducible from latest until version 5.4.7 where the code was introduced. Also the exception is thrown by all modern Node versions.

Possible solution: As the method contains multiple methods of detecting a usable shell. It might be proficient to simply catch the exception and carry on using one of the following detection methods to determine the shell.

jurgenf avatar May 13 '20 11:05 jurgenf

I'm surprised this is still a problem after all this time. I encountered the problem while trying to build a capacitor app using TeamCity.

This is the stack trace documenting the exact problem

node:os:355
    throw new ERR_SYSTEM_ERROR(ctx);
    ^

SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_os_get_passwd returned ENOENT (no such file or directory)
    at new SystemError (node:internal/errors:244:5)
    at new NodeError (node:internal/errors:355:7)
    at Object.userInfo (node:os:355:11)
    at getShell (/Users/user212060/TeamCityAgent/work/b23c190b6167b5c7/node_modules/@ionic/utils-terminal/dist/info.js:15:26)
    at Object.<anonymous> (/Users/user212060/TeamCityAgent/work/b23c190b6167b5c7/node_modules/@ionic/utils-terminal/dist/info.js:35:12)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19) {
  code: 'ERR_SYSTEM_ERROR',
  info: {
    errno: -2,
    code: 'ENOENT',
    message: 'no such file or directory',
    syscall: 'uv_os_get_passwd'
  },
  errno: [Getter/Setter],
  syscall: [Getter/Setter]
}

Node.js v18.12.1

And this is the PR the avoids it allowing the build to be completed successfully: #4958

mgiova avatar Mar 10 '23 10:03 mgiova

Well i found a way to make it work in my build after hours of testing different solutions. I just set up an env variable SHELL = {}. Not sure if it's the best solution but it works.

amish1188 avatar May 03 '23 15:05 amish1188

Well i found a way to make it work in my build after hours of testing different solutions. I just set up an env variable SHELL = {}. Not sure if it's the best solution but it works.

But it seems this will still got the error, since it will always call os. userinfo?

leonnelleijing avatar Oct 24 '23 20:10 leonnelleijing