fix: add trace ID validation to trace view + UUID dash-stripping#375
Merged
fix: add trace ID validation to trace view + UUID dash-stripping#375
Conversation
Fix two related issues (CLI-7Z, CLI-4X) in `sentry trace view`: 1. Add missing `validateTraceId()` call in `parsePositionalArgs()` — the raw, unvalidated trace ID was going directly to the API, causing confusing "No trace found" errors for malformed input. Now matches the pattern used by `trace logs` and `log view`. 2. Add UUID dash-stripping in `validateHexId()` — when input matches UUID format (8-4-4-4-12 hex with dashes), dashes are automatically stripped and a warning is printed to stderr. This handles the common case of users copy-pasting trace IDs in UUID format (e.g., `ed29abc8-71c4-475b-9675-4655ef1a02d0`). Changes: - src/lib/hex-id.ts: Add UUID_DASH_RE regex and dash-stripping before validation in validateHexId() - src/commands/trace/view.ts: Add validateTraceId() at all 4 return paths in parsePositionalArgs(), with validateAndWarn() helper for UUID auto-correction warnings - Updated tests: hex-id (unit + property), trace-id (unit + property), trace view (unit, property, func)
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 104 passed | Total: 104 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 87.23%. Project has 4058 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 82.02% 82.03% +0.01%
==========================================
Files 140 140 —
Lines 22547 22588 +41
Branches 0 0 —
==========================================
+ Hits 18493 18530 +37
- Misses 4054 4058 +4
- Partials 0 0 —Generated by Codecov Action |
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.
Fix two related issues (CLI-7Z, CLI-4X) in
sentry trace view:Missing trace ID validation —
parsePositionalArgs()never calledvalidateTraceId(), so raw user input went directly to the API. Invalidformats produced confusing "No trace found" errors instead of clear
validation messages. Now matches the pattern used by
trace logs.UUID dash-stripping — users often copy trace IDs in UUID format
(e.g.,
ed29abc8-71c4-475b-9675-4655ef1a02d0).validateHexId()nowauto-strips dashes when the input matches the 8-4-4-4-12 UUID pattern
and logs a warning to stderr, following the project's auto-correct
convention.
Changes
src/lib/hex-id.ts: AddUUID_DASH_REregex and dash-stripping invalidateHexId()src/commands/trace/view.ts: AddvalidateTraceId()at all 4 returnpaths in
parsePositionalArgs()viavalidateAndWarn()helpertrace view (unit, property, func) — 123 tests pass
Fixes CLI-7Z
Fixes CLI-4X