Skip to content

Commit 10d32da

Browse files
authored
chore!: remove deprecated MaxPartErrors global var (#353)
Signed-off-by: James Hillyerd <[email protected]>
1 parent e563ba5 commit 10d32da

File tree

4 files changed

+5
-65
lines changed

4 files changed

+5
-65
lines changed

error.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ const (
2727
ErrorMalformedChildPart = "Malformed child part"
2828
)
2929

30-
// MaxPartErrors limits number of part parsing errors, errors after the limit are ignored.
31-
// 0 means unlimited.
32-
//
33-
// Deprecated: This limit may be set via the `MaxStoredPartErrors` Parser option.
34-
var MaxPartErrors = 0
35-
3630
// Error describes an error encountered while parsing.
3731
type Error struct {
3832
Name string // The name or type of error encountered, from Error consts.
@@ -84,10 +78,10 @@ func (p *Part) addWarningf(name string, detailFmt string, args ...interface{}) {
8478

8579
// addProblem adds general *Error to the Part error slice.
8680
func (p *Part) addProblem(err *Error) {
87-
maxErrors := MaxPartErrors
88-
if p.parser != nil && p.parser.maxStoredPartErrors != nil {
81+
maxErrors := 0
82+
if p.parser != nil {
8983
// Override global var.
90-
maxErrors = *p.parser.maxStoredPartErrors
84+
maxErrors = p.parser.maxStoredPartErrors
9185
}
9286

9387
if (maxErrors == 0) || (len(p.Errors) < maxErrors) {

error_test.go

-53
Original file line numberDiff line numberDiff line change
@@ -133,53 +133,7 @@ func TestErrorEnvelopeWarnings(t *testing.T) {
133133
}
134134
}
135135

136-
// Deprecated.
137-
func TestErrorLimit(t *testing.T) {
138-
// Backup global variable
139-
originalMaxPartErros := MaxPartErrors
140-
defer func() {
141-
MaxPartErrors = originalMaxPartErros
142-
}()
143-
144-
addThreeErrors := func() int {
145-
part := NewPart("text/plain")
146-
part.addError("test1", "test1")
147-
part.addError("test2", "test2")
148-
part.addError("test3", "test3")
149-
150-
return len(part.Errors)
151-
}
152-
153-
// Check unlimited
154-
var errCount int
155-
MaxPartErrors = 0
156-
errCount = addThreeErrors()
157-
if errCount != 3 {
158-
t.Errorf("Expected unlimited errors (3), got %d", errCount)
159-
}
160-
161-
// Check limit
162-
MaxPartErrors = 1
163-
errCount = addThreeErrors()
164-
if errCount != 1 {
165-
t.Errorf("Expected limited errors (1), got %d", errCount)
166-
}
167-
168-
// Check limit matching count
169-
MaxPartErrors = 3
170-
errCount = addThreeErrors()
171-
if errCount != 3 {
172-
t.Errorf("Expected limited errors (3), got %d", errCount)
173-
}
174-
}
175-
176136
func TestErrorLimitOption(t *testing.T) {
177-
// Backup global variable
178-
originalMaxPartErros := MaxPartErrors
179-
defer func() {
180-
MaxPartErrors = originalMaxPartErros
181-
}()
182-
183137
addThreeErrors := func(parser *Parser) int {
184138
part := NewPart("text/plain")
185139
if parser != nil {
@@ -205,13 +159,6 @@ func TestErrorLimitOption(t *testing.T) {
205159
got = addThreeErrors(NewParser())
206160
assert.Equal(t, want, got, "expected unlimited errors")
207161

208-
// Check the default actually comes from deprecated MaxPartErrors global.
209-
want = 1
210-
MaxPartErrors = want
211-
got = addThreeErrors(nil)
212-
assert.Equal(t, want, got, "expected limited errors")
213-
MaxPartErrors = 0
214-
215162
// Check limit.
216163
want = 1
217164
got = addThreeErrors(NewParser(MaxStoredPartErrors(want)))

options.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ func MaxStoredPartErrors(n int) Option {
4848
type maxStoredPartErrorsOption int
4949

5050
func (o maxStoredPartErrorsOption) apply(p *Parser) {
51-
n := int(o)
52-
p.maxStoredPartErrors = &n
51+
p.maxStoredPartErrors = int(o)
5352
}
5453

5554
// RawContent if set to true will not try to decode the CTE and return the raw part content.

parser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type CustomParseMediaType func(ctype string) (mtype string, params map[string]st
1818

1919
// Parser parses MIME. Create with NewParser to inherit recommended defaults.
2020
type Parser struct {
21-
maxStoredPartErrors *int // TODO: Pointer until global var removed.
21+
maxStoredPartErrors int
2222
multipartWOBoundaryAsSinglePart bool
2323
readPartErrorPolicy ReadPartErrorPolicy
2424
skipMalformedParts bool

0 commit comments

Comments
 (0)