-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Annotate some errors with context canceled/deadline exceeded info
- Loading branch information
Showing
4 changed files
with
32 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["annotate.go"], | ||
importpath = "github.com/buchgr/bazel-remote/v2/utils/annotate", | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package annotate | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
func Err(ctx context.Context, prefix string, err error) error { | ||
ctxErr := ctx.Err() | ||
|
||
if ctxErr == nil { | ||
// The context is still valid/not done, we don't have extra info to add. | ||
return fmt.Errorf("%s: %w", prefix, err) | ||
} | ||
|
||
// Add info that the context was cancelled or deadline exceeded. | ||
return fmt.Errorf("%s: %w (%w)", prefix, err, ctxErr) | ||
} |