exercism fetch go error-handling

Error Handling

Implement various kinds of error handling and resource management.

An important point of programming is how to handle errors and close resources even if errors occur.

If you are new to Go errors or panics we recommend reading the documentation on these topics first for context.

In this exercise you will be required to define a function Use(o ResourceOpener, input string) error that opens a resource, calls Frob(input) on the result resource and then closes that resource (in all cases). Your function should properly handle errors and panics.

ResourceOpener o will be a function you may invoke directly o() in an attempt to "open" the resource. It returns a Resource and error value in the idiomatic Go fashion:

See the common.go file for the definitions of Resource, ResourceOpener, FrobError and TransientError. You will define your solution to be in the same package as common.go and error_handling_test.go: "erratum". This will make those types available for use in your solution.

There will be a few places in your Use function where errors may occur:

Testing for specific error types may be performed by type assertions. You may also need to look at named return values as a helpful way to return error information from panic recovery.

Running the tests

To run the tests run the command go test from within the exercise directory.

If the test suite contains benchmarks, you can run these with the -bench flag:

go test -bench .

Keep in mind that each reviewer will run benchmarks on a different machine, with different specs, so the results from these benchmark tests may vary.

Further information

For more detailed information about the Go track, including how to get help if you're having trouble, please visit the exercism.io Go language page.

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.