Compare errors with errors.Is:
if errors.Is(err, ErrNotFound) {
// Handle not found case
}
Don't use == for error comparison. errors.Is works with wrapped errors, which you'll learn about next. It checks if any error in the chain matches.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Checking error identity
Compare errors with errors.Is:
if errors.Is(err, ErrNotFound) {
// Handle not found case
}
Don't use == for error comparison. errors.Is works with wrapped errors, which you'll learn about next. It checks if any error in the chain matches.