mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-02 06:07:21 +01:00
caddyfile: Adjust error formatting (#5765)
This commit is contained in:
parent
84d5e1c5d6
commit
38a7b6b3d0
2 changed files with 12 additions and 9 deletions
|
@ -391,22 +391,22 @@ func (d *Dispenser) Reset() {
|
||||||
// an argument.
|
// an argument.
|
||||||
func (d *Dispenser) ArgErr() error {
|
func (d *Dispenser) ArgErr() error {
|
||||||
if d.Val() == "{" {
|
if d.Val() == "{" {
|
||||||
return d.Err("Unexpected token '{', expecting argument")
|
return d.Err("unexpected token '{', expecting argument")
|
||||||
}
|
}
|
||||||
return d.Errf("Wrong argument count or unexpected line ending after '%s'", d.Val())
|
return d.Errf("wrong argument count or unexpected line ending after '%s'", d.Val())
|
||||||
}
|
}
|
||||||
|
|
||||||
// SyntaxErr creates a generic syntax error which explains what was
|
// SyntaxErr creates a generic syntax error which explains what was
|
||||||
// found and what was expected.
|
// found and what was expected.
|
||||||
func (d *Dispenser) SyntaxErr(expected string) error {
|
func (d *Dispenser) SyntaxErr(expected string) error {
|
||||||
msg := fmt.Sprintf("%s:%d - Syntax error: Unexpected token '%s', expecting '%s', import chain: ['%s']", d.File(), d.Line(), d.Val(), expected, strings.Join(d.Token().imports, "','"))
|
msg := fmt.Sprintf("syntax error: unexpected token '%s', expecting '%s', at %s:%d import chain: ['%s']", d.Val(), expected, d.File(), d.Line(), strings.Join(d.Token().imports, "','"))
|
||||||
return errors.New(msg)
|
return errors.New(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EOFErr returns an error indicating that the dispenser reached
|
// EOFErr returns an error indicating that the dispenser reached
|
||||||
// the end of the input when searching for the next token.
|
// the end of the input when searching for the next token.
|
||||||
func (d *Dispenser) EOFErr() error {
|
func (d *Dispenser) EOFErr() error {
|
||||||
return d.Errf("Unexpected EOF")
|
return d.Errf("unexpected EOF")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Err generates a custom parse-time error with a message of msg.
|
// Err generates a custom parse-time error with a message of msg.
|
||||||
|
@ -421,7 +421,10 @@ func (d *Dispenser) Errf(format string, args ...any) error {
|
||||||
|
|
||||||
// WrapErr takes an existing error and adds the Caddyfile file and line number.
|
// WrapErr takes an existing error and adds the Caddyfile file and line number.
|
||||||
func (d *Dispenser) WrapErr(err error) error {
|
func (d *Dispenser) WrapErr(err error) error {
|
||||||
return fmt.Errorf("%s:%d - Error during parsing: %w, import chain: ['%s']", d.File(), d.Line(), err, strings.Join(d.Token().imports, "','"))
|
if len(d.Token().imports) > 0 {
|
||||||
|
return fmt.Errorf("%w, at %s:%d import chain ['%s']", err, d.File(), d.Line(), strings.Join(d.Token().imports, "','"))
|
||||||
|
}
|
||||||
|
return fmt.Errorf("%w, at %s:%d", err, d.File(), d.Line())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete deletes the current token and returns the updated slice
|
// Delete deletes the current token and returns the updated slice
|
||||||
|
|
|
@ -181,17 +181,17 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
|
||||||
case "protocols":
|
case "protocols":
|
||||||
args := h.RemainingArgs()
|
args := h.RemainingArgs()
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return nil, h.SyntaxErr("one or two protocols")
|
return nil, h.Errf("protocols requires one or two arguments")
|
||||||
}
|
}
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
if _, ok := caddytls.SupportedProtocols[args[0]]; !ok {
|
if _, ok := caddytls.SupportedProtocols[args[0]]; !ok {
|
||||||
return nil, h.Errf("Wrong protocol name or protocol not supported: '%s'", args[0])
|
return nil, h.Errf("wrong protocol name or protocol not supported: '%s'", args[0])
|
||||||
}
|
}
|
||||||
cp.ProtocolMin = args[0]
|
cp.ProtocolMin = args[0]
|
||||||
}
|
}
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
if _, ok := caddytls.SupportedProtocols[args[1]]; !ok {
|
if _, ok := caddytls.SupportedProtocols[args[1]]; !ok {
|
||||||
return nil, h.Errf("Wrong protocol name or protocol not supported: '%s'", args[1])
|
return nil, h.Errf("wrong protocol name or protocol not supported: '%s'", args[1])
|
||||||
}
|
}
|
||||||
cp.ProtocolMax = args[1]
|
cp.ProtocolMax = args[1]
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
|
||||||
case "ciphers":
|
case "ciphers":
|
||||||
for h.NextArg() {
|
for h.NextArg() {
|
||||||
if !caddytls.CipherSuiteNameSupported(h.Val()) {
|
if !caddytls.CipherSuiteNameSupported(h.Val()) {
|
||||||
return nil, h.Errf("Wrong cipher suite name or cipher suite not supported: '%s'", h.Val())
|
return nil, h.Errf("wrong cipher suite name or cipher suite not supported: '%s'", h.Val())
|
||||||
}
|
}
|
||||||
cp.CipherSuites = append(cp.CipherSuites, h.Val())
|
cp.CipherSuites = append(cp.CipherSuites, h.Val())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue