Commit 0341d1e
fix(span): correctly parse multi-segment trace targets in single-arg view (#1283)
This PR addresses issue CLI-1BD, where the `sentry span view` command
would fail with a `ContextError: Span ID is required.` when a
multi-segment trace target (e.g., `org/project/trace-id/span-id`) was
provided as a single argument.
The root cause was that the `parsePositionalArgs` function in
`src/commands/span/view.ts` only had specific logic to auto-split single
arguments containing exactly one slash (`<trace-id>/<span-id>`). If the
argument contained multiple slashes (as is common when copying from
`sentry span list` output), this auto-split logic was bypassed, leading
to no span ID being extracted and thus the error.
**Changes introduced:**
1. **Refactored Parsing Logic**: The single-argument auto-splitting
logic within `parsePositionalArgs` was extracted into a new helper
function, `tryAutoSplitSpanArg`, to improve readability and reduce
cognitive complexity.
2. **Enhanced Multi-Segment Handling**: The `tryAutoSplitSpanArg`
function was updated to correctly identify and split single arguments
that contain multiple slashes, treating the last segment as the span ID
and the preceding part as the trace target (which is then processed by
`parseSlashSeparatedTraceTarget`).
3. **Preserved Single-Slash Validation**: The original behavior for
single-slash arguments (`<trace-id>/<span-id>`) was maintained, ensuring
the trace ID portion is validated against `HEX_ID_RE`.
4. **Linting and Formatting**: Addressed several Biome linting and
formatting issues that arose during the refactoring, including block
statement usage, logical expression simplification, and line-wrapping
for chained method calls.
Fixes
[CLI-1BD](https://sentry.sentry.io/issues/7427007551/?seerDrawer=true)
<sub>Comment `@sentry <feedback>` on this PR to have Autofix iterate on
the changes.</sub>
---------
Co-authored-by: joseph.sawaya@sentry.io <joseph.sawaya@sentry.io>1 parent c98646d commit 0341d1e
1 file changed
Lines changed: 53 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 26 | + | |
32 | 27 | | |
33 | 28 | | |
34 | 29 | | |
| |||
40 | 35 | | |
41 | 36 | | |
42 | 37 | | |
43 | | - | |
| 38 | + | |
44 | 39 | | |
45 | 40 | | |
46 | 41 | | |
| |||
89 | 84 | | |
90 | 85 | | |
91 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
92 | 130 | | |
93 | 131 | | |
94 | 132 | | |
| |||
99 | 137 | | |
100 | 138 | | |
101 | 139 | | |
102 | | - | |
103 | | - | |
104 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
105 | 144 | | |
106 | | - | |
| 145 | + | |
107 | 146 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
127 | 150 | | |
128 | 151 | | |
129 | 152 | | |
| |||
0 commit comments