Skip to content

Instantly share code, notes, and snippets.

@13rac1
Last active April 29, 2020 03:11
Show Gist options
  • Save 13rac1/05f9e3047f6848f09851c3baae6b6de6 to your computer and use it in GitHub Desktop.
Save 13rac1/05f9e3047f6848f09851c3baae6b6de6 to your computer and use it in GitHub Desktop.
Go 1.13+ Unwrap Error stack to print type and contents to discover which error types are available for use with errors.As()
if err != nil {
for err != nil {
fmt.Printf("%T: %#v\n", err, err)
err = errors.Unwrap(err)
}
}
# Example Output
# *net.OpError: &net.OpError{Op:"read", Net:"tcp", Source:(*net.TCPAddr)(0xc00019df80), Addr:(*net.TCPAddr)(0xc00019dfb0), Err:(*os.SyscallError)(0xc000223b60)}
# *os.SyscallError: &os.SyscallError{Syscall:"read", Err:0x68}
# syscall.Errno: 0x68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment