errors.Join combines multiple Go errors into a single error value for unified handling and inspection.
Use errors.Join to combine multiple error values into a single error that can be checked with errors.Is or errors.As.
import "errors"
err1 := fmt.Errorf("failed to read file")
err2 := fmt.Errorf("failed to write file")
combined := errors.Join(err1, err2)
if combined != nil {
// Handle combined error
}
errors.Join bundles several errors together into one so you don't lose information when multiple things fail at once. It lets you check if any of the original errors are present without writing extra code. Think of it like putting several warning labels on a single box instead of having to carry multiple boxes.