Skip to content

[BUG] --configure-network writes invalid JSON (comma after the colon) when a postgres/mcp/web section's last member is a string with no trailing comma #2073

Closed

Description

@gotqn

Component

Darling

Performance Monitor Version

stable v3.3.0 and dev @0eb7f52c (both)

SQL Server Version

not related

Windows Version

not related

Describe the Bug

On a minimal darling.json, --configure-network (the Store branch, or any branch that adds a network block to an existing section) produces invalid JSON and aborts with "the edited darling.json did not parse … No changes were written." - so LAN exposure can't be configured via the wizard for such a file.

Steps to Reproduce

  1. Minimal config:

    { "postgres": { "managed": true, "dataDirectory": "E:\\Foo\\pg" }, "servers": [ { "name": "X", "host": "X", "auth": "sql", "username": "u", "encryptedPassword": "…" } ] }

  2. Run PerformanceMonitor.Darling.Service.exe --configure-network, choose All (or just Store), enter a bind IP, CIDR, role.

  3. At write time:

    Internal error: the edited darling.json did not parse (',' is an invalid start of a value. Path: $.postgres.dataDirectory | LineNumber: 3 | BytePositionInLine: 20.). No changes were written.

Expected Behavior

To work.

Actual Behavior

Not working.

Error Messages / Log Output


Screenshots

No response

Additional Context

Root cause: DarlingNetworkConfigEditor.InsertAsLastMember (Darling/PerformanceMonitor.Darling.Service/DarlingNetworkConfigEditor.cs:626-650) locates the previous member's end via PreviousCodeIndex(objectClose, objectOpen). PreviousCodeIndex skips StringLiteral regions, so when the last member's value is a string with no trailing comma (and no following commented template), it walks past the entire value and lands on the colon between key and value. needComma is then true and the comma is spliced in after the colon → "dataDirectory":, "…". It only bites a string-valued last member without a trailing comma; the shipped sample's postgres block ends "connectAs": "admin",, so the fixtures never exercise this shape.

Suggested fix: derive the comma-insertion point from the last member's actual value end (string-aware — e.g. reuse ValueEndFrom / enumerate members) instead of PreviousCodeIndex, which is blind to string values. Add a regression fixture with a minimal postgres/mcp/web block whose last member is string-valued and comma-less.

Activity

  1. added
    bugSomething isn't working
    on Aug 5, 2026
  2. erikdarlingdata commented on Aug 5, 2026

    @erikdarlingdata
    Owner

    Thank you for an exceptional report — the root cause was exactly as you diagnosed, verified against the classifier: string values are entirely StringLiteral region (quotes included), so PreviousCodeIndex's code-only walk from the closing brace skipped the whole value and landed on the colon, and the synthesized separator spliced in there. Only a string-valued, comma-less last member trips it, which is why the shipped sample's fixtures never caught the shape.

    Fix is up in #2075: a member-end-aware scan (PreviousMemberEndIndex) that treats a string-literal hit as the value's closing quote — a real trailing comma is Code and is found first, and quoted runs inside comments classify as Comment, so the hit is always a genuine value end. Your minimal config is the regression fixture verbatim, asserted through the same parse gate the wizard enforces plus the live ResolveNetworkExposure path. The other PreviousCodeIndex call site (member removal) only ever looks for ,/{ and is unaffected.

    Will land on dev shortly and ride the next nightly.

  3. added a commit that references this issue on Aug 5, 2026
  4. erikdarlingdata commented on Aug 5, 2026

    @erikdarlingdata
    Owner

    Fixed by #2075 (merged to dev) — the member-end-aware scan replaces the code-only walk, with your minimal config as the regression fixture. The fix is in the published 3.3.0-nightly.20260805 build if you want it before the next stable release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions