@@ -55,7 +55,7 @@ defmodule SszEx.Decode do
55
55
{ :error ,
56
56
% Error {
57
57
message:
58
- "Invalid binary length while decoding uint.\n Expected size: #{ size } .\n Found:#{ bit_size ( binary ) } \n "
58
+ "Invalid binary length while decoding uint.\n Expected size: #{ size } .\n Found:#{ bit_size ( binary ) } "
59
59
} }
60
60
61
61
defp decode_uint ( binary , size ) do
@@ -68,7 +68,7 @@ defmodule SszEx.Decode do
68
68
{ :error ,
69
69
% Error {
70
70
message:
71
- "Invalid binary length while decoding bool.\n Expected size: 1.\n Found:#{ byte_size ( binary ) } \n "
71
+ "Invalid binary length while decoding bool.\n Expected size: 1.\n Found:#{ byte_size ( binary ) } "
72
72
} }
73
73
74
74
defp decode_bool ( "\x01 " ) , do: { :ok , true }
@@ -86,7 +86,7 @@ defmodule SszEx.Decode do
86
86
do:
87
87
{ :error ,
88
88
% Error {
89
- message: "Invalid binary value while decoding BitList.\n Empty binary found.\n "
89
+ message: "Invalid binary value while decoding BitList.\n Empty binary found."
90
90
} }
91
91
92
92
defp decode_bitlist ( bit_list , max_size ) do
@@ -98,14 +98,14 @@ defmodule SszEx.Decode do
98
98
match? ( << _ :: binary - size ( num_bytes - 1 ) , 0 >> , bit_list ) ->
99
99
{ :error ,
100
100
% Error {
101
- message: "Invalid binary value while decoding BitList.\n Missing sentinel bit.\n "
101
+ message: "Invalid binary value while decoding BitList.\n Missing sentinel bit."
102
102
} }
103
103
104
104
len > max_size ->
105
105
{ :error ,
106
106
% Error {
107
107
message:
108
- "Invalid binary length while decoding BitList. \n Expected max_size: #{ max_size } . Found: #{ len } .\n "
108
+ "Invalid binary length while decoding BitList. \n Expected max_size: #{ max_size } . Found: #{ len } ."
109
109
} }
110
110
111
111
true ->
@@ -125,7 +125,7 @@ defmodule SszEx.Decode do
125
125
_ ->
126
126
{ :error ,
127
127
% Error {
128
- message: "Invalid binary length while decoding BitVector. \n Expected size: #{ size } .\n "
128
+ message: "Invalid binary length while decoding BitVector. \n Expected size: #{ size } ."
129
129
} }
130
130
end
131
131
end
@@ -162,7 +162,7 @@ defmodule SszEx.Decode do
162
162
{ :error ,
163
163
% Error {
164
164
message:
165
- "Invalid binary length while decoding list of #{ inspect ( inner_type ) } .\n Expected max_size: #{ max_size } .\n Found: #{ byte_length } \n "
165
+ "Invalid binary length while decoding list of #{ inspect ( inner_type ) } .\n Expected max_size: #{ max_size } .\n Found: #{ byte_length } "
166
166
} }
167
167
168
168
defp check_valid_fixed_list_size ( _byte_length , _inner_type , _inner_type_size , _max_size ) ,
@@ -174,7 +174,7 @@ defmodule SszEx.Decode do
174
174
{ :error ,
175
175
% Error {
176
176
message:
177
- "Invalid binary length while decoding vector of #{ inspect ( inner_type ) } .\n Expected size #{ inner_type_size * size } bytes.\n Found: #{ byte_length } .\n "
177
+ "Invalid binary length while decoding vector of #{ inspect ( inner_type ) } .\n Expected size #{ inner_type_size * size } bytes.\n Found: #{ byte_length } ."
178
178
} }
179
179
180
180
defp check_valid_vector_size ( _byte_length , _inner_type , _inner_type_size , _size ) ,
@@ -310,7 +310,7 @@ defmodule SszEx.Decode do
310
310
{ :error ,
311
311
% Error {
312
312
message:
313
- "Invalid binary length while decoding #{ module } . \n Expected #{ expected_length } . \n Found #{ size } .\n "
313
+ "Invalid binary length while decoding #{ module } . \n Expected #{ expected_length } . \n Found #{ size } ."
314
314
} }
315
315
316
316
defp check_fixed_container_size ( _module , _expected_length , _size ) ,
@@ -322,7 +322,7 @@ defmodule SszEx.Decode do
322
322
{ :error ,
323
323
% Error {
324
324
message:
325
- "First offset does not point to the first variable byte.\n Expected index: #{ items_index } .\n Offset: #{ offset } . "
325
+ "First offset does not point to the first variable byte.\n Expected index: #{ items_index } .\n Offset: #{ offset } ."
326
326
} }
327
327
328
328
defp check_first_offset ( _offsets , _items_index , _binary_size ) ,
@@ -337,14 +337,17 @@ defmodule SszEx.Decode do
337
337
:ok ->
338
338
size = next_offset - offset
339
339
<< chunk :: binary - size ( size ) , rest :: bitstring >> = rest_bytes
340
- { :cont , { rest , [ { key , decode ( chunk , schema ) } | acc_variable_parts ] } }
340
+
341
+ { :cont ,
342
+ { rest , [ { key , decode ( chunk , schema ) |> Error . add_trace ( key ) } | acc_variable_parts ] } }
341
343
342
344
error ->
343
345
{ :halt , { << >> , [ { key , error } | acc_variable_parts ] } }
344
346
end
345
347
346
348
[ { _offset , { key , schema } } ] , { rest_bytes , acc_variable_parts } ->
347
- { :cont , { << >> , [ { key , decode ( rest_bytes , schema ) } | acc_variable_parts ] } }
349
+ { :cont ,
350
+ { << >> , [ { key , decode ( rest_bytes , schema ) |> Error . add_trace ( key ) } | acc_variable_parts ] } }
348
351
end )
349
352
|> then ( fn { << >> , variable_parts } ->
350
353
flatten_container_results ( variable_parts )
@@ -363,7 +366,9 @@ defmodule SszEx.Decode do
363
366
else
364
367
ssz_fixed_len = Utils . get_fixed_size ( schema )
365
368
<< chunk :: binary - size ( ssz_fixed_len ) , rest :: bitstring >> = binary
366
- { rest , [ { key , decode ( chunk , schema ) } | fixed_parts ] , offsets , items_index + ssz_fixed_len }
369
+
370
+ { rest , [ { key , decode ( chunk , schema ) |> Error . add_trace ( key ) } | fixed_parts ] , offsets ,
371
+ items_index + ssz_fixed_len }
367
372
end
368
373
end )
369
374
|> then ( fn { _rest_bytes , fixed_parts , offsets , items_index } ->
@@ -441,7 +446,7 @@ defmodule SszEx.Decode do
441
446
{ :error ,
442
447
% Error {
443
448
message:
444
- "Invalid binary length while decoding collection. \n Inner type size: #{ chunk_size } bytes. Binary length: #{ byte_size ( binary ) } bytes.\n "
449
+ "Invalid binary length while decoding collection. \n Inner type size: #{ chunk_size } bytes. Binary length: #{ byte_size ( binary ) } bytes."
445
450
} }
446
451
| results
447
452
]
@@ -455,7 +460,7 @@ defmodule SszEx.Decode do
455
460
case Enum . group_by ( results , fn { _ , { type , _ } } -> type end , fn { key , { _ , result } } ->
456
461
{ key , result }
457
462
end ) do
458
- % { error: errors } -> { :error , errors }
463
+ % { error: [ first_error | _rest ] } -> { :error , first_error }
459
464
summary -> { :ok , Map . get ( summary , :ok , [ ] ) }
460
465
end
461
466
end
0 commit comments