Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a meaningful error when CWD does not exist #21

Merged
merged 3 commits into from
Dec 12, 2024

Conversation

jugglinmike
Copy link
Member

Prior to this commit, if a command was executed in a non-existing current working directory, the "exec" method of the built-in child_process module would throw an error that only partially described the problem, e.g.

Error: spawn /bin/sh ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:284:19)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /bin/sh',
  path: '/bin/sh',
  spawnargs: [
    '-c',
    '/System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -f -R -trusted -u MacOSATDriverServer.app'
  ],
  cmd: '/System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -f -R -trusted -u MacOSATDriverServer.app',
  stdout: '',
  stderr: ''
}

Detect this specific error condition and provide a more detailed description, e.g.

Error: Cannot access directory: /Users/example/packages/macos-at-driver-server/MacOSATDriverServer/Build/Debug
    at exec (/Users/example/packages/macos-at-driver-server/shared/install/macos.js:42:13)
    at async unregisterExtensions (/Users/example/packages/macos-at-driver-server/shared/install/macos.js:195:3)
    at async exports.uninstall (/Users/example/packages/macos-at-driver-server/shared/install/macos.js:123:3)
    at async Object.handler (/Users/example/packages/macos-at-driver-server/shared/commands/uninstall.js:13:5) {
  [cause]: Error: spawn /bin/sh ENOENT
      at ChildProcess._handle.onexit (node:internal/child_process:284:19)
      at onErrorNT (node:internal/child_process:477:16)
      at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'spawn /bin/sh',
    path: '/bin/sh',
    spawnargs: [
      '-c',
      '/System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -f -R -trusted -u MacOSATDriverServer.app'
    ],
    cmd: '/System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -f -R -trusted -u MacOSATDriverServer.app',
    stdout: '',
    stderr: ''
  }
}

@ChrisC: This should clear up the issue that you and I (and @stalgiag before us) have observed.

Prior to this commit, if a command was executed in a non-existing
current working directory, the "exec" method of the built-in
`child_process` module would throw an error that only partially
described the problem, e.g.

    Error: spawn /bin/sh ENOENT
        at ChildProcess._handle.onexit (node:internal/child_process:284:19)
        at onErrorNT (node:internal/child_process:477:16)
        at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
      errno: -2,
      code: 'ENOENT',
      syscall: 'spawn /bin/sh',
      path: '/bin/sh',
      spawnargs: [
        '-c',
        '/System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -f -R -trusted -u MacOSATDriverServer.app'
      ],
      cmd: '/System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -f -R -trusted -u MacOSATDriverServer.app',
      stdout: '',
      stderr: ''
    }

Detect this specific error condition and provide a more detailed
description, e.g.

    Error: Cannot access directory: /Users/example/packages/macos-at-driver-server/MacOSATDriverServer/Build/Debug
        at exec (/Users/example/packages/macos-at-driver-server/shared/install/macos.js:42:13)
        at async unregisterExtensions (/Users/example/packages/macos-at-driver-server/shared/install/macos.js:195:3)
        at async exports.uninstall (/Users/example/packages/macos-at-driver-server/shared/install/macos.js:123:3)
        at async Object.handler (/Users/example/packages/macos-at-driver-server/shared/commands/uninstall.js:13:5) {
      [cause]: Error: spawn /bin/sh ENOENT
          at ChildProcess._handle.onexit (node:internal/child_process:284:19)
          at onErrorNT (node:internal/child_process:477:16)
          at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
        errno: -2,
        code: 'ENOENT',
        syscall: 'spawn /bin/sh',
        path: '/bin/sh',
        spawnargs: [
          '-c',
          '/System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -f -R -trusted -u MacOSATDriverServer.app'
        ],
        cmd: '/System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -f -R -trusted -u MacOSATDriverServer.app',
        stdout: '',
        stderr: ''
      }
    }
@jugglinmike jugglinmike requested a review from ChrisC December 11, 2024 04:50
@ChrisC
Copy link
Contributor

ChrisC commented Dec 11, 2024

Looks good, tho I'm not sure it entirely clears up the issue that Stalgia reported, since it's very likely that the uninstall command is still not working.

@jugglinmike
Copy link
Member Author

Agreed. This patch only disambiguates an error.

@jugglinmike jugglinmike merged commit 763d2b9 into main Dec 12, 2024
10 checks passed
@jugglinmike jugglinmike deleted the report-missing-cwd branch December 12, 2024 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants