|
1 | 1 | package handlers |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + stdctx "context" |
| 5 | + "errors" |
| 6 | + "io" |
4 | 7 | "os" |
5 | 8 | "strings" |
6 | 9 | "testing" |
@@ -117,3 +120,58 @@ func TestHandleFileLineNumbers(t *testing.T) { |
117 | 120 | assert.Equal(t, int64(11), results[1].LineNumber, "peek data should not be counted") |
118 | 121 | }) |
119 | 122 | } |
| 123 | + |
| 124 | +// TestDefaultHandler_ChunkErrorPreservesIdentity is a regression test for the |
| 125 | +// %v wrap at default.go:137. Before the fix, wrapping the inner chunk-reader |
| 126 | +// error with %v dropped its identity from the errors.Is chain, which caused |
| 127 | +// isFatal in handleChunksWithError to misclassify real per-chunk timeouts as |
| 128 | +// non-fatal warnings. The test asserts both that the outer ErrProcessingWarning |
| 129 | +// wrap is preserved (so warning-class consumers still see it) and that the |
| 130 | +// inner cause remains inspectable. |
| 131 | +func TestDefaultHandler_ChunkErrorPreservesIdentity(t *testing.T) { |
| 132 | + cases := []struct { |
| 133 | + name string |
| 134 | + innerErr error |
| 135 | + wantFatal bool |
| 136 | + }{ |
| 137 | + { |
| 138 | + name: "context.DeadlineExceeded is fatal", |
| 139 | + innerErr: stdctx.DeadlineExceeded, |
| 140 | + wantFatal: true, |
| 141 | + }, |
| 142 | + { |
| 143 | + name: "context.Canceled is fatal", |
| 144 | + innerErr: stdctx.Canceled, |
| 145 | + wantFatal: true, |
| 146 | + }, |
| 147 | + { |
| 148 | + name: "io.EOF is non-fatal", |
| 149 | + innerErr: io.EOF, |
| 150 | + wantFatal: false, |
| 151 | + }, |
| 152 | + } |
| 153 | + |
| 154 | + for _, tc := range cases { |
| 155 | + t.Run(tc.name, func(t *testing.T) { |
| 156 | + chunks := []sources.ChunkResult{sources.NewChunkResultError(tc.innerErr)} |
| 157 | + handler := newDefaultHandler(defaultHandlerType, withChunkReader(mockChunkReader(chunks))) |
| 158 | + reader, err := newFileReader(context.Background(), strings.NewReader("ignored")) |
| 159 | + require.NoError(t, err) |
| 160 | + |
| 161 | + var got []DataOrErr |
| 162 | + for dataOrErr := range handler.HandleFile(context.Background(), reader) { |
| 163 | + got = append(got, dataOrErr) |
| 164 | + } |
| 165 | + |
| 166 | + require.Len(t, got, 1) |
| 167 | + require.Error(t, got[0].Err) |
| 168 | + |
| 169 | + assert.True(t, errors.Is(got[0].Err, ErrProcessingWarning), |
| 170 | + "outer ErrProcessingWarning wrap should be preserved") |
| 171 | + assert.True(t, errors.Is(got[0].Err, tc.innerErr), |
| 172 | + "inner cause should be inspectable via errors.Is") |
| 173 | + assert.Equal(t, tc.wantFatal, isFatal(got[0].Err), |
| 174 | + "isFatal should classify based on the inner cause") |
| 175 | + }) |
| 176 | + } |
| 177 | +} |
0 commit comments