Skip to content

Commit

Permalink
Display the last primitive array item whose parsing failed
Browse files Browse the repository at this point in the history
The idea behind the implementation is that if `_debug[*].arr` is
available, it will be more complete, since it will also contain an entry
for the last array item whose value could not even be "constructed" and
inserted into the array (which is the case for primitive types, but one
can also imagine other cases, for example when `size` of the repeated
field is negative or exceeds EOF).

If `_debug[*].arr` doesn't exist (which happens for value instances
containing arrays), we fall back to the previous implementation, except
that we know that no debug info is available.
  • Loading branch information
generalmimon committed Jun 20, 2024
1 parent f53caf2 commit 08f45e6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/v1/kaitaiWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ function exportValue(obj: any, debug: IDebugInfo, hasRawAttr: boolean, path: str
}
}
else if (result.type === ObjectType.Array) {
result.arrayItems = (<any[]>obj).map((item, i) => exportValue(item, debug && debug.arr && debug.arr[i], hasRawAttr, path.concat(i.toString()), noLazy));
if (result.incomplete && debug && debug.arr) {
debug.end = inferDebugEnd(debug.arr);
result.end = debug.end;
if (debug && debug.arr) {
result.arrayItems = debug.arr.map((itemDebug, i) => exportValue(obj[i], itemDebug, hasRawAttr, path.concat(i.toString()), noLazy));
if (result.incomplete) {
debug.end = inferDebugEnd(debug.arr);
result.end = debug.end;
}
} else {
result.arrayItems = (<any[]>obj).map((item, i) => exportValue(item, undefined, hasRawAttr, path.concat(i.toString()), noLazy));
}
}
else if (result.type === ObjectType.Object) {
Expand Down

0 comments on commit 08f45e6

Please sign in to comment.