Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Rheisen committed Mar 15, 2024
1 parent 62ad813 commit 5a2c672
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion attachment_detail_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package berr
const AttachmentDetailType = "detail"

type detailAttachment struct {
key string
value any
key string
}

func (d detailAttachment) Key() string {
Expand Down
2 changes: 1 addition & 1 deletion attachment_error_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package berr
const AttachmentErrorType = "error"

type errorAttachment struct {
key string
value error
key string
}

func (d errorAttachment) Key() string {
Expand Down
4 changes: 2 additions & 2 deletions attachment_metadata_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package berr
const AttachmentMetadataType = "metadata"

type metadataAttachment struct {
key string
value any
key string
}

func (d metadataAttachment) Key() string {
Expand All @@ -16,7 +16,7 @@ func (d metadataAttachment) Value() any {
}

func (d metadataAttachment) Type() string {
return "berr_metadata_detail"
return AttachmentMetadataType
}

func (d metadataAttachment) Sensitive() bool {
Expand Down
1 change: 1 addition & 0 deletions error_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func (e Errors) Error() string {
if idx > 0 {
builder.WriteString(", ")
}

builder.WriteString(val.Error())
}

Expand Down
15 changes: 8 additions & 7 deletions error_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ func newBerr(errorType ErrorType, errorMessage string, attachments ...Attachment
var next error

for _, d := range attachments {
if d.Type() == AttachmentErrorType && next == nil {
switch {
case d.Type() == AttachmentErrorType && next == nil:
next, _ = d.Value().(error)
} else if d.Type() == AttachmentErrorType {
case d.Type() == AttachmentErrorType:
next = fmt.Errorf("%s: %w", next, d.Value().(error))
} else if d.Type() == "berr_metadata_detail" {
case d.Type() == AttachmentMetadataType:
errorMetadata[d.Key()] = d.Value()
} else {
default:
errorDetail[d.Key()] = d.Value()
}
}
Expand All @@ -39,12 +40,12 @@ func newBerrWithAttachments(
}

type berr struct {
ErrType ErrorType `json:"-"`
ErrTypeString string `json:"error_type"`
ErrMessage string `json:"message"`
ErrDetails map[string]any `json:"details"`
ErrMetadata map[string]any `json:"-"`
nextError error
ErrTypeString string `json:"error_type"`
ErrMessage string `json:"message"`
ErrType ErrorType `json:"-"`
}

func (e *berr) String() string {
Expand Down
6 changes: 6 additions & 0 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import (

func TestErrorStructThroughInterface(t *testing.T) {
const errorMessage = "unexpected problem unmarshalling struct"

const nestedErrorMessage = "invalid struct tag"

const metadataAttachKey = "metadata_key"

const metadataAttachValue = "metadata_val"

const detailAttachKey = "detail_key"

const detailAttachValue = "detail_val"

metadataAttachment := berr.M(metadataAttachKey, metadataAttachValue)
Expand Down Expand Up @@ -198,9 +201,12 @@ func testErrorFunc(
errorFunc func(message string, attachments ...berr.Attachment) berr.Error,
errorMessage string,
) {
t.Helper()

expectErrorType := errorType

const detailAttachKey = "detail_key"

const detailAttachValue = "detail_val"

detailAttachment := berr.D(detailAttachKey, detailAttachValue)
Expand Down

0 comments on commit 5a2c672

Please sign in to comment.