File: error.go

package info (click to toggle)
golang-github-scaleway-scaleway-sdk-go 1.0.0~beta32-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,444 kB
  • sloc: sh: 70; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 854 bytes parent folder | download | duplicates (4)
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
package errors

import "fmt"

// Error is a base error that implement scw.SdkError
type Error struct {
	Str string
	Err error
}

// Error implement standard xerror.Wrapper interface
func (e *Error) Unwrap() error {
	return e.Err
}

// Error implement standard error interface
func (e *Error) Error() string {
	str := "scaleway-sdk-go: " + e.Str
	if e.Err != nil {
		str += ": " + e.Err.Error()
	}
	return str
}

// IsScwSdkError implement SdkError interface
func (e *Error) IsScwSdkError() {}

// New creates a new error with that same interface as fmt.Errorf
func New(format string, args ...interface{}) *Error {
	return &Error{
		Str: fmt.Sprintf(format, args...),
	}
}

// Wrap an error with additional information
func Wrap(err error, format string, args ...interface{}) *Error {
	return &Error{
		Err: err,
		Str: fmt.Sprintf(format, args...),
	}
}