Skip to content

Commit a8e9f68

Browse files
authored
Add more error handling for unrecognized subdirectives in Caddyfile parsing (#80)
1 parent 6195ca6 commit a8e9f68

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

caddyfile.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ func parseCaddyfile(helper httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, e
4343
// key <string>
4444
// window <duration>
4545
// events <max_events>
46+
// match {
47+
// <matchers>
48+
// }
4649
// }
4750
// distributed {
4851
// read_interval <duration>
4952
// write_interval <duration>
5053
// purge_age <duration>
5154
// }
55+
// log_key
5256
// storage <module...>
5357
// jitter <percent>
5458
// sweep_interval <duration>
@@ -104,13 +108,17 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
104108
return d.Errf("invalid max events integer '%s': %v", d.Val(), err)
105109
}
106110
zone.MaxEvents = maxEvents
111+
107112
case "match":
108113
matcherSet, err := caddyhttp.ParseCaddyfileNestedMatcherSet(d)
109114
if err != nil {
110115
return d.Errf("failed to parse match: %w", err)
111116
}
112117

113118
zone.MatcherSetsRaw = append(zone.MatcherSetsRaw, matcherSet)
119+
120+
default:
121+
return d.Errf("unrecognized subdirective '%s'", d.Val())
114122
}
115123
}
116124
if zone.Window == 0 || zone.MaxEvents == 0 {
@@ -165,6 +173,9 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
165173
return d.Errf("invalid purge age '%s': %v", d.Val(), err)
166174
}
167175
h.Distributed.PurgeAge = caddy.Duration(age)
176+
177+
default:
178+
return d.Errf("unrecognized subdirective '%s'", d.Val())
168179
}
169180
}
170181

0 commit comments

Comments
 (0)