Skip to content

Conversation

@obaibula
Copy link
Contributor

In Go 1.13, the new function errors.As was added, which examines the error tree looking for an error that can be assigned to the target. Using As is preferable to the approach shown in Go by Example, because As will succeed even if the error is wrapped.

Note: In this example the error is not wrapped, but since Go by Example is a learning resource, the recommended way of examining errors should be demonstrated.

Copy link
Collaborator

@eliben eliben left a comment

Choose a reason for hiding this comment

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

Thanks! Overall I agree with the change - just a couple of small comments

// command (e.g. wrong path), and `*exec.ExitError`
// if the command ran but exited with a non-zero return
// code.
// command (e.g. executable file not found in $PATH),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please keep the original comment here

if err != nil {
switch e := err.(type) {
case *exec.Error:
var (
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd just do:

var execErr *exec.Error
var exitErr *exec.ExitError

IMHO saving one var keyword doesn't justify the two extra lines

@obaibula
Copy link
Contributor Author

Sure thing, fixed.

@obaibula obaibula requested a review from eliben September 29, 2025 18:32
@eliben eliben merged commit d2eea41 into mmcgrana:master Sep 29, 2025
2 checks passed
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