V3: [Go] Implement new Concept Exercise: errors

Created on 1 Mar 2020  路  5Comments  路  Source: exercism/v3

[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.

Getting started

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:

Goal

The goal of this exercise is to teach the student how to work with errors in Go.

Learning objectives

  • Create new errors (errors.New)
  • create formatted errors (fmt.Errorf)
  • correct format of error message (not capitalized, no punctuation at the end)
  • wrap error messages manually with colon
  • error constants (usually exported so they can be checked against)
  • error is always the last return parameter.

Out of scope

  • error handling (checking for errors)
  • wrapping/unwrapping
  • custom error types

Concepts

  • errors.basic

Prerequisites

  • constants, types

Resources to refer to

Help

If you have any questions while implementing the exercise, please post the questions as comments in this issue.

good first issue statuin-progress tracgo typnew-exercise

All 5 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fpetru picture fpetru  路  5Comments

heshamfm picture heshamfm  路  6Comments

tehsphinx picture tehsphinx  路  4Comments

wolf99 picture wolf99  路  5Comments

SleeplessByte picture SleeplessByte  路  7Comments