Unwrapping errors

Report a typo

Below you will see a very simple code implementation of a wrapped error message. Use the errors.Unwrap function to print the original error message.

Write a program in Go
package main

import (
"errors"
"fmt"
)

func main() {
err := errors.New("error: am I the original error?")
err = fmt.Errorf("error: no! I'm the original error! %w", err)

// call the errors.Unwrap function here and pass err as the argument
unwrappedErr := ?

// print the unwrapped error here
}
___

Create a free account to access the full topic