diff --git a/internal/encoding/encoding.go b/internal/encoding/encoding.go index 8c173f51b9..fba7f33dad 100644 --- a/internal/encoding/encoding.go +++ b/internal/encoding/encoding.go @@ -45,7 +45,13 @@ func (h HexBytes) MarshalJSON() ([]byte, error) { func (h *HexBytes) UnmarshalYAML(unmarshal func(any) error) error { var hexString string if err := unmarshal(&hexString); err != nil { - return err + // compatibility mode for old state file format: + // fall back to unmarshalling as a byte slice for backwards compatibility + var oldHexBytes []byte + if err := unmarshal(&oldHexBytes); err != nil { + return fmt.Errorf("unmarshalling hex bytes: %w", err) + } + hexString = hex.EncodeToString(oldHexBytes) } return h.unmarshal(hexString) } diff --git a/internal/encoding/encoding_test.go b/internal/encoding/encoding_test.go index 3e14914ebb..0c6e4a1304 100644 --- a/internal/encoding/encoding_test.go +++ b/internal/encoding/encoding_test.go @@ -76,6 +76,16 @@ func TestUnmarshalHexBytes(t *testing.T) { jsonString: "\"\"", expected: nil, }, + "byte slice compat": { + yamlString: "[0xab, 0xcd, 0xef]", + jsonString: "\"abcdef\"", // no backwards compatibility since we never used this format for json + expected: []byte{0xab, 0xcd, 0xef}, + }, + "byte slice compat 2": { + yamlString: "[00, 12, 34]", + jsonString: "\"000c22\"", // no backwards compatibility since we never used this format for json + expected: []byte{0x00, 0x0c, 0x22}, + }, } for name, tc := range testCases {