[Use this issue template to describe how to implement a new concept exercises. Please fill in the issue template, and remove any sections wrapped in square brackets (such as this section!).]
This issue describes how to implement the errors concept exercise for the Go track.
Please please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:
Please also watch the following video:
The goal of this exercise is to teach the student how to work with errors in Go.
errors.basicconstants, typesIf you have any questions while implementing the exercise, please post the questions as comments in this issue.
I would like to take a stab at this, if it is not assigned to anyone else.
@micuffaro: That'd be awesome!
As there is no existing exercise in another language you could build on, I'd recommend to first implement the .meta/sample.go file with the complete solution and create a draft PR. That way we can discuss it and make changes easily before too much work has gone into it.
Hey @tehsphinx , I have a couple questions about the learning objectives of this exercise, that I may or may not be overthinking:
wrap error messages manually with colon.
Meaning something like the following?
func (e *PathError) Error() string {
return e.Op + " " + e.Path + ": " + e.Err.Error()
}
Or should we simplify? Can you provide examples?
error is always the last argument
Are we specifically talking about the return order or something else that I am missing?
f, err := strconv.ParseFloat(asciiFloat, 64)
wrap error messages manually with colon.
For example if an error happened while connecting to a tcp target you could wrap the error to give more context:
return fmt.Errorf("connecting to tcp target failed: %s", err)
Meanwhile there are many error packages that do this for you with a Wrap method -- usually also doing more fancy stuff like adding stack traces, etc. But idea of concatenating the error string to create a "error trace" is essentially still the same.
error is always the last argument
Yes, correct. Talking about the order of return parameters here. Fixed in description.
Thank you!
I put together a draft PR.
Can you take a look and let me know if it is going in the right direction?