Deviopath › Go

Wrap an Error

Medium · Errors

fmt.Errorf("load: %w", err) wraps err so errors.Is and errors.Unwrap still see it. If id is empty, return fmt.Errorf("empty id") without wrapping. Otherwise wrap that error with "load: %w".

Write Load(id) that returns an error as described. CheckLoad(id) is already written and returns the error string plus whether errors.Is matches the empty-id error.

Next: Generic Max