diff --git a/CHANGELOG.md b/CHANGELOG.md index d2cc0d15..92ff0383 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Fixed +* Improved the error handling when decoding table rows with variant types. + * Fixed decoding of table rows with variant types. * Fixed serialization of `map[K]V` when using `eos.MarshalBinary` so that ordering in which the keys are serialized is in lexicographical order, just like JSON serialization. diff --git a/abidecoder.go b/abidecoder.go index a316c21e..58e73512 100644 --- a/abidecoder.go +++ b/abidecoder.go @@ -81,11 +81,13 @@ func (a *ABI) decode(binaryDecoder *Decoder, structName string) (map[string]inte } if variant := a.VariantForName(structName); variant != nil { - out, err := binaryDecoder.ReadUvarint32() + variantIndex, err := binaryDecoder.ReadUvarint32() if err != nil { - zlog.Error("error reading variant", zap.Error(err)) + return nil, fmt.Errorf("error reading variant: %w", err) + } else if int(variantIndex) >= len(variant.Types) { + return nil, fmt.Errorf("variant type index is unknown, got type index %d, know up to index %d", variantIndex, len(variant.Types)-1) } - structName = variant.Types[out] + structName, _ = a.TypeNameForNewTypeName(variant.Types[variantIndex]) } structure := a.StructForName(structName)