diff options
author | Ian Gudger <igudger@google.com> | 2019-01-03 15:09:31 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-01-03 15:10:31 -0800 |
commit | 4a4cc7dc3794535f3d65736cde4293ecf0e565e0 (patch) | |
tree | 199a34b8f7266c1f307c3cfa5030bc4e2f4125e5 /pkg/syserr/syserr.go | |
parent | d033a76fa6e215cb302e5383dbd7b0120de4395d (diff) |
Allow creating syserr.Errors at runtime.
Not allowing this was an oversight.
PiperOrigin-RevId: 227757813
Change-Id: I845800ab69028b7320afca36d832c477ff17c5ce
Diffstat (limited to 'pkg/syserr/syserr.go')
-rw-r--r-- | pkg/syserr/syserr.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/pkg/syserr/syserr.go b/pkg/syserr/syserr.go index 6a66e23a2..dad83e80c 100644 --- a/pkg/syserr/syserr.go +++ b/pkg/syserr/syserr.go @@ -68,8 +68,21 @@ func New(message string, linuxTranslation *linux.Errno) *Error { return err } +// NewDynamic creates a new error with a dynamic error message and an errno +// translation. +// +// NewDynamic should only be used sparingly and not be used for static error +// messages. Errors with static error messages should be declared with New as +// global variables. +func NewDynamic(message string, linuxTranslation *linux.Errno) *Error { + return &Error{message: message, errno: linuxTranslation} +} + // NewWithoutTranslation creates a new Error. If translation is attempted on // the error, translation will fail. +// +// NewWithoutTranslation may be called at any time, but static errors should +// be declared as global variables and dynamic errors should be used sparingly. func NewWithoutTranslation(message string) *Error { return &Error{message: message, noTranslation: true} } |