Skip to content

fix(comment): convert plain text to ADF for v3 and surface field errors#38

Merged
pchuri merged 3 commits into
mainfrom
fix/comment-adf-v3
Jun 18, 2026
Merged

fix(comment): convert plain text to ADF for v3 and surface field errors#38
pchuri merged 3 commits into
mainfrom
fix/comment-adf-v3

Conversation

@pchuri

@pchuri pchuri commented Jun 18, 2026

Copy link
Copy Markdown
Owner

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:

  1. Plain text body rejected by v3. addComment/updateComment sent body: "plain string". The v3 endpoint requires Atlassian Document Format, so it returned 400 {"errors":{"comment":"Comment body is not valid!"}}.
  2. No v2 fallback on 400. shouldFallbackApiVersion() only triggers on 404/410, so the 400 was terminal — the CLI never retried against v2 (where plain text works).
  3. Empty error message. formatJiraErrorMessage() did data.errorMessages.join(', ') — but errorMessages was an empty array (truthy → '') and the structured errors object was ignored, so the user saw Failed to add comment: with nothing after it.

Fix (option 3 from the issue: ADF + safety-net fallback + error parsing)

  • Per-version body construction. Comment bodies are now built per API version — ADF for v3, plain text for v2 — via a dedicated 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 in searchUsers()).
  • Narrow v2 safety net. Fallback to v2 is triggered only by the specific "comment body invalid" 400 signature (isCommentBodyRejection), not all 400s — a generic 400 still surfaces as a real error rather than being masked by a double request.
  • Field-level error messages. extractErrorDetail() now reads the errors field map when errorMessages is empty, so validation failures show comment: 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 --file multi-line bodies).

Tests

  • Updated existing addComment/updateComment assertions to expect ADF on v3.
  • Added: v2-pinned plain text, v3→v2 fallback on the ADF-rejection 400, no-fallback on unrelated 400, and unit tests for toADF (single paragraph, blank-line split, hard breaks, empty input) and extractErrorDetail.
  • Full suite: 283 passing, lint clean.

Out of scope / follow-up

createIssue/updateIssue send description as 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

pchuri and others added 2 commits June 18, 2026 16:42
`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>
@pchuri pchuri merged commit 70375dd into main Jun 18, 2026
5 checks passed
@pchuri pchuri deleted the fix/comment-adf-v3 branch June 18, 2026 08:13
github-actions Bot pushed a commit that referenced this pull request Jun 18, 2026
## [2.8.1](v2.8.0...v2.8.1) (2026-06-18)

### Bug Fixes

* **comment:** convert plain text to ADF for v3 and surface field errors ([#38](#38)) ([70375dd](70375dd)), closes [#37](#37)
* **deps:** bump form-data override to 4.0.6 to resolve CRLF advisory ([#39](#39)) ([4bf04e8](4bf04e8))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.8.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] comment add fails silently on Jira Cloud (API v3) — plain text body rejected, fallback not triggered

1 participant