I currently have some basic Go code running with the following:
var test = errors.New("exit status 127")
cmd := exec.Command("sh", "-c", "'exit 3'")
err := cmd.Run()
fmt.Printf("%v\n", err)
fmt.Printf("%v\n", test)
if errors.Is(err, test) {
fmt.Printf("Ahh found error\n")
}
Now the output is as follows:
exit status 127
exit status 127
Program exited.
I think I am misunderstanding how errors.Is works as I would expect the code above to output Ahh found error as both errors are the same.
Can anyone explain why errors.Is(err, test) is not true in this instance?
Go Playground Link: https://go.dev/play/p/4MQEvljdz53
Update: This question was marked as duplicate because I was not clear enough with my question. The question should have been "How do I check for error status codes when using Go's "exec" package?" using the example of exit status 127