From af1751b12217686541c1bd13743f64310dda7cb5 Mon Sep 17 00:00:00 2001 From: Shashank Ram Date: Wed, 30 Jun 2021 12:43:38 -0700 Subject: [PATCH] errcode: introduce error code management Introduces a pkg to manage error codes. Documentation and tooling to inspect errors will be built around the error code and description mapping provided by this pkg. Part of #2866 Signed-off-by: Shashank Ram --- cmd/osm-controller/osm-controller.go | 3 ++- pkg/errcode/errcode.go | 32 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 pkg/errcode/errcode.go diff --git a/cmd/osm-controller/osm-controller.go b/cmd/osm-controller/osm-controller.go index dca496c3ed..fa2d0a2068 100644 --- a/cmd/osm-controller/osm-controller.go +++ b/cmd/osm-controller/osm-controller.go @@ -34,6 +34,7 @@ import ( "github.com/openservicemesh/osm/pkg/endpoint" "github.com/openservicemesh/osm/pkg/envoy/ads" "github.com/openservicemesh/osm/pkg/envoy/registry" + "github.com/openservicemesh/osm/pkg/errcode" "github.com/openservicemesh/osm/pkg/gen/client/config/clientset/versioned" "github.com/openservicemesh/osm/pkg/health" "github.com/openservicemesh/osm/pkg/httpserver" @@ -109,7 +110,7 @@ func init() { func main() { log.Info().Msgf("Starting osm-controller %s; %s; %s", version.Version, version.GitCommit, version.BuildDate) if err := parseFlags(); err != nil { - log.Fatal().Err(err).Msg("Error parsing cmd line arguments") + log.Fatal().Err(err).Str(errcode.Kind, errcode.ErrInvalidCLIArgument.String()).Msg("Error parsing cmd line arguments") } if err := logger.SetLogLevel(verbosity); err != nil { diff --git a/pkg/errcode/errcode.go b/pkg/errcode/errcode.go new file mode 100644 index 0000000000..0d486c01ca --- /dev/null +++ b/pkg/errcode/errcode.go @@ -0,0 +1,32 @@ +// Package errcode defines the error codes for error messages and an explanation +// of what the error signifies. +package errcode + +import ( + "fmt" +) + +type errCode int + +const ( + // Kind defines the kind for the error code constants + Kind = "error_code" +) + +// Range 1000-1050 is reserved for errors related to +const ( + // ErrInvalidCLIArgument refers to an invalid CLI argument being specified + ErrInvalidCLIArgument errCode = iota + 1000 +) + +// String returns the error code as a string, ex. E1000 +func (e errCode) String() string { + return fmt.Sprintf("E%d", e) +} + +//nolint: deadcode,varcheck,unused +var errCodeMap = map[errCode]string{ + ErrInvalidCLIArgument: ` +An invalid comment line argument was passed to the application. +`, +}