Commit e1c176c
fix: use errors.Is() for wrapped context errors in tests
The ParseWithContext and ParseWithTimeout functions wrap context errors
(context.Canceled, context.DeadlineExceeded) in descriptive error messages
using fmt.Errorf with %w. This maintains the error chain but changes the
error identity.
Tests were using direct equality comparison (err != context.DeadlineExceeded)
which fails for wrapped errors. Updated all context error checks to use
errors.Is() which properly checks the error chain.
This fix resolves Windows Go 1.21 test failures where:
- Expected: context.DeadlineExceeded
- Got: 'tokenization failed: context deadline exceeded'
Changes:
- Import 'errors' package
- Replace 'err != context.DeadlineExceeded' with 'errors.Is(err, context.DeadlineExceeded)'
- Replace 'err != context.Canceled' with 'errors.Is(err, context.Canceled)'
- Replace 'err == context.DeadlineExceeded' with 'errors.Is(err, context.DeadlineExceeded)'
- Replace 'err == context.Canceled' with 'errors.Is(err, context.Canceled)'
Affected tests:
- TestParseWithContext_CancelledContext
- TestParseWithContext_Timeout
- TestParseWithTimeout_TimeoutExpires
- TestParseWithTimeout_ZeroTimeout
- TestParseWithContext_ErrorHandling
Fixes: Windows test failures in PR #94
Platform: Windows Go 1.21 (and all other Go versions)
Root Cause: Wrapped errors not being properly checked
Solution: Use errors.Is() for error chain inspection1 parent 45ccbbc commit e1c176c
1 file changed
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | | - | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
93 | | - | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
| |||
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
151 | | - | |
| 152 | + | |
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| |||
338 | 339 | | |
339 | 340 | | |
340 | 341 | | |
341 | | - | |
| 342 | + | |
342 | 343 | | |
343 | 344 | | |
344 | 345 | | |
| |||
430 | 431 | | |
431 | 432 | | |
432 | 433 | | |
433 | | - | |
| 434 | + | |
434 | 435 | | |
435 | 436 | | |
436 | 437 | | |
| |||
0 commit comments