Help us understand the problem. What is going on with this article?

Go 1.13のerrorsへの移行手順

Go 1.13のerrorsへの移行手順

https://github.com/pkg/errors を利用している前提で紹介します。

基本

errors.Wrap(err, "") を errors.Errorf(": %w", err)に変更

errors.Wrap(err, "message")
fmt.Errorf("message: %w", err)

errors.Cause を errors.Unwrap に変更

err = errors.Cause(err)
err = errors.Unwrap(err)

エラーの値の比較をerrors.Isに変更

err = errors.Cause(err)
if err == ErrNotFound {

}
// Unwrapは不要
if errors.Is(err, ErrNotFound) {

}

type assertion を Asに変更

if myErr, ok := err.(*MyError); ok {

}
var myErr *MyError
if ok := errors.As(err, &myErr); ok {

}

その他

エラー出力でスタックトレースを表示

Go 1.13のerrors パッケージではスタックトレースの表示には対応していません。
スタックトレースの表示をしたい場合にはxerrorsへの移行手順 をご確認ください。

関連情報

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away