summaryrefslogtreecommitdiff
path: root/vendor/github.com/opencontainers/runtime-tools/error
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2017-11-01 11:24:59 -0400
committerMatthew Heon <matthew.heon@gmail.com>2017-11-01 11:24:59 -0400
commita031b83a09a8628435317a03f199cdc18b78262f (patch)
treebc017a96769ce6de33745b8b0b1304ccf38e9df0 /vendor/github.com/opencontainers/runtime-tools/error
parent2b74391cd5281f6fdf391ff8ad50fd1490f6bf89 (diff)
downloadpodman-a031b83a09a8628435317a03f199cdc18b78262f.tar.gz
podman-a031b83a09a8628435317a03f199cdc18b78262f.tar.bz2
podman-a031b83a09a8628435317a03f199cdc18b78262f.zip
Initial checkin from CRI-O repo
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'vendor/github.com/opencontainers/runtime-tools/error')
-rw-r--r--vendor/github.com/opencontainers/runtime-tools/error/error.go92
1 files changed, 92 insertions, 0 deletions
diff --git a/vendor/github.com/opencontainers/runtime-tools/error/error.go b/vendor/github.com/opencontainers/runtime-tools/error/error.go
new file mode 100644
index 000000000..f5a90800e
--- /dev/null
+++ b/vendor/github.com/opencontainers/runtime-tools/error/error.go
@@ -0,0 +1,92 @@
+// Package error implements generic tooling for tracking RFC 2119
+// violations and linking back to the appropriate specification section.
+package error
+
+import (
+ "fmt"
+ "strings"
+)
+
+// Level represents the RFC 2119 compliance levels
+type Level int
+
+const (
+ // MAY-level
+
+ // May represents 'MAY' in RFC 2119.
+ May Level = iota
+ // Optional represents 'OPTIONAL' in RFC 2119.
+ Optional
+
+ // SHOULD-level
+
+ // Should represents 'SHOULD' in RFC 2119.
+ Should
+ // ShouldNot represents 'SHOULD NOT' in RFC 2119.
+ ShouldNot
+ // Recommended represents 'RECOMMENDED' in RFC 2119.
+ Recommended
+ // NotRecommended represents 'NOT RECOMMENDED' in RFC 2119.
+ NotRecommended
+
+ // MUST-level
+
+ // Must represents 'MUST' in RFC 2119
+ Must
+ // MustNot represents 'MUST NOT' in RFC 2119.
+ MustNot
+ // Shall represents 'SHALL' in RFC 2119.
+ Shall
+ // ShallNot represents 'SHALL NOT' in RFC 2119.
+ ShallNot
+ // Required represents 'REQUIRED' in RFC 2119.
+ Required
+)
+
+// Error represents an error with compliance level and specification reference.
+type Error struct {
+ // Level represents the RFC 2119 compliance level.
+ Level Level
+
+ // Reference is a URL for the violated specification requirement.
+ Reference string
+
+ // Err holds additional details about the violation.
+ Err error
+}
+
+// ParseLevel takes a string level and returns the RFC 2119 compliance level constant.
+func ParseLevel(level string) (Level, error) {
+ switch strings.ToUpper(level) {
+ case "MAY":
+ fallthrough
+ case "OPTIONAL":
+ return May, nil
+ case "SHOULD":
+ fallthrough
+ case "SHOULDNOT":
+ fallthrough
+ case "RECOMMENDED":
+ fallthrough
+ case "NOTRECOMMENDED":
+ return Should, nil
+ case "MUST":
+ fallthrough
+ case "MUSTNOT":
+ fallthrough
+ case "SHALL":
+ fallthrough
+ case "SHALLNOT":
+ fallthrough
+ case "REQUIRED":
+ return Must, nil
+ }
+
+ var l Level
+ return l, fmt.Errorf("%q is not a valid compliance level", level)
+}
+
+// Error returns the error message with specification reference.
+func (err *Error) Error() string {
+ return fmt.Sprintf("%s\nRefer to: %s", err.Err.Error(), err.Reference)
+}