state: a state file without a section loads it empty (closes #267)
check / check (push) Canceled after 0s

Load fills in each of domains, hostnames, ports and certificates that
the file leaves out or holds as null with an empty map. Before, such a
section loaded as a nil map, and the first check's write into it
panicked, so a state file holding {} stopped the watcher at every
start.

The test loads {} and a file missing each section in turn, then saves
an entry in every section as the first check does; it does not run a
check, which would look names up in live DNS.

Model: opus-5-5
This commit is contained in:
2026-10-13 16:49:02 +00:00
parent 5617c92fb3
commit d6f6132951
4 changed files with 89 additions and 0 deletions
+18
View File
@@ -216,6 +216,24 @@ func (s *State) Load() error {
return fmt.Errorf("parsing state file: %w", err)
}
// A section the file leaves out, or holds as null, loads empty: the
// setters write into these maps, and writing into a nil map panics.
if snapshot.Domains == nil {
snapshot.Domains = make(map[string]*DomainState)
}
if snapshot.Hostnames == nil {
snapshot.Hostnames = make(map[string]*HostnameState)
}
if snapshot.Ports == nil {
snapshot.Ports = make(map[string]*PortState)
}
if snapshot.Certificates == nil {
snapshot.Certificates = make(map[string]*CertificateState)
}
// A state file saved before each record value was stored once can
// hold a hostname's CNAME once for every record type asked for.
// Each value is kept once, so the first check does not see a