Commit 8eaf28b
authored
fix: best-effort fallback when slash line is invalid grammar (#217)
* test: add failing cases for best-effort malformed slash lines
ParseTask currently aborts the entire parse when a line starts with `/`
but isn't a valid slash command (e.g. `//`, lone `/`, `/=foo`). These
should fall through to text, preserving both the malformed line and any
surrounding content.
In-fence slashes are already handled by the markdown-aware path; only
the bare-text case is broken.
* fix: best-effort fallback when slash line is invalid grammar
A single malformed slash line (e.g. `//`, lone `/`, `/=foo`) outside a
fenced code block caused ParseTask to abort the entire task, silently
dropping the user prompt and frontmatter and corrupting downstream
runs.
On parser failure, parseGrammar now re-attempts line-by-line. Lines
that still fail are emitted as raw text with a WARN logged at
slog.Default. The whole-segment fast path is unchanged for valid input.
* feat: inject logger through markdown and taskparser parse APIs
Adds *WithLogger variants for the parse entry points so callers can route
taskparser's best-effort fallback WARN logs through their own slog.Logger
instead of slog.Default():
- taskparser.NewExtension(logger) (Extension stays as NewExtension(nil))
- taskparser.ParseTaskWithLogger(text, logger)
- markdown.ParseMarkdownFileWithLogger(path, fm, logger)
The original ParseTask/ParseMarkdownFile/Extension entry points are
preserved as nil-logger wrappers, so external callers are unaffected.
A nil logger resolves to slog.Default() at log time (via loggerOrDefault)
rather than being captured at construction, so slog.SetDefault changes
made after package load still take effect. A new test covers this.
All five ParseMarkdownFile callsites and the ParseTask callsite in
pkg/codingcontext/context.go now pass cc.logger.1 parent 4b1d82d commit 8eaf28b
5 files changed
Lines changed: 215 additions & 24 deletions
File tree
- pkg/codingcontext
- markdown
- taskparser
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
295 | | - | |
| 295 | + | |
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
389 | | - | |
| 389 | + | |
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
431 | | - | |
| 431 | + | |
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
| |||
549 | 549 | | |
550 | 550 | | |
551 | 551 | | |
552 | | - | |
| 552 | + | |
553 | 553 | | |
554 | 554 | | |
555 | 555 | | |
| |||
816 | 816 | | |
817 | 817 | | |
818 | 818 | | |
819 | | - | |
| 819 | + | |
820 | 820 | | |
821 | 821 | | |
822 | 822 | | |
| |||
1042 | 1042 | | |
1043 | 1043 | | |
1044 | 1044 | | |
1045 | | - | |
| 1045 | + | |
1046 | 1046 | | |
1047 | 1047 | | |
1048 | 1048 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| 72 | + | |
| 73 | + | |
71 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
72 | 82 | | |
73 | 83 | | |
74 | 84 | | |
| |||
77 | 87 | | |
78 | 88 | | |
79 | 89 | | |
80 | | - | |
| 90 | + | |
81 | 91 | | |
82 | | - | |
| 92 | + | |
83 | 93 | | |
84 | 94 | | |
85 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | | - | |
| 99 | + | |
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
105 | | - | |
| 106 | + | |
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
| |||
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
130 | | - | |
| 131 | + | |
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
| |||
149 | 150 | | |
150 | 151 | | |
151 | 152 | | |
152 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
153 | 158 | | |
154 | 159 | | |
155 | 160 | | |
156 | 161 | | |
157 | 162 | | |
158 | | - | |
159 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
160 | 176 | | |
161 | 177 | | |
162 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
163 | 210 | | |
164 | 211 | | |
165 | 212 | | |
| |||
176 | 223 | | |
177 | 224 | | |
178 | 225 | | |
| 226 | + | |
| 227 | + | |
179 | 228 | | |
180 | 229 | | |
181 | 230 | | |
| |||
185 | 234 | | |
186 | 235 | | |
187 | 236 | | |
188 | | - | |
| 237 | + | |
189 | 238 | | |
190 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
191 | 249 | | |
192 | 250 | | |
193 | 251 | | |
194 | 252 | | |
195 | | - | |
| 253 | + | |
196 | 254 | | |
197 | 255 | | |
198 | 256 | | |
| |||
225 | 283 | | |
226 | 284 | | |
227 | 285 | | |
228 | | - | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
229 | 289 | | |
230 | 290 | | |
231 | 291 | | |
| |||
265 | 325 | | |
266 | 326 | | |
267 | 327 | | |
268 | | - | |
| 328 | + | |
269 | 329 | | |
270 | 330 | | |
271 | 331 | | |
272 | 332 | | |
273 | 333 | | |
274 | | - | |
275 | | - | |
| 334 | + | |
| 335 | + | |
276 | 336 | | |
277 | 337 | | |
278 | | - | |
| 338 | + | |
279 | 339 | | |
280 | 340 | | |
281 | 341 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
114 | 122 | | |
115 | 123 | | |
116 | 124 | | |
117 | 125 | | |
118 | 126 | | |
119 | 127 | | |
120 | | - | |
| 128 | + | |
121 | 129 | | |
122 | 130 | | |
123 | 131 | | |
| |||
0 commit comments