fix(result-utils): avoid collapsing error payloads to data#106
Open
AielloChan wants to merge 1 commit intosteipete:mainfrom
Open
fix(result-utils): avoid collapsing error payloads to data#106AielloChan wants to merge 1 commit intosteipete:mainfrom
AielloChan wants to merge 1 commit intosteipete:mainfrom
Conversation
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes result parsing in
src/result-utils.tssomcporterno longer collapses full error payloads todatawhen a parsed JSON object contains additional fields.Before this change, any object with a
datafield could be reduced todataalone. That meant payloads shaped like:{ "status": "error", "summary": "Failed to create base: name is required", "error": { "type": "USER_ERROR", "message": "Base name is required and cannot be empty or only whitespace", "retryable": false, "code": "INVALID_NAME" }, "data": {}, "meta": {}, "trace_id": "trace-123" }could end up rendered as:
{}This PR preserves the full object unless
datais the only field.Root Cause
tryParseJson()treated any object containingdataas an envelope wrapper and returnedrecord.datadirectly. That assumption is valid for some transport envelopes but incorrect for general API payloads wheredatais just one field among many.structuredContenthandling had already been partially corrected to preserve full objects in some cases, but the shared parsing path still unwrapped too aggressively.What Changed
unwrapJsonEnvelope()helper insrc/result-utils.ts.parseStructuredContent()andtryParseJson().jsonenvelope behavior unchanged.dataunwrapping to happen only whendatais the sole key in the object.dataappears alongsidestatus,error,summary,meta, or similar fields.Behavior After This PR
New parsing rules:
json, returnjson.data, returndata.dataand any other keys, return the full object.Tests Added
Added regression coverage for:
structuredContentpayloads that containdataplus top-level error fieldsdataplus top-level error fieldsUpdated test files:
tests/result-utils.test.tstests/cli-output-utils.test.tsVerification
Passed:
pnpm buildpnpm checkpnpm exec vitest run tests/result-utils.test.ts tests/cli-output-utils.test.tsFull
pnpm testis not green in this environment, but the failures appear unrelated to this change. They are dominated by existing sandbox and environment issues such as:listen EPERMfor localhost or unix socket listenersEPERMwriting~/.mcporter/credentials.jsontests/server-proxy.test.tsfailure unrelated to result parsingUser Impact
This makes failed tool results much easier to debug because
mcporternow preserves the full error payload instead of showing{}whendatahappens to be present and empty.Linked Issue
Closes #105