A sentinel error is a predefined, recognizable error value that callers check to identify a specific domain condition without depending on implementation details. section 5.3.2 section 6.5.3
Implement a sentinel error in Go by:
- Defining a named string type that implements the error interface. section 5.3.2 section 5.6
- Declaring exported values such as ErrCorpusIsEmpty or ErrCallingServer near the code that returns them. section 5.3.2 section 6.5.3
- Returning the sentinel for the known condition and wrapping underlying failures when additional context is needed. section 5.3.2 section 6.5.3
- Checking returned errors with errors.Is so consumers can recognize the condition through the package API. section 6.5.3 section 5.3.2
Empty corpus
Define `type corpusError string` with an `Error() string` method, then declare `const ErrCorpusIsEmpty = corpusError("corpus is empty")`. `ReadCorpus` returns this value when the file contains no data. A table-driven test expects `ErrCorpusIsEmpty` for an empty corpus while expecting 34 words from the English corpus. section 5.3.2


