Skip to content

Commit

Permalink
proxy: imp err msg
Browse files Browse the repository at this point in the history
  • Loading branch information
schzhn committed Dec 18, 2023
1 parent 0f49b8b commit 6aef013
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions proxy/upstreams.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"golang.org/x/exp/slices"
)

const errWrongUpstreamSpecs errors.Error = "wrong upstream specification"

// UpstreamConfig is a wrapper for a list of default upstreams, a map of
// reserved domains and corresponding upstreams.
type UpstreamConfig struct {
Expand Down Expand Up @@ -119,7 +121,7 @@ var _ error = (*ParseError)(nil)

// Error implements the [error] interface for *ParseError.
func (e *ParseError) Error() (msg string) {
return fmt.Sprintf("index: %d: %s", e.Idx, e.err)
return fmt.Sprintf("parsing error at index %d: %s", e.Idx, e.err)
}

// type check
Expand Down Expand Up @@ -180,18 +182,18 @@ func (p *configParser) parse(conf []string) (c *UpstreamConfig, err error) {

// parseLine returns an error if upstream configuration line is invalid.
func (p *configParser) parseLine(idx int, confLine string) (err error) {
if len(confLine) == 0 || confLine[0] == '#' {
return nil
}

upstreams, domains, err := splitConfigLine(confLine)
if err != nil {
// Don't wrap the error since it's informative enough as is.
return err
}

if upstreams[0] == "#" {
if len(domains) > 0 {
p.excludeFromReserved(domains)

return nil
}
if upstreams[0] == "#" && len(domains) > 0 {
p.excludeFromReserved(domains)

return nil
}
Expand All @@ -217,7 +219,7 @@ func splitConfigLine(confLine string) (upstreams, domains []string, err error) {

domainsLine, upstreamsLine, found := strings.Cut(confLine[len("[/"):], "/]")
if !found || upstreamsLine == "" {
return nil, nil, fmt.Errorf("wrong upstream specification")
return nil, nil, errWrongUpstreamSpecs
}

// split domains list
Expand Down

0 comments on commit 6aef013

Please sign in to comment.