Last active
April 29, 2020 03:11
-
-
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()
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
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