Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove some unnecessary nolint comments. Replace gocyclo with maintidx. Add some new linters, and fix some errors reported by them.
- Loading branch information
Showing
12 changed files
with
35 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,24 @@ | ||
package icmd | ||
|
||
import ( | ||
"fmt" | ||
"syscall" | ||
"errors" | ||
|
||
exec "golang.org/x/sys/execabs" | ||
) | ||
|
||
// getExitCode returns the ExitStatus of a process from the error returned by | ||
// exec.Run(). If the exit status could not be parsed an error is returned. | ||
func getExitCode(err error) (int, error) { | ||
if exiterr, ok := err.(*exec.ExitError); ok { | ||
if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok { | ||
return procExit.ExitStatus(), nil | ||
} | ||
} | ||
return 0, fmt.Errorf("failed to get exit code: %w", err) | ||
} | ||
|
||
func processExitCode(err error) (exitCode int) { | ||
func processExitCode(err error) int { | ||
if err == nil { | ||
return 0 | ||
} | ||
exitCode, exiterr := getExitCode(err) | ||
if exiterr != nil { | ||
// TODO: Fix this so we check the error's text. | ||
// we've failed to retrieve exit code, so we set it to 127 | ||
return 127 | ||
|
||
var exitErr *exec.ExitError | ||
if errors.As(err, &exitErr) { | ||
if exitErr.ProcessState == nil { | ||
return 0 | ||
} | ||
if code := exitErr.ProcessState.ExitCode(); code != -1 { | ||
return code | ||
} | ||
} | ||
return exitCode | ||
return 127 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters