Skip to content

Commit

Permalink
Better error message on timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jan 28, 2024
1 parent f102138 commit 3b8a98b
Show file tree
Hide file tree
Showing 36 changed files with 354 additions and 174 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
dev:
- provide better error message on context deadlline exceeded

1.35.2:
- update dependencies

Expand Down
15 changes: 10 additions & 5 deletions cmd/account/create/run.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019, 2020 Weald Technology Trading
// Copyright © 2019 - 2024 Weald Technology Trading.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -15,8 +15,8 @@ package accountcreate

import (
"context"
"errors"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -26,15 +26,20 @@ func Run(cmd *cobra.Command) (string, error) {
ctx := context.Background()
dataIn, err := input(ctx)
if err != nil {
return "", errors.Wrap(err, "failed to obtain input")
return "", errors.Join(errors.New("failed to set up command"), err)
}

// Further errors do not need a usage report.
cmd.SilenceUsage = true

dataOut, err := process(ctx, dataIn)
if err != nil {
return "", errors.Wrap(err, "failed to process")
switch {
case errors.Is(err, context.DeadlineExceeded):
return "", errors.New("operation timed out; try increasing with --timeout option")
default:
return "", errors.Join(errors.New("failed to process"), err)
}
}

if !viper.GetBool("verbose") {
Expand All @@ -43,7 +48,7 @@ func Run(cmd *cobra.Command) (string, error) {

results, err := output(ctx, dataOut)
if err != nil {
return "", errors.Wrap(err, "failed to obtain output")
return "", errors.Join(errors.New("failed to obtain output"), err)
}

return results, nil
Expand Down
15 changes: 10 additions & 5 deletions cmd/account/derive/run.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 Weald Technology Trading
// Copyright © 2020, 2024 Weald Technology Trading.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -15,9 +15,9 @@ package accountderive

import (
"context"
"errors"
"strings"

"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand All @@ -26,15 +26,20 @@ func Run(cmd *cobra.Command) (string, error) {
ctx := context.Background()
dataIn, err := input(ctx)
if err != nil {
return "", errors.Wrap(err, "failed to obtain input")
return "", errors.Join(errors.New("failed to obtain input"), err)
}

// Further errors do not need a usage report.
cmd.SilenceUsage = true

dataOut, err := process(ctx, dataIn)
if err != nil {
return "", errors.Wrap(err, "failed to process")
switch {
case errors.Is(err, context.DeadlineExceeded):
return "", errors.New("operation timed out; try increasing with --timeout option")
default:
return "", errors.Join(errors.New("failed to process"), err)
}
}

if dataIn.quiet {
Expand All @@ -43,7 +48,7 @@ func Run(cmd *cobra.Command) (string, error) {

results, err := output(ctx, dataOut)
if err != nil {
return "", errors.Wrap(err, "failed to obtain output")
return "", errors.Join(errors.New("failed to obtain output"), err)
}

return strings.TrimSuffix(results, "\n"), nil
Expand Down
15 changes: 10 additions & 5 deletions cmd/account/import/run.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019, 2020 Weald Technology Trading
// Copyright © 2019 - 2024 Weald Technology Trading.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -15,8 +15,8 @@ package accountimport

import (
"context"
"errors"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -26,15 +26,20 @@ func Run(cmd *cobra.Command) (string, error) {
ctx := context.Background()
dataIn, err := input(ctx)
if err != nil {
return "", errors.Wrap(err, "failed to obtain input")
return "", errors.Join(errors.New("failed to obtain input"), err)
}

// Further errors do not need a usage report.
cmd.SilenceUsage = true

dataOut, err := process(ctx, dataIn)
if err != nil {
return "", errors.Wrap(err, "failed to process")
switch {
case errors.Is(err, context.DeadlineExceeded):
return "", errors.New("operation timed out; try increasing with --timeout option")
default:
return "", errors.Join(errors.New("failed to process"), err)
}
}

if !viper.GetBool("verbose") {
Expand All @@ -43,7 +48,7 @@ func Run(cmd *cobra.Command) (string, error) {

results, err := output(ctx, dataOut)
if err != nil {
return "", errors.Wrap(err, "failed to obtain output")
return "", errors.Join(errors.New("failed to obtain output"), err)
}

return results, nil
Expand Down
15 changes: 10 additions & 5 deletions cmd/account/key/run.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019, 2020 Weald Technology Trading
// Copyright © 2019 - 2024 Weald Technology Trading.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -15,8 +15,8 @@ package accountkey

import (
"context"
"errors"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -26,15 +26,20 @@ func Run(cmd *cobra.Command) (string, error) {
ctx := context.Background()
dataIn, err := input(ctx)
if err != nil {
return "", errors.Wrap(err, "failed to obtain input")
return "", errors.Join(errors.New("failed to set up command"), err)
}

// Further errors do not need a usage report.
cmd.SilenceUsage = true

dataOut, err := process(ctx, dataIn)
if err != nil {
return "", errors.Wrap(err, "failed to process")
switch {
case errors.Is(err, context.DeadlineExceeded):
return "", errors.New("operation timed out; try increasing with --timeout option")
default:
return "", errors.Join(errors.New("failed to process"), err)
}
}

if viper.GetBool("quiet") {
Expand All @@ -43,7 +48,7 @@ func Run(cmd *cobra.Command) (string, error) {

results, err := output(ctx, dataOut)
if err != nil {
return "", errors.Wrap(err, "failed to obtain output")
return "", errors.Join(errors.New("failed to obtain output"), err)
}

return results, nil
Expand Down
15 changes: 10 additions & 5 deletions cmd/attester/duties/run.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 Weald Technology Trading
// Copyright © 2021, 2024 Weald Technology Trading.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -15,8 +15,8 @@ package attesterduties

import (
"context"
"errors"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -26,15 +26,20 @@ func Run(cmd *cobra.Command) (string, error) {
ctx := context.Background()
dataIn, err := input(ctx)
if err != nil {
return "", errors.Wrap(err, "failed to obtain input")
return "", errors.Join(errors.New("failed to set up command"), err)
}

// Further errors do not need a usage report.
cmd.SilenceUsage = true

dataOut, err := process(ctx, dataIn)
if err != nil {
return "", errors.Wrap(err, "failed to process")
switch {
case errors.Is(err, context.DeadlineExceeded):
return "", errors.New("operation timed out; try increasing with --timeout option")
default:
return "", errors.Join(errors.New("failed to process"), err)
}
}

if viper.GetBool("quiet") {
Expand All @@ -43,7 +48,7 @@ func Run(cmd *cobra.Command) (string, error) {

results, err := output(ctx, dataOut)
if err != nil {
return "", errors.Wrap(err, "failed to obtain output")
return "", errors.Join(errors.New("failed to obtain output"), err)
}

return results, nil
Expand Down
15 changes: 10 additions & 5 deletions cmd/attester/inclusion/run.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019, 2020 Weald Technology Trading
// Copyright © 2019 - 2024 Weald Technology Trading.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -15,8 +15,8 @@ package attesterinclusion

import (
"context"
"errors"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -26,15 +26,20 @@ func Run(cmd *cobra.Command) (string, error) {
ctx := context.Background()
dataIn, err := input(ctx)
if err != nil {
return "", errors.Wrap(err, "failed to obtain input")
return "", errors.Join(errors.New("failed to set up command"), err)
}

// Further errors do not need a usage report.
cmd.SilenceUsage = true

dataOut, err := process(ctx, dataIn)
if err != nil {
return "", errors.Wrap(err, "failed to process")
switch {
case errors.Is(err, context.DeadlineExceeded):
return "", errors.New("operation timed out; try increasing with --timeout option")
default:
return "", errors.Join(errors.New("failed to process"), err)
}
}

if viper.GetBool("quiet") {
Expand All @@ -43,7 +48,7 @@ func Run(cmd *cobra.Command) (string, error) {

results, err := output(ctx, dataOut)
if err != nil {
return "", errors.Wrap(err, "failed to obtain output")
return "", errors.Join(errors.New("failed to obtain output"), err)
}

return results, nil
Expand Down
15 changes: 10 additions & 5 deletions cmd/block/analyze/run.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Weald Technology Trading.
// Copyright © 2022, 2024 Weald Technology Trading.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -15,8 +15,8 @@ package blockanalyze

import (
"context"
"errors"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -27,14 +27,19 @@ func Run(cmd *cobra.Command) (string, error) {

c, err := newCommand(ctx)
if err != nil {
return "", errors.Wrap(err, "failed to set up command")
return "", errors.Join(errors.New("failed to set up command"), err)
}

// Further errors do not need a usage report.
cmd.SilenceUsage = true

if err := c.process(ctx); err != nil {
return "", errors.Wrap(err, "failed to process")
switch {
case errors.Is(err, context.DeadlineExceeded):
return "", errors.New("operation timed out; try increasing with --timeout option")
default:
return "", errors.Join(errors.New("failed to process"), err)
}
}

if viper.GetBool("quiet") {
Expand All @@ -43,7 +48,7 @@ func Run(cmd *cobra.Command) (string, error) {

results, err := c.output(ctx)
if err != nil {
return "", errors.Wrap(err, "failed to obtain output")
return "", errors.Join(errors.New("failed to obtain output"), err)
}

return results, nil
Expand Down
15 changes: 10 additions & 5 deletions cmd/block/info/run.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019, 2020 Weald Technology Trading
// Copyright © 2019 - 2024 Weald Technology Trading.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -15,8 +15,8 @@ package blockinfo

import (
"context"
"errors"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -26,15 +26,20 @@ func Run(cmd *cobra.Command) (string, error) {
ctx := context.Background()
dataIn, err := input(ctx)
if err != nil {
return "", errors.Wrap(err, "failed to obtain input")
return "", errors.Join(errors.New("failed to set up command"), err)
}

// Further errors do not need a usage report.
cmd.SilenceUsage = true

dataOut, err := process(ctx, dataIn)
if err != nil {
return "", errors.Wrap(err, "failed to process")
switch {
case errors.Is(err, context.DeadlineExceeded):
return "", errors.New("operation timed out; try increasing with --timeout option")
default:
return "", errors.Join(errors.New("failed to process"), err)
}
}

if viper.GetBool("quiet") {
Expand All @@ -43,7 +48,7 @@ func Run(cmd *cobra.Command) (string, error) {

results, err := output(ctx, dataOut)
if err != nil {
return "", errors.Wrap(err, "failed to obtain output")
return "", errors.Join(errors.New("failed to obtain output"), err)
}

return results, nil
Expand Down
Loading

0 comments on commit 3b8a98b

Please sign in to comment.