QKeyDB text-format parser double-counts nesting depth on nested objects
QKeyParseError: Expected colon after key (parseNestedStructure depth mismatch on nested object)
QKeyDB text-format parseNestedStructure() decrements depth only for cross-type nesting (array inside object), never for same-type nesting (object inside object, array inside array). Real payloads like context.context_tags.environments (object > object > array) round-trip through stringifyText fine but fail to re-parse with a key-parsing error, because the parser keeps reading past its own real closing brace, misinterpreting it as a bare key.
Root Cause
parseNestedStructure scans every line for brace/bracket delta unconditionally before deciding whether to recurse. When a nested object/array of the SAME delimiter type as the parent is fully consumed by a recursive call, the parent depth counter was never decremented for that nested open/close pair, so the parent never reaches depth 0 at its own real closing delimiter. Independently verified against the live source (qkeyConverter.js lines 2597-2710): the fix's depth -= 1 compensation is present and guarded specifically for same-type nesting, matching this diagnosis exactly.
Solution Steps
- Identify all recursive calls in parseNestedStructure that recurse into a nested block of the SAME delimiter type as the parent (object-in-object, array-in-array).
- After each same-type recursive call returns, decrement the parent scope depth counter by 1 to account for the open/close pair already fully consumed by the recursive call.
- Run the two QKeyDB test files that directly exercise this parser path. Confirmed deterministic across 3 repeated runs (unlike the full suite, which has one unrelated pre-existing flaky test - anchor-emission.test.js - with no connection to this fix).
Validation
[object Object]
Rollback
[object Object]
Ecosystem: qkeydb
License: CC-BY-4.0
Last updated: Jul 6, 2026