Skip to content

fix(init): match formatError priority order for WizardError message#981

Merged
betegon merged 1 commit into
mainfrom
fix/init-wizard-error-message-priority
May 19, 2026
Merged

fix(init): match formatError priority order for WizardError message#981
betegon merged 1 commit into
mainfrom
fix/init-wizard-error-message-priority

Conversation

@betegon
Copy link
Copy Markdown
Member

@betegon betegon commented May 19, 2026

Summary

The squash merge for #980 captured the first 3 commits but missed the priority-order fix that came in as a follow-up from a bot review. Main currently has result.result?.message ?? result.error but formatError (which writes to the terminal) uses the opposite: result.error ?? inner?.message. This makes the terminal output and the Sentry exception message inconsistent when both fields are set.

Changes

One-line fix in handleFinalResult (wizard-runner.ts): swap the operands so the Sentry message uses result.error ?? result.result?.message, matching formatError exactly.

In practice the two fields are mutually exclusive (structured bails populate result.result.message; Mastra framework failures populate result.error), so there's no user-visible behaviour change — just consistency between what the terminal shows and what Sentry captures.

Test Plan

Existing tests in wizard-runner-handle-final-result.mocked.test.ts cover both the result.error and result.result.message paths and pass unchanged.

result.error (Mastra framework failure) takes precedence over
result.result?.message (structured bail message), consistent with
what formatError already shows in the terminal. In practice the
two fields are mutually exclusive, so no behavior changes.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@betegon betegon marked this pull request as ready for review May 19, 2026 13:50
@github-actions
Copy link
Copy Markdown
Contributor

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-981/

Built to branch gh-pages at 2026-05-19 13:50 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@betegon betegon enabled auto-merge (squash) May 19, 2026 13:50
@github-actions
Copy link
Copy Markdown
Contributor

Codecov Results 📊

6994 passed | Total: 6994 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 14211 uncovered lines.
❌ Project coverage is 77.03%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    77.06%    77.03%    -0.03%
==========================================
  Files          320       320         —
  Lines        61852     61876       +24
  Branches         0         0         —
==========================================
+ Hits         47664     47665        +1
- Misses       14188     14211       +23
- Partials         0         0         —

Generated by Codecov Action

@betegon betegon merged commit 362b813 into main May 19, 2026
28 checks passed
@betegon betegon deleted the fix/init-wizard-error-message-priority branch May 19, 2026 13:56
BYK added a commit that referenced this pull request May 23, 2026
…1015)

## Summary

Enhance `sentry local` for the agent monitoring launch with OTel
semantic attribute rendering, JSON output, SSE reconnection, and several
quality improvements.

### OTel Semantic Display

Port `trace-semantic-display` from sentry-mcp ([PR
#981](getsentry/sentry-mcp#981)) to enrich tail
output with OTel semantic attribute rendering. Transactions with GenAI,
MCP, HTTP, database, and other OTel attributes now show rich labels:

```
[gen_ai] chat anthropic/claude-4-sonnet [1200ms] [5 spans]
[mcp] tools/call search_files [320ms]
[db] SELECT users [postgresql] [12ms]
```

Covers 15 attribute families: GenAI, MCP, HTTP, database, GraphQL,
RPC/cloud, messaging, FaaS, object stores, CloudEvents, CICD, feature
flags, process, exception, and error types. Falls back to existing
behavior when no semantic attributes are present.

### `--format json` (NDJSON)

New `--format json` / `-F json` flag for machine-readable output. Each
envelope item produces one JSON line with structured fields including
semantic labels, stack frames, and source detection:

```json
{"type":"transaction","op":"gen_ai","label":"chat anthropic/claude-4-sonnet","duration_ms":1200,"source":"server"}
{"type":"error","error_type":"TypeError","message":"x is not a function","filename":"app.ts","lineno":42,"source":"server"}
```

### `--filter ai`

New filter value that matches transactions with GenAI or MCP OTel
attributes, so you can focus on agent activity: `sentry local -f ai`

### SSE Reconnection

The SSE consumer now reconnects automatically with exponential backoff
on connection loss, using `Last-Event-ID` to resume from where the
stream left off. Retry counter resets after successful reconnection.
Transient HTTP errors after a previous successful session are retried
rather than treated as fatal.

### Quality Improvements

- **Signal handler leak fixed** in `run.ts` — named handler refs,
cleanup in `finally`, settled flag for close/error race
- **`parsePort` deduplicated** — single implementation exported from
`server.ts`
- **`SENTRY_TRACES_SAMPLE_RATE`** preserved when already set (uses `??`
fallback)
- **Startup banner** with ingest URL, SSE endpoint, and connection hints
- **Agent monitoring docs** with GenAI/MCP examples and JSON output
section

## Files Changed

| File | Change |
|------|--------|
| `src/lib/formatters/semantic-display.ts` | **New** — OTel semantic
attribute rendering (15 families) |
| `src/lib/formatters/local.ts` | Semantic display integration, JSON
formatters, `--filter ai`, `inferSourceName` |
| `src/commands/local/server.ts` | SSE reconnection, `--format json`,
`--filter ai`, `parsePort` export, `feedSSELine` id tracking, startup
banner |
| `src/commands/local/run.ts` | Signal handler fix, `parsePort` import,
env var preservation |
| `docs/src/fragments/commands/local.md` | Agent monitoring section,
JSON output section |
| `test/lib/formatters/semantic-display.test.ts` | **New** — 70+ tests
for all semantic formatters |
| `test/lib/formatters/local.test.ts` | AI transaction tests, JSON
format tests |
| `test/commands/local/server.test.ts` | **New** — parsePort,
feedSSELine, buildApp, CORS, isServerRunning |
| `test/commands/local/run.test.ts` | Expanded — ENOENT, env
preservation, separator handling |

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

1 participant