Browse Source

Fix error handling with Validate when loading modules (fixes #2658)

The return statement was improperly nested in context.go
master
Matthew Holt 6 years ago
parent
commit
42acdad9e5
No known key found for this signature in database GPG Key ID: 2A349DD577D586A5
  1. 2
      context.go
  2. 10
      modules/caddyhttp/caddyhttp.go
  3. 8
      modules/caddyhttp/fileserver/staticfiles.go

2
context.go

@ -138,8 +138,8 @@ func (ctx Context) LoadModule(name string, rawMsg json.RawMessage) (interface{},
if err2 != nil { if err2 != nil {
err = fmt.Errorf("%v; additionally, cleanup: %v", err, err2) err = fmt.Errorf("%v; additionally, cleanup: %v", err, err2)
} }
return nil, fmt.Errorf("%s: invalid configuration: %v", mod.Name, err)
} }
return nil, fmt.Errorf("%s: invalid configuration: %v", mod.Name, err)
} }
} }

10
modules/caddyhttp/caddyhttp.go

@ -102,7 +102,7 @@ func (app *App) Validate() error {
} }
for _, a := range expanded { for _, a := range expanded {
if sn, ok := lnAddrs[netw+a]; ok { if sn, ok := lnAddrs[netw+a]; ok {
return fmt.Errorf("listener address repeated: %s (already claimed by server '%s')", a, sn) return fmt.Errorf("server %s: listener address repeated: %s (already claimed by server '%s')", srvName, a, sn)
} }
lnAddrs[netw+a] = srvName lnAddrs[netw+a] = srvName
} }
@ -486,5 +486,9 @@ const (
DefaultHTTPSPort = 443 DefaultHTTPSPort = 443
) )
// Interface guard // Interface guards
var _ caddy.App = (*App)(nil) var (
_ caddy.App = (*App)(nil)
_ caddy.Provisioner = (*App)(nil)
_ caddy.Validator = (*App)(nil)
)

8
modules/caddyhttp/fileserver/staticfiles.go

@ -450,5 +450,9 @@ var defaultIndexNames = []string{"index.html"}
const minBackoff, maxBackoff = 2, 5 const minBackoff, maxBackoff = 2, 5
// Interface guard // Interface guards
var _ caddyhttp.Handler = (*FileServer)(nil) var (
_ caddy.Provisioner = (*FileServer)(nil)
_ caddy.Validator = (*FileServer)(nil)
_ caddyhttp.Handler = (*FileServer)(nil)
)

Loading…
Cancel
Save