Comment by platz

5 years ago

> Composing Errors Codes ... Instead of sprinkling if statements, the error handling can be integrated into the type ... The check for errors is only done once.

That is only a superficial level of composition, if one can call it that at all, that doesn't account for actual composition of errors of different types. The example provided is just encapsulation and therefore orthogonal to the issue of error handling approaches. i.e. in the example, the error handling code is only centralized, not composed.

Can you make the distinction between "centralization" vs "composition" of errors?

Do you mean the fact that there must be some if-statement within the API that reacts to the different errors and sets a flag used by the Err() method?

Is you opinion that "composition of errors" always requires special syntactic elements such as the match statement?

The code from the blog section:

  scanner := bufio.NewScanner(input)
  for scanner.Scan() {
      token := scanner.Text()
      // process token
  }
  if err := scanner.Err(); err != nil {
      // process the error
  }