Example #1
0
// NewContextErrorGeneric ...
func NewContextErrorGeneric(logger log.Logger, err error) *log.Context {
	if pqe, ok := err.(*pq.Error); ok {
		return NewContextError(logger, pqe)
	}

	return sklog.NewContextErrorGeneric(logger, err)
}
Example #2
0
// NewContextErrorGeneric creates context for given error.
// Performs error type check internally to choose strategy that fits the best.
func NewContextError(logger log.Logger, err error) *log.Context {
	if ctx, ok := err.(sklog.Contexter); ok {
		return log.NewContext(logger).With(ctx.Context())
	}

	switch e := err.(type) {
	case *json.MarshalerError:
		return NewContextJSONMarshalerError(logger, e)
	case *json.InvalidUnmarshalError:
		return NewContextJSONInvalidUnmarshalError(logger, e)
	case *json.UnmarshalFieldError:
		return NewContextJSONUnmarshalFieldError(logger, e)
	case *json.UnmarshalTypeError:
		return NewContextJSONUnmarshalTypeError(logger, e)
	case *json.UnsupportedTypeError:
		return NewContextJSONUnsupportedTypeError(logger, e)
	case *json.UnsupportedValueError:
		return NewContextJSONUnsupportedValueError(logger, e)
	case *json.InvalidUTF8Error:
		return NewContextJSONInvalidUTF8Error(logger, e)
	case *json.SyntaxError:
		return NewContextJSONSyntaxError(logger, e)
	default:
		return sklog.NewContextErrorGeneric(logger, e)
	}
}
Example #3
0
// NewContextJSONUnmarshalTypeError ...
func NewContextJSONUnmarshalTypeError(logger log.Logger, e *json.UnmarshalTypeError) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"json_type", e.Type,
		"json_offset", e.Offset,
		"json_value", e.Value,
	)
}
Example #4
0
// NewContextErrorGeneric ...
func NewContextErrorGeneric(logger log.Logger, err error) *log.Context {
	if mgoe, ok := err.(*mgo.QueryError); ok {
		return NewContextQueryError(logger, mgoe)
	}

	return sklog.NewContextErrorGeneric(logger, err)
}
Example #5
0
// NewContextNetOpError ...
func NewContextNetOpError(logger log.Logger, e *net.OpError) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"net_addr", e.Addr,
		"net_net", e.Net,
		"net_op", e.Op,
		"net_source", e.Source,
	)
}
Example #6
0
// NewContextJSONUnmarshalFieldError ...
func NewContextJSONUnmarshalFieldError(logger log.Logger, e *json.UnmarshalFieldError) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"json_key", e.Key,
		"json_type", e.Type,
		"json_field_name", e.Field.Name,
		"json_field_pkg_path", e.Field.PkgPath,
		"json_field_type", e.Field.Type,
		"json_field_tag", e.Field.Tag,
		"json_field_offset", e.Field.Offset,
		"json_field_index", e.Field.Index,
		"json_field_anonymous", e.Field.Anonymous,
	)
}
Example #7
0
// NewContextError ...
func NewContextError(logger log.Logger, err *pq.Error) *log.Context {
	pqCodeName := ""
	pqCodeClass := ""

	if err.Code != "" && len(err.Code) == 5 {
		pqCodeName = err.Code.Name()
		pqCodeClass = err.Code.Class().Name()
	}
	return sklog.NewContextErrorGeneric(logger, err).With(
		"pq_code", err.Code,
		"pq_code_name", pqCodeName,
		"pq_code_class", pqCodeClass,
		"pq_details", err.Detail,
		"pq_hint", err.Hint,
		"pq_table", err.Table,
		"pq_constraint", err.Constraint,
		"pq_internal_query", err.InternalQuery,
		"pq_where", err.Where,
	)
}
Example #8
0
// NewContextErrorGeneric creates context for given error.
// Performs error type check internally to choose strategy that fits the best.
func NewContextErrorGeneric(logger log.Logger, err error) *log.Context {
	if ctx, ok := err.(sklog.Contexter); ok {
		return log.NewContext(logger).With(ctx.Context())
	}

	switch e := err.(type) {
	case *reflect.ValueError:
		return NewContextReflectValueError(logger, e)
	// encoding/json
	case *json.MarshalerError:
		return NewContextJSONMarshalerError(logger, e)
	case *json.InvalidUnmarshalError:
		return NewContextJSONInvalidUnmarshalError(logger, e)
	case *json.UnmarshalFieldError:
		return NewContextJSONUnmarshalFieldError(logger, e)
	case *json.UnmarshalTypeError:
		return NewContextJSONUnmarshalTypeError(logger, e)
	case *json.UnsupportedTypeError:
		return NewContextJSONUnsupportedTypeError(logger, e)
	case *json.UnsupportedValueError:
		return NewContextJSONUnsupportedValueError(logger, e)
	case *json.InvalidUTF8Error:
		return NewContextJSONInvalidUTF8Error(logger, e)
	case *json.SyntaxError:
		return NewContextJSONSyntaxError(logger, e)
	// os
	case *os.PathError:
		return NewContextOSPathError(logger, e)
	case *os.SyscallError:
		return NewContextOSSyscallError(logger, e)
	case *scanner.Error:
		return NewContextScannerError(logger, e)
	case *net.OpError:
		return NewContextNetOpError(logger, e)
	case *textproto.Error:
		return NewContextTextProtoError(logger, e)
	default:
		return sklog.NewContextErrorGeneric(logger, e)
	}
}
Example #9
0
// NewContextOSPathError ...
func NewContextOSPathError(logger log.Logger, e *os.PathError) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"os_op", e.Op,
		"os_path", e.Path,
	)
}
Example #10
0
// NewContextJSONSyntaxError ...
func NewContextJSONSyntaxError(logger log.Logger, e *json.SyntaxError) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"json_offset", e.Offset,
	)
}
Example #11
0
// NewContextJSONInvalidUTF8Error ...
func NewContextJSONInvalidUTF8Error(logger log.Logger, e *json.InvalidUTF8Error) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"json_s", e.S,
	)
}
Example #12
0
// NewContextJSONUnsupportedValueError ...
func NewContextJSONUnsupportedValueError(logger log.Logger, e *json.UnsupportedValueError) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"json_value", e.Value,
		"json_str", e.Str,
	)
}
Example #13
0
// NewContextJSONUnsupportedTypeError ...
func NewContextJSONUnsupportedTypeError(logger log.Logger, e *json.UnsupportedTypeError) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"json_type", e.Type,
	)
}
Example #14
0
// NewContextJSONInvalidUnmarshalError ...
func NewContextJSONInvalidUnmarshalError(logger log.Logger, e *json.InvalidUnmarshalError) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"json_type", e.Type,
	)
}
Example #15
0
// NewContextJSONMarshalerError ...
func NewContextJSONMarshalerError(logger log.Logger, e *json.MarshalerError) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"json_type", e.Type,
	)
}
Example #16
0
// NewContextScannerError ...
func NewContextScannerError(logger log.Logger, e *scanner.Error) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"scanner_pos", e.Pos,
	)
}
Example #17
0
// NewContextOSSyscallError ...
func NewContextOSSyscallError(logger log.Logger, e *os.SyscallError) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"os_syscall", e.Syscall,
	)
}
Example #18
0
// NewContextTextProtoError ...
func NewContextTextProtoError(logger log.Logger, e *textproto.Error) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"textproto_code", e.Code,
	)
}
Example #19
0
// NewContextQueryError ...
func NewContextQueryError(logger log.Logger, err *mgo.QueryError) *log.Context {
	return sklog.NewContextErrorGeneric(logger, err).With(
		"mgo_query_code", err.Code,
		"mgo_query_assertion", err.Assertion,
	)
}
Example #20
0
// NewContextReflectValueError ...
func NewContextReflectValueError(logger log.Logger, e *reflect.ValueError) *log.Context {
	return sklog.NewContextErrorGeneric(logger, e).With(
		"reflect_kind", e.Kind,
		"reflect_method", e.Method,
	)
}