Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bump_20.10 backport ]Fix panic in agent #3032

Open
wants to merge 1 commit into
base: bump_20.10
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions agent/exec/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,14 @@ func (t temporary) Temporary() bool { return true }
// IsTemporary returns true if the error or a recursive cause returns true for
// temporary.
func IsTemporary(err error) bool {
for err != nil {
if tmp, ok := err.(Temporary); ok && tmp.Temporary() {
return true
}
if tmp, ok := err.(Temporary); ok && tmp.Temporary() {
return true
}

cause := errors.Cause(err)
if cause == err {
break
}
cause := errors.Cause(err)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually; wondering if we should replace this function to use errors.As(). which should be compatible with both errors.Wrap() (github.com/pkg/errors) and native go 1.13 %w wrapping;

// IsTemporary returns true if the error or a recursive cause returns true for
// temporary.
func IsTemporary(err error) bool {
	var tmp Temporary
	if errors.As(err, &tmp) {
		return tmp.Temporary()
	}
	return false
}

See https://play.golang.org/p/tG1klGjjS8R

package main

import (
	"fmt"

	"github.com/pkg/errors"
)

func main() {
	err := fmt.Errorf("hello")
	err1 := temporary{fmt.Errorf("hello1: %w", err)}
	err2 := errors.Wrap(err1, "hello2")
	err3 := errors.Wrap(err2, "hello3")
	err4 := fmt.Errorf("hello4: %w", err3)
	err5 := fmt.Errorf("hello5: %w", err4)

	yeah := IsTemporary(nil)
	fmt.Println(yeah)

	yeah = IsTemporary(err)
	fmt.Println(yeah)

	yeah = IsTemporary(err5)
	fmt.Println(yeah)
}

// Temporary indicates whether or not the error condition is temporary.
//
// If this is encountered in the controller, the failing operation will be
// retried when this returns true. Otherwise, the operation is considered
// fatal.
type Temporary interface {
	Temporary() bool
}

type temporary struct {
	error
}

func (t temporary) Cause() error    { return t.error }
func (t temporary) Temporary() bool { return true }

// IsTemporary returns true if the error or a recursive cause returns true for
// temporary.
func IsTemporary(err error) bool {
	var tmp Temporary
	if errors.As(err, &tmp) {
		return tmp.Temporary()
	}
	return false
}


err = cause
if tmp, ok := cause.(Temporary); ok && tmp.Temporary() {
return true
}

return false
Expand Down