{"record":{"id":"f69e780eda57725f","repo":"caddyserver/caddy","slug":"invalid-host-in-address-v","errorCode":null,"errorMessage":"invalid host in address: %v","messagePattern":"invalid host in address: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/logging/netwriter.go","lineNumber":64,"sourceCode":"\tSoftStart bool `json:\"soft_start,omitempty\"`\n\n\taddr caddy.NetworkAddress\n}\n\n// CaddyModule returns the Caddy module information.\nfunc (NetWriter) CaddyModule() caddy.ModuleInfo {\n\treturn caddy.ModuleInfo{\n\t\tID:  \"caddy.logging.writers.net\",\n\t\tNew: func() caddy.Module { return new(NetWriter) },\n\t}\n}\n\n// Provision sets up the module.\nfunc (nw *NetWriter) Provision(ctx caddy.Context) error {\n\trepl := caddy.NewReplacer()\n\taddress, err := repl.ReplaceOrErr(nw.Address, true, true)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid host in address: %v\", err)\n\t}\n\n\tnw.addr, err = caddy.ParseNetworkAddress(address)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"parsing network address '%s': %v\", address, err)\n\t}\n\n\tif nw.addr.PortRangeSize() != 1 {\n\t\treturn fmt.Errorf(\"multiple ports not supported\")\n\t}\n\n\tif nw.DialTimeout < 0 {\n\t\treturn fmt.Errorf(\"timeout cannot be less than 0\")\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/logging/netwriter.go#L46-L82","documentation":"NetWriter.Provision runs the configured address through the replacer with ReplaceOrErr(..., true, true) before parsing; this error means a placeholder in the address (e.g. {$SYSLOG_URL}) was either unrecognized or evaluated to empty, so the address cannot be trusted for dialing.","triggerScenarios":"Configuring output net with an address containing a placeholder that is undefined at provisioning time, such as 'net {$LOG_HOST}:514}' when the environment variable is unset.","commonSituations":"Env-var placeholders not exported in the service unit; typos in placeholder names; running config in a context (different user, container) where the variable is absent.","solutions":["Export/define the environment variable or placeholder referenced in the net address","Replace the placeholder with a literal address to confirm the rest of the config works","For systemd deployments, add the variable under [Service] Environment= or EnvironmentFile="],"exampleFix":"# before\noutput net {$SYSLOG_HOST}:514 {\n} # SYSLOG_HOST unset\n\n# after\n# export SYSLOG_HOST=log.internal before starting caddy, or:\noutput net log.internal:514","handlingStrategy":"validation","validationCode":"if os.Getenv(\"SYSLOG_HOST\") == \"\" {\n    return fmt.Errorf(\"SYSLOG_HOST must be set for net output address\")\n}","typeGuard":null,"tryCatchPattern":"if err := nw.Provision(ctx); err != nil {\n    if strings.Contains(err.Error(), \"invalid host in address\") {\n        // a placeholder was unset/unknown: fix environment and reload\n    }\n    return err\n}","preventionTips":["Declare required env vars in systemd Environment= or EnvironmentFile=","Use {$VAR:default} fallback syntax in addresses"],"tags":["caddy","logging","network","placeholders"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}