Failure appears as an error value or condition when an operation cannot produce its intended result. Go favors direct, explicit handling over exception-based control flow, making the failure path part of ordinary program logic. section 7.0 section 7.4
A function typically returns an error as its last result. Any type implementing Error() string can represent one, allowing errors to carry either a message or structured diagnostic data. section 7.13 section 7.9
Handle failures deliberately:
- Check the error as soon as the function returns it rather than silently discarding it. section 7.13 section 7.4
- Log useful context, then return or wrap the error so callers can continue the decision path. section 7.4 section 7.13
- Use errors.Is() for a particular error and errors.As() for a particular error type. section 7.13
- Reserve panic for truly unexpected conditions; use ordinary errors for expected operational failures. section 7.13 section 7.4
Reporting missing keys in a bulk operation
A key/value store can define a bulkGetError slice containing every missing key. Its Error() method formats those keys, while BulkGet continues collecting successful values, returns the custom error when any key is absent, and wraps unexpected failures. section 7.9
Listing 7.6 An example of not capturing an error
val, _ := store.Get("fizz")
Shows the compact form of discarding a returned error, useful for contrasting brevity with deliberate failure handling. section 7.4











