Skip to content

Commit 4f9109c

Browse files
committed
remove ErrAlreadyExist
1 parent 986bd0c commit 4f9109c

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

configparser.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ var (
1818
interpolater = regexp.MustCompile(`%\(([^)]*)\)s`)
1919
)
2020

21-
var ErrAlreadyExist = errors.New("already exist")
22-
2321
var boolMapping = map[string]bool{
2422
"1": true,
2523
"true": true,
@@ -255,7 +253,7 @@ func (p *ConfigParser) ParseReader(in io.Reader) error {
255253
} else {
256254
// If key was defined, but current line does not start with any of the
257255
// multiline prefixes or it is an empty line which is not allowed within values,
258-
// then it counts as the value parsing is finished and it can be added
256+
// then it counts as the value parsing is finished and it can be added
259257
// to the current section.
260258
if err := curSect.Add(key, value); err != nil {
261259
return fmt.Errorf("failed to add %q = %q: %w", key, value, err)
@@ -279,7 +277,9 @@ func (p *ConfigParser) ParseReader(in io.Reader) error {
279277
curSect = newSection(section)
280278
p.config[section] = curSect
281279
} else if p.opt.strict {
282-
return fmt.Errorf("section %q error: %w", section, ErrAlreadyExist)
280+
return fmt.Errorf(
281+
"section %q already exists and strict flag was set", section,
282+
)
283283
}
284284

285285
// Since section was defined on current line, may continue.

methods.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ func (p *ConfigParser) inOptions(key string) error {
273273

274274
for _, o := range opts {
275275
if key == o {
276-
return fmt.Errorf("option %q error: %w", key, ErrAlreadyExist)
276+
return fmt.Errorf(
277+
"option %q already exists and strict flag was set",
278+
key,
279+
)
277280
}
278281
}
279282

options_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (s *ConfigParserSuite) TestStrictOptDuplicateSection(c *C) {
199199
)
200200

201201
c.Assert(err, NotNil)
202-
c.Assert(err.Error(), Equals, "section \"dubl\" error: already exist")
202+
c.Assert(err.Error(), Equals, "section \"dubl\" already exists and strict flag was set")
203203
}
204204

205205
// TestStrictOptDuplicateValue tests strict option with value duplicate.
@@ -210,7 +210,7 @@ func (s *ConfigParserSuite) TestStrictOptDuplicateValue(c *C) {
210210
)
211211

212212
c.Assert(err, NotNil)
213-
c.Assert(err.Error(), Equals, "option \"dubl\" error: already exist")
213+
c.Assert(err.Error(), Equals, "option \"dubl\" already exists and strict flag was set")
214214
}
215215

216216
// TestStrictOptDuplicateEmptyValue tests strict option with empty value duplicate.
@@ -222,7 +222,7 @@ func (s *ConfigParserSuite) TestStrictOptDuplicateEmptyValue(c *C) {
222222
)
223223

224224
c.Assert(err, NotNil)
225-
c.Assert(err.Error(), Equals, "option \"dubl\" error: already exist")
225+
c.Assert(err.Error(), Equals, "option \"dubl\" already exists and strict flag was set")
226226
}
227227

228228
// TestAllowEmptyLines tests empty lines as part of the value.

0 commit comments

Comments
 (0)