From ca2472598826dba8c47d0490a41a1f25eb6b592f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Fri, 14 Feb 2025 13:38:13 -0800 Subject: [PATCH 1/2] panic with UnreachableError in unreachable cases --- array.go | 2 +- cmd/smoke/array.go | 6 +++--- cmd/smoke/map.go | 4 ++-- cmd/smoke/typeinfo.go | 2 +- map.go | 2 +- test_utils/expected_value_utils.go | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/array.go b/array.go index 3d54976..57e421b 100644 --- a/array.go +++ b/array.go @@ -939,7 +939,7 @@ func (a *Array) Storable(_ SlabStorage, _ Address, maxInlineSize uint64) (Storab return SlabIDStorable(a.SlabID()), nil default: - panic("not reachable") + panic(NewUnreachableError()) } } diff --git a/cmd/smoke/array.go b/cmd/smoke/array.go index 9c58d88..d910a52 100644 --- a/cmd/smoke/array.go +++ b/cmd/smoke/array.go @@ -329,7 +329,7 @@ func modifyArray( case arrayMutateChildContainerAfterAppend: nextNestedLevels = nestedLevels - 1 default: - panic("not reachable") + panic(atree.NewUnreachableError()) } // Create new chid child @@ -366,7 +366,7 @@ func modifyArray( case arrayMutateChildContainerAfterSet: nextNestedLevels = nestedLevels - 1 default: - panic("not reachable") + panic(atree.NewUnreachableError()) } // Create new child child @@ -425,7 +425,7 @@ func modifyArray( case arrayMutateChildContainerAfterInsert: nextNestedLevels = nestedLevels - 1 default: - panic("not reachable") + panic(atree.NewUnreachableError()) } // Create new child child diff --git a/cmd/smoke/map.go b/cmd/smoke/map.go index a049bbd..36d07a4 100644 --- a/cmd/smoke/map.go +++ b/cmd/smoke/map.go @@ -337,7 +337,7 @@ func modifyMap( case mapMutateChildContainerAfterSet: nextNestedLevels = nestedLevels - 1 default: - panic("not reachable") + panic(atree.NewUnreachableError()) } var expectedKey, key atree.Value @@ -416,7 +416,7 @@ func modifyMap( case mapRemoveOp: if m.Type().IsComposite() { - panic("not reachable") + panic(atree.NewUnreachableError()) } // Use for-range on Go map to get random key diff --git a/cmd/smoke/typeinfo.go b/cmd/smoke/typeinfo.go index 343f7b5..0529aaf 100644 --- a/cmd/smoke/typeinfo.go +++ b/cmd/smoke/typeinfo.go @@ -125,7 +125,7 @@ func newCompositeTypeInfo() compositeTypeInfo { endIndex := startIndex + count if endIndex > len(compositeFieldNames) { - panic("not reachable") + panic(atree.NewUnreachableError()) } return compositeTypeInfo{fieldStartIndex: startIndex, fieldEndIndex: endIndex} diff --git a/map.go b/map.go index dc867ed..a764fc9 100644 --- a/map.go +++ b/map.go @@ -1137,7 +1137,7 @@ func (m *OrderedMap) Storable(_ SlabStorage, _ Address, maxInlineSize uint64) (S return SlabIDStorable(m.SlabID()), nil default: - panic("not reachable") + panic(NewUnreachableError()) } } diff --git a/test_utils/expected_value_utils.go b/test_utils/expected_value_utils.go index 49d2a34..0cd4c91 100644 --- a/test_utils/expected_value_utils.go +++ b/test_utils/expected_value_utils.go @@ -32,7 +32,7 @@ type ExpectedArrayValue []atree.Value var _ atree.Value = &ExpectedArrayValue{} func (v ExpectedArrayValue) Storable(atree.SlabStorage, atree.Address, uint64) (atree.Storable, error) { - panic("not reachable") + panic(atree.NewUnreachableError()) } // ExpectedMapValue @@ -42,7 +42,7 @@ type ExpectedMapValue map[atree.Value]atree.Value var _ atree.Value = &ExpectedMapValue{} func (v ExpectedMapValue) Storable(atree.SlabStorage, atree.Address, uint64) (atree.Storable, error) { - panic("not reachable") + panic(atree.NewUnreachableError()) } // ExpectedWrapperValue @@ -58,7 +58,7 @@ func NewExpectedWrapperValue(value atree.Value) ExpectedWrapperValue { } func (v ExpectedWrapperValue) Storable(atree.SlabStorage, atree.Address, uint64) (atree.Storable, error) { - panic("not reachable") + panic(atree.NewUnreachableError()) } func ValueEqual(expected atree.Value, actual atree.Value) (bool, error) { From 827ac1ead3d2792adf7ca668017a324a947ebf7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Fri, 14 Feb 2025 13:39:10 -0800 Subject: [PATCH 2/2] write to stderr instead of panicing, like for other errors --- cmd/smoke/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/smoke/main.go b/cmd/smoke/main.go index 0a39891..1e46d33 100644 --- a/cmd/smoke/main.go +++ b/cmd/smoke/main.go @@ -117,7 +117,8 @@ func main() { var err error seed, err = strconv.ParseInt(strings.ReplaceAll(flagSeedHex, "0x", ""), 16, 64) if err != nil { - panic("Failed to parse seed flag (hex string)") + fmt.Fprintf(os.Stderr, "failed to parse seed flag (hex string) %s: %s", flagSeedHex, err) + return } }