Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize internal error messages #3703

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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) 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 (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 (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 (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 @@
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 (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 @@
)

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 (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 (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 (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 @@
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 @@
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 @@
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
}
Loading