fix(comment): convert plain text to ADF for v3 and surface field errors#38
Merged
Conversation
`jira issue comment add` failed silently on Jira Cloud (API v3). The
v3 endpoint requires the comment body in Atlassian Document Format, but
addComment/updateComment sent a plain string, so v3 returned a 400
("Comment body is not valid!"). That status is not in shouldFallbackApiVersion,
so no v2 retry happened. The error message was also empty because
formatJiraErrorMessage joined an empty errorMessages array and ignored
the structured `errors` object.
- Build comment bodies per API version: ADF for v3, plain text for v2,
via a dedicated requestCommentWrite() that rebuilds the payload on
fallback (requestApi can't, since it replays the same body).
- Add a narrow v2 safety-net fallback triggered only by the specific
"comment body invalid" 400 signature, not all 400s.
- Parse `errors` field map in extractErrorDetail so field-level
validation messages are shown instead of an empty string.
Fixes #37
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
requestCommentWrite() bypassed requestApi(), which dropped the isNonJsonResponse() guard for comment add/edit. On Jira Data Center/SSO setups that answer an unsupported /rest/api/3 endpoint with a 200 text/html page, the CLI would treat that HTML as a successful comment instead of falling back to v2. Mirror requestApi()'s non-JSON success check so the fallback is preserved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
🎉 This PR is included in version 2.8.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Fixes #37
Problem
jira issue comment add PROJ-123 "text"failed silently on Jira Cloud (API v3) with an empty error message and exit code 1. Three root causes, all confirmed in code:addComment/updateCommentsentbody: "plain string". The v3 endpoint requires Atlassian Document Format, so it returned400 {"errors":{"comment":"Comment body is not valid!"}}.shouldFallbackApiVersion()only triggers on 404/410, so the 400 was terminal — the CLI never retried against v2 (where plain text works).formatJiraErrorMessage()diddata.errorMessages.join(', ')— buterrorMessageswas an empty array (truthy →'') and the structurederrorsobject was ignored, so the user sawFailed to add comment:with nothing after it.Fix (option 3 from the issue: ADF + safety-net fallback + error parsing)
requestCommentWrite().requestApi()couldn't be reused because its fallback replays the same payload, and the body shape differs by version (this mirrors the existing per-version pattern insearchUsers()).isCommentBodyRejection), not all 400s — a generic 400 still surfaces as a real error rather than being masked by a double request.extractErrorDetail()now reads theerrorsfield map whenerrorMessagesis empty, so validation failures showcomment: Comment body is not valid!instead of an empty string. This improves error visibility for all write operations, not just comments.ADF conversion preserves structure: blank lines become separate paragraphs and single newlines become hard breaks (relevant for
--filemulti-line bodies).Tests
addComment/updateCommentassertions to expect ADF on v3.toADF(single paragraph, blank-line split, hard breaks, empty input) andextractErrorDetail.Out of scope / follow-up
createIssue/updateIssuesenddescriptionas a raw string and likely have the same latent v3/ADF issue. Left for a separate change since #37 is scoped to comments.🤖 Generated with Claude Code