← All Exercises

Error Wrapping and Unwrapping

basicgo~15min

Background

Error wrapping preserves the error chain while adding context for debugging.

Problem

Wrap errors with context using fmt.Errorf and check specific errors with errors.Is and errors.As.

Input

An error from a function call

Output

A wrapped error with context

Sample tests

Sample 1

Input: wrapped error
Expected: errors.Is matches original

Your solution

Learning objective

Learn Go error handling patterns and error chains