File: error.go

package info (click to toggle)
packer 1.6.6%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 33,156 kB
  • sloc: sh: 1,154; python: 619; makefile: 251; ruby: 205; xml: 97
file content (50 lines) | stat: -rw-r--r-- 1,208 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package function

import (
	"fmt"
	"runtime/debug"
)

// ArgError represents an error with one of the arguments in a call. The
// attribute Index represents the zero-based index of the argument in question.
//
// Its error *may* be a cty.PathError, in which case the error actually
// pertains to a nested value within the data structure passed as the argument.
type ArgError struct {
	error
	Index int
}

func NewArgErrorf(i int, f string, args ...interface{}) error {
	return ArgError{
		error: fmt.Errorf(f, args...),
		Index: i,
	}
}

func NewArgError(i int, err error) error {
	return ArgError{
		error: err,
		Index: i,
	}
}

// PanicError indicates that a panic occurred while executing either a
// function's type or implementation function. This is captured and wrapped
// into a normal error so that callers (expected to be language runtimes)
// are freed from having to deal with panics in buggy functions.
type PanicError struct {
	Value interface{}
	Stack []byte
}

func errorForPanic(val interface{}) error {
	return PanicError{
		Value: val,
		Stack: debug.Stack(),
	}
}

func (e PanicError) Error() string {
	return fmt.Sprintf("panic in function implementation: %s\n%s", e.Value, e.Stack)
}