Skip to content

Commit

Permalink
errcode: introduce error code management
Browse files Browse the repository at this point in the history
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 openservicemesh#2866

Signed-off-by: Shashank Ram <shashr2204@gmail.com>
  • Loading branch information
shashankram committed Jun 30, 2021
1 parent 94449b5 commit af1751b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/osm-controller/osm-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
32 changes: 32 additions & 0 deletions pkg/errcode/errcode.go
Original file line number Diff line number Diff line change
@@ -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.
`,
}

0 comments on commit af1751b

Please sign in to comment.