aboutsummaryrefslogtreecommitdiffhomepage
path: root/caddyconfig/caddyfile/parse.go
diff options
context:
space:
mode:
authorFrancis Lavoie <[email protected]>2021-08-23 13:53:27 -0400
committerGitHub <[email protected]>2021-08-23 11:53:27 -0600
commit51f125bd44be41d6220f0c134b6a402a85f80ad6 (patch)
tree04b4176525f303dbcc88866e47f687ffdef6c78b /caddyconfig/caddyfile/parse.go
parentd74913f871414ddac9a3884fc6aef4492ee4f65f (diff)
downloadcaddy-51f125bd44be41d6220f0c134b6a402a85f80ad6.tar.gz
caddy-51f125bd44be41d6220f0c134b6a402a85f80ad6.zip
caddyfile: Better error message for missing site block braces (#4301)
Some new users mistakenly try to define two sites without braces around each. Doing this can yield a confusing error message saying that their site address is an "unknown directive". We can do better by keeping track of whether the current site block was parsed with or without a brace, then changing the error message later based on that. For example, now this invalid config: ``` foo.example.com respond "foo" bar.example.com respond "bar" ``` Will yield this error message: ``` $ caddy adapt 2021/08/22 19:21:31.028 INFO using adjacent Caddyfile adapt: Caddyfile:4: unrecognized directive: bar.example.com Did you mean to define a second site? If so, you must use curly braces around each site to separate their configurations. ```
Diffstat (limited to 'caddyconfig/caddyfile/parse.go')
-rwxr-xr-xcaddyconfig/caddyfile/parse.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/caddyconfig/caddyfile/parse.go b/caddyconfig/caddyfile/parse.go
index 5906bdd9c..c0f607944 100755
--- a/caddyconfig/caddyfile/parse.go
+++ b/caddyconfig/caddyfile/parse.go
@@ -211,6 +211,12 @@ func (p *parser) addresses() error {
if expectingAnother {
return p.Errf("Expected another address but had '%s' - check for extra comma", tkn)
}
+ // Mark this server block as being defined with braces.
+ // This is used to provide a better error message when
+ // the user may have tried to define two server blocks
+ // without having used braces, which are required in
+ // that case.
+ p.block.HasBraces = true
break
}
@@ -571,8 +577,9 @@ func (p *parser) snippetTokens() ([]Token, error) {
// head of the server block with tokens, which are
// grouped by segments.
type ServerBlock struct {
- Keys []string
- Segments []Segment
+ HasBraces bool
+ Keys []string
+ Segments []Segment
}
// DispenseDirective returns a dispenser that contains