#using custom error type definitions
12 messages · Page 1 of 1 (latest)
errors are just values, and error is just an interface. you can make a value of your error type like &ConflictError{Username: user.Username} and return it.
My bad, because the method receives a pointer type
func (e *ConflictError) Error() string { return "" }
Should revise methods and interfaces
Go tour has good pages on it
@warm lantern Which go tour or effictive go pages do you recommend on this? I also have been interested in seeing what people do when handling many custom error types.
I don't think it has a specific page for custom error types, but it has good pages on methods, and interfaces
https://go.dev/tour/methods/1
This also pretty good by dave cheney: https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully
@warm lantern I do like typing errors from previous experience working with C#, but the opaque practice seems very good. I just add helpers to check for things like isTransient, isTemporary, isValidation and such. Then at my domain layer I can add those checks to add the proper error message return types.
Yeah can also switch on the type