Skip to content

fix: handle non-JSON error message in submit 400 response - #57

Open
caroolcanelas2 wants to merge 1 commit into
masterfrom
fix/handle-non-json-error-message
Open

fix: handle non-JSON error message in submit 400 response#57
caroolcanelas2 wants to merge 1 commit into
masterfrom
fix/handle-non-json-error-message

Conversation

@caroolcanelas2

Copy link
Copy Markdown
Contributor

Problem

handleSubmitAppError assumes response.data.message from the vtex.app-store-seller validation call is always a JSON-encoded string and calls JSON.parse on it unconditionally for HTTP 400 responses:

case 400: {
  logger.error(Messages.OBJECT_FORMAT, JSON.parse(response?.data?.message))
  break
}

When an upstream failure is instead propagated as a plain-text message (e.g. "Request failed with status code 401", the default axios error string, likely leaking from an internal deploy-status check that failed), JSON.parse throws a raw, unhandled SyntaxError that kills the CLI process with zero actionable context:

18:58:51.778 - info: We are validating your data, please wait a few seconds
SyntaxError: Unexpected token 'R', "Request fa"... is not valid JSON

This masked the real, fixable cause (app published but not deployed) and cost ~3 weeks of investigation across Product Support and Engineering before it was root-caused. Slack thread: internal ticket #1434688 / APPS_4680.

Fix

Wrap the JSON.parse in a try/catch. On failure, fall back to logging the raw message (in case it's still useful plain text), or a generic, actionable hint if the message is empty:

"Your submission could not be validated. Make sure your app is both published and deployed before running vtex submit, then try again. If the problem persists, contact VTEX support."

Follow-up (out of scope for this PR)

The root cause of why app-store-seller returns an unparseable message in the first place (an internal 401 propagated as raw axios error text) should also be fixed server-side, so the message is precise rather than a generic hint. Flagging to the App Store Seller team separately.

🤖 Generated with Claude Code

Previously, handleSubmitAppError assumed response.data.message from the
vtex.app-store-seller validation call was always a JSON-encoded string
and called JSON.parse on it unconditionally. When an upstream failure
(e.g. a 401 from an internal deploy-status check) is instead propagated
as a plain-text message ("Request failed with status code 401"),
JSON.parse throws a raw, unhandled SyntaxError that kills the CLI with
no actionable context for the user.

This wraps the parse in a try/catch and falls back to logging the raw
message, or a generic actionable hint (check publish + deploy) if the
message is empty.

Context: vtex.slack.com thread p1784654346302669 (TICKET #1434688) —
took ~3 weeks to root-cause a submit failure that was actually
"app published but not deployed", because the real error was masked
by this SyntaxError.
@sonar-workflows

Copy link
Copy Markdown

@wisneycardeal wisneycardeal left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants