Skip to content

Commit

Permalink
add same prefix to all internal error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Nov 28, 2024
1 parent d555d17 commit 854dd10
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
15 changes: 13 additions & 2 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func NewUnreachableError() InternalError {
return NewUnexpectedError("unreachable")
}

const InternalErrorMessagePrefix = "internal error:"

// InternalError is an implementation error, e.g: an unreachable code path (UnreachableError).
// A program should never throw an InternalError in an ideal world.
//
Expand Down Expand Up @@ -174,9 +176,18 @@ func (e UnexpectedError) Unwrap() error {
func (e UnexpectedError) Error() string {
message := e.Err.Error()
if len(e.Stack) == 0 {
return fmt.Sprintf("unexpected error: %s", message)
return fmt.Sprintf(
"%s unexpected: %s",
InternalErrorMessagePrefix,
message,
)

Check warning on line 183 in errors/errors.go

View check run for this annotation

Codecov / codecov/patch

errors/errors.go#L179-L183

Added lines #L179 - L183 were not covered by tests
} else {
return fmt.Sprintf("unexpected error: %s\n%s", message, e.Stack)
return fmt.Sprintf(
"%s unexpected: %s\n%s",
InternalErrorMessagePrefix,
message,
e.Stack,
)
}
}

Expand Down
6 changes: 4 additions & 2 deletions interpreter/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func (UnsupportedTagDecodingError) IsInternalError() {}

func (e UnsupportedTagDecodingError) Error() string {
return fmt.Sprintf(
"internal error: unsupported decoded tag: %d",
"%s unsupported decoded tag: %d",
errors.InternalErrorMessagePrefix,

Check warning on line 58 in interpreter/decode.go

View check run for this annotation

Codecov / codecov/patch

interpreter/decode.go#L57-L58

Added lines #L57 - L58 were not covered by tests
e.Tag,
)
}
Expand All @@ -69,7 +70,8 @@ func (InvalidStringLengthError) IsInternalError() {}

func (e InvalidStringLengthError) Error() string {
return fmt.Sprintf(
"internal error: invalid string length: got %d, expected max %d",
"%s invalid string length: got %d, expected max %d",
errors.InternalErrorMessagePrefix,

Check warning on line 74 in interpreter/decode.go

View check run for this annotation

Codecov / codecov/patch

interpreter/decode.go#L73-L74

Added lines #L73 - L74 were not covered by tests
e.Length,
goMaxInt,
)
Expand Down
33 changes: 24 additions & 9 deletions interpreter/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (*unsupportedOperation) IsInternalError() {}

func (e *unsupportedOperation) Error() string {
return fmt.Sprintf(
"internal error: cannot evaluate unsupported %s operation: %s",
"%s cannot evaluate unsupported %s operation: %s",
errors.InternalErrorMessagePrefix,

Check warning on line 48 in interpreter/errors.go

View check run for this annotation

Codecov / codecov/patch

interpreter/errors.go#L47-L48

Added lines #L47 - L48 were not covered by tests
e.kind.Name(),
e.operation.Symbol(),
)
Expand Down Expand Up @@ -323,7 +324,10 @@ var _ errors.InternalError = InvalidatedResourceError{}
func (InvalidatedResourceError) IsInternalError() {}

func (e InvalidatedResourceError) Error() string {
return "internal error: resource is invalidated and cannot be used anymore"
return fmt.Sprintf(
"%s resource is invalidated and cannot be used anymore",
errors.InternalErrorMessagePrefix,
)
}

// DestroyedResourceError is the error which is reported
Expand Down Expand Up @@ -633,7 +637,8 @@ func (MemberAccessTypeError) IsInternalError() {}

func (e MemberAccessTypeError) Error() string {
return fmt.Sprintf(
"invalid member access: expected `%s`, got `%s`",
"%s invalid member access: expected `%s`, got `%s`",
errors.InternalErrorMessagePrefix,
e.ExpectedType.QualifiedString(),
e.ActualType.QualifiedString(),
)
Expand All @@ -657,7 +662,8 @@ func (e ValueTransferTypeError) Error() string {
)

return fmt.Sprintf(
"invalid transfer of value: expected `%s`, got `%s`",
"%s invalid transfer of value: expected `%s`, got `%s`",
errors.InternalErrorMessagePrefix,
expected,
actual,
)
Expand All @@ -675,7 +681,8 @@ func (UnexpectedMappedEntitlementError) IsInternalError() {}

func (e UnexpectedMappedEntitlementError) Error() string {
return fmt.Sprintf(
"invalid transfer of value: found an unexpected runtime mapped entitlement `%s`",
"%s invalid transfer of value: found an unexpected runtime mapped entitlement `%s`",
errors.InternalErrorMessagePrefix,

Check warning on line 685 in interpreter/errors.go

View check run for this annotation

Codecov / codecov/patch

interpreter/errors.go#L684-L685

Added lines #L684 - L685 were not covered by tests
e.Type.QualifiedString(),
)
}
Expand All @@ -692,7 +699,8 @@ func (ResourceConstructionError) IsInternalError() {}

func (e ResourceConstructionError) Error() string {
return fmt.Sprintf(
"cannot create resource `%s`: outside of declaring location %s",
"%s cannot create resource `%s`: outside of declaring location %s",
errors.InternalErrorMessagePrefix,
e.CompositeType.QualifiedString(),
e.CompositeType.Location.String(),
)
Expand Down Expand Up @@ -952,7 +960,8 @@ func (InvalidAttachmentOperationTargetError) IsInternalError() {}

func (e InvalidAttachmentOperationTargetError) Error() string {
return fmt.Sprintf(
"cannot add or remove attachment with non-owned value (%T)",
"%s cannot add or remove attachment with non-owned value (%T)",
errors.InternalErrorMessagePrefix,

Check warning on line 964 in interpreter/errors.go

View check run for this annotation

Codecov / codecov/patch

interpreter/errors.go#L963-L964

Added lines #L963 - L964 were not covered by tests
e.Value,
)
}
Expand Down Expand Up @@ -1092,7 +1101,10 @@ var _ errors.InternalError = ResourceReferenceDereferenceError{}
func (ResourceReferenceDereferenceError) IsInternalError() {}

func (e ResourceReferenceDereferenceError) Error() string {
return "internal error: resource-references cannot be dereferenced"
return fmt.Sprintf(
"%s resource-references cannot be dereferenced",
errors.InternalErrorMessagePrefix,
)
}

// ResourceLossError
Expand All @@ -1117,7 +1129,10 @@ var _ errors.InternalError = InvalidCapabilityIDError{}
func (InvalidCapabilityIDError) IsInternalError() {}

func (e InvalidCapabilityIDError) Error() string {
return "capability created with invalid ID"
return fmt.Sprintf(
"%s capability created with invalid ID",
errors.InternalErrorMessagePrefix,
)

Check warning on line 1135 in interpreter/errors.go

View check run for this annotation

Codecov / codecov/patch

interpreter/errors.go#L1132-L1135

Added lines #L1132 - L1135 were not covered by tests
}

// ReferencedValueChangedError
Expand Down
6 changes: 5 additions & 1 deletion runtime/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,5 +380,9 @@ var _ errors.InternalError = UnreferencedRootSlabsError{}
func (UnreferencedRootSlabsError) IsInternalError() {}

func (e UnreferencedRootSlabsError) Error() string {
return fmt.Sprintf("slabs not referenced: %s", e.UnreferencedRootSlabIDs)
return fmt.Sprintf(
"%s slabs not referenced: %s",
errors.InternalErrorMessagePrefix,
e.UnreferencedRootSlabIDs,
)

Check warning on line 387 in runtime/storage.go

View check run for this annotation

Codecov / codecov/patch

runtime/storage.go#L383-L387

Added lines #L383 - L387 were not covered by tests
}

0 comments on commit 854dd10

Please sign in to comment.