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

new(error.go): catch exec.ExitError and return error #68

Merged
merged 2 commits into from
Feb 10, 2023

Conversation

didof
Copy link
Contributor

@didof didof commented Feb 10, 2023

If the input to the in (package.json) command is invalid, there is little that can be done. It can happen, however, that it is valid but makes (incorrectly in my opinion) assumptions about the presence of certain executables on the host. This is the case of node-sdk, as seen in #62.

After internal analysis with @leodido, I propose a simple casting of the error in order to give more information about why the failure occurred.

Fixes #67

Signed-off-by: Francesco Di Donato didonato.fr@gmail.com

@didof didof added the enhancement New feature or request label Feb 10, 2023
@didof didof linked an issue Feb 10, 2023 that may be closed by this pull request
@didof didof self-assigned this Feb 10, 2023
@didof
Copy link
Contributor Author

didof commented Feb 10, 2023

Alternatively, I suggest removing what my commit adds and instead catching it further up:

if err := npmPackageLockOnly.Run(); err != nil {
		if e, ok := err.(*exec.ExitError); !ok {
			fmt.Printf("npm subprocess terminated with status code %s\n", e.ProcessState)
		}
		return []byte{}, pkgcontext.OutputErrorf(ctx, err, "couldn't generate the package-lock.json file")
	}

Copy link
Member

@leodido leodido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

But left a comment :)

@@ -29,6 +30,9 @@ func Error(ctx context.Context, input error) error {
if e, ok := input.(net.Error); ok && e.Timeout() {
return context.DeadlineExceeded
}
if e, ok := input.(*exec.ExitError); ok {
return fmt.Errorf("subprocess terminated with status code %s", e.ProcessState)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The e instance contains also the Stderr byte slice.

We could think of appending it to this error string.

Can you send a screenshot of what the Stderr byte slice contains so we can decide?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!
Screenshot 2023-02-10 at 16 25 10

Copy link
Member

@leodido leodido Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to:

  • check if len(e.Stderr) > 0
  • if so, append it to the error with string(e.Stderr)

Signed-off-by: Francesco Di Donato <didonato.fr@gmail.com>
Signed-off-by: Francesco Di Donato <didonato.fr@gmail.com>
@didof didof force-pushed the fix/could-not-generate-the-package-lockjson branch from cb33a6c to 030d4dd Compare February 10, 2023 17:15
@leodido leodido merged commit 374fd08 into main Feb 10, 2023
@leodido leodido deleted the fix/could-not-generate-the-package-lockjson branch February 10, 2023 17:20
@github-actions github-actions bot locked and limited conversation to collaborators Feb 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proxy npm logs Couldn't generate the package-lock.json file for certain projects
2 participants