From 08f45e6c8f557aaf1389cbfe96193b2fd21d4c04 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Thu, 20 Jun 2024 17:08:57 +0200 Subject: [PATCH] Display the last primitive array item whose parsing failed 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. --- src/v1/kaitaiWorker.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/v1/kaitaiWorker.ts b/src/v1/kaitaiWorker.ts index 5cfec151..e198e566 100644 --- a/src/v1/kaitaiWorker.ts +++ b/src/v1/kaitaiWorker.ts @@ -83,10 +83,14 @@ function exportValue(obj: any, debug: IDebugInfo, hasRawAttr: boolean, path: str } } else if (result.type === ObjectType.Array) { - result.arrayItems = (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 = (obj).map((item, i) => exportValue(item, undefined, hasRawAttr, path.concat(i.toString()), noLazy)); } } else if (result.type === ObjectType.Object) {