Skip to content

Commit 854dd10

Browse files
committed
add same prefix to all internal error messages
1 parent d555d17 commit 854dd10

File tree

4 files changed

+46
-14
lines changed

4 files changed

+46
-14
lines changed

errors/errors.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func NewUnreachableError() InternalError {
3030
return NewUnexpectedError("unreachable")
3131
}
3232

33+
const InternalErrorMessagePrefix = "internal error:"
34+
3335
// InternalError is an implementation error, e.g: an unreachable code path (UnreachableError).
3436
// A program should never throw an InternalError in an ideal world.
3537
//
@@ -174,9 +176,18 @@ func (e UnexpectedError) Unwrap() error {
174176
func (e UnexpectedError) Error() string {
175177
message := e.Err.Error()
176178
if len(e.Stack) == 0 {
177-
return fmt.Sprintf("unexpected error: %s", message)
179+
return fmt.Sprintf(
180+
"%s unexpected: %s",
181+
InternalErrorMessagePrefix,
182+
message,
183+
)
178184
} else {
179-
return fmt.Sprintf("unexpected error: %s\n%s", message, e.Stack)
185+
return fmt.Sprintf(
186+
"%s unexpected: %s\n%s",
187+
InternalErrorMessagePrefix,
188+
message,
189+
e.Stack,
190+
)
180191
}
181192
}
182193

interpreter/decode.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ func (UnsupportedTagDecodingError) IsInternalError() {}
5454

5555
func (e UnsupportedTagDecodingError) Error() string {
5656
return fmt.Sprintf(
57-
"internal error: unsupported decoded tag: %d",
57+
"%s unsupported decoded tag: %d",
58+
errors.InternalErrorMessagePrefix,
5859
e.Tag,
5960
)
6061
}
@@ -69,7 +70,8 @@ func (InvalidStringLengthError) IsInternalError() {}
6970

7071
func (e InvalidStringLengthError) Error() string {
7172
return fmt.Sprintf(
72-
"internal error: invalid string length: got %d, expected max %d",
73+
"%s invalid string length: got %d, expected max %d",
74+
errors.InternalErrorMessagePrefix,
7375
e.Length,
7476
goMaxInt,
7577
)

interpreter/errors.go

+24-9
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ func (*unsupportedOperation) IsInternalError() {}
4444

4545
func (e *unsupportedOperation) Error() string {
4646
return fmt.Sprintf(
47-
"internal error: cannot evaluate unsupported %s operation: %s",
47+
"%s cannot evaluate unsupported %s operation: %s",
48+
errors.InternalErrorMessagePrefix,
4849
e.kind.Name(),
4950
e.operation.Symbol(),
5051
)
@@ -323,7 +324,10 @@ var _ errors.InternalError = InvalidatedResourceError{}
323324
func (InvalidatedResourceError) IsInternalError() {}
324325

325326
func (e InvalidatedResourceError) Error() string {
326-
return "internal error: resource is invalidated and cannot be used anymore"
327+
return fmt.Sprintf(
328+
"%s resource is invalidated and cannot be used anymore",
329+
errors.InternalErrorMessagePrefix,
330+
)
327331
}
328332

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

634638
func (e MemberAccessTypeError) Error() string {
635639
return fmt.Sprintf(
636-
"invalid member access: expected `%s`, got `%s`",
640+
"%s invalid member access: expected `%s`, got `%s`",
641+
errors.InternalErrorMessagePrefix,
637642
e.ExpectedType.QualifiedString(),
638643
e.ActualType.QualifiedString(),
639644
)
@@ -657,7 +662,8 @@ func (e ValueTransferTypeError) Error() string {
657662
)
658663

659664
return fmt.Sprintf(
660-
"invalid transfer of value: expected `%s`, got `%s`",
665+
"%s invalid transfer of value: expected `%s`, got `%s`",
666+
errors.InternalErrorMessagePrefix,
661667
expected,
662668
actual,
663669
)
@@ -675,7 +681,8 @@ func (UnexpectedMappedEntitlementError) IsInternalError() {}
675681

676682
func (e UnexpectedMappedEntitlementError) Error() string {
677683
return fmt.Sprintf(
678-
"invalid transfer of value: found an unexpected runtime mapped entitlement `%s`",
684+
"%s invalid transfer of value: found an unexpected runtime mapped entitlement `%s`",
685+
errors.InternalErrorMessagePrefix,
679686
e.Type.QualifiedString(),
680687
)
681688
}
@@ -692,7 +699,8 @@ func (ResourceConstructionError) IsInternalError() {}
692699

693700
func (e ResourceConstructionError) Error() string {
694701
return fmt.Sprintf(
695-
"cannot create resource `%s`: outside of declaring location %s",
702+
"%s cannot create resource `%s`: outside of declaring location %s",
703+
errors.InternalErrorMessagePrefix,
696704
e.CompositeType.QualifiedString(),
697705
e.CompositeType.Location.String(),
698706
)
@@ -952,7 +960,8 @@ func (InvalidAttachmentOperationTargetError) IsInternalError() {}
952960

953961
func (e InvalidAttachmentOperationTargetError) Error() string {
954962
return fmt.Sprintf(
955-
"cannot add or remove attachment with non-owned value (%T)",
963+
"%s cannot add or remove attachment with non-owned value (%T)",
964+
errors.InternalErrorMessagePrefix,
956965
e.Value,
957966
)
958967
}
@@ -1092,7 +1101,10 @@ var _ errors.InternalError = ResourceReferenceDereferenceError{}
10921101
func (ResourceReferenceDereferenceError) IsInternalError() {}
10931102

10941103
func (e ResourceReferenceDereferenceError) Error() string {
1095-
return "internal error: resource-references cannot be dereferenced"
1104+
return fmt.Sprintf(
1105+
"%s resource-references cannot be dereferenced",
1106+
errors.InternalErrorMessagePrefix,
1107+
)
10961108
}
10971109

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

11191131
func (e InvalidCapabilityIDError) Error() string {
1120-
return "capability created with invalid ID"
1132+
return fmt.Sprintf(
1133+
"%s capability created with invalid ID",
1134+
errors.InternalErrorMessagePrefix,
1135+
)
11211136
}
11221137

11231138
// ReferencedValueChangedError

runtime/storage.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -380,5 +380,9 @@ var _ errors.InternalError = UnreferencedRootSlabsError{}
380380
func (UnreferencedRootSlabsError) IsInternalError() {}
381381

382382
func (e UnreferencedRootSlabsError) Error() string {
383-
return fmt.Sprintf("slabs not referenced: %s", e.UnreferencedRootSlabIDs)
383+
return fmt.Sprintf(
384+
"%s slabs not referenced: %s",
385+
errors.InternalErrorMessagePrefix,
386+
e.UnreferencedRootSlabIDs,
387+
)
384388
}

0 commit comments

Comments
 (0)