coredns/coredns · error

failed to parse %q: %v

Error message

failed to parse %q: %v

What it means

When the autopath resolv-conf argument is not an @middleware reference, it is treated as a path to a resolv.conf file parsed with dns.ClientConfigFromFile. If that file cannot be read or parsed, the error wraps the underlying cause. This is typically a missing file or malformed resolv.conf.

Source

Thrown at plugin/autopath/setup.go:60

}

func autoPathParse(c *caddy.Controller) (*AutoPath, string, error) {
	ap := &AutoPath{}
	mw := ""

	for c.Next() {
		zoneAndresolv := c.RemainingArgs()
		if len(zoneAndresolv) < 1 {
			return ap, "", fmt.Errorf("no resolv-conf specified")
		}
		resolv := zoneAndresolv[len(zoneAndresolv)-1]
		if strings.HasPrefix(resolv, "@") {
			mw = resolv[1:]
		} else {
			// assume file on disk
			rc, err := dns.ClientConfigFromFile(resolv)
			if err != nil {
				return ap, "", fmt.Errorf("failed to parse %q: %v", resolv, err)
			}
			ap.search = rc.Search
			plugin.Zones(ap.search).Normalize()
			ap.search = append(ap.search, "") // sentinel value as demanded.
		}
		zones := zoneAndresolv[:len(zoneAndresolv)-1]
		ap.Zones = plugin.OriginsFromArgsOrServerBlock(zones, c.ServerBlockKeys)
	}
	return ap, mw, nil
}

View on GitHub (pinned to 558c9757a9)

Solutions

  1. Verify the path in `autopath <path>` points to an existing, readable resolv.conf file
  2. Fix syntax errors in the resolv.conf file (check the wrapped %v cause)
  3. Use `@kubernetes` style middleware reference instead of a file path if appropriate

Example fix

# before
autopath /etc/resolve.conf
# after
autopath /etc/resolv.conf
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(resolvPath); err != nil { return fmt.Errorf("resolv.conf not readable: %w", err) }

Try / catch

if err := runCoreDNS(); err != nil { if strings.Contains(err.Error(), "failed to parse") { log.Fatalf("check autopath resolv.conf path/syntax: %v", err) } }

Prevention

When it happens

Trigger: autoPathParse calls dns.ClientConfigFromFile(resolv) and it returns an error — file does not exist, unreadable permissions, or invalid resolv.conf syntax.

Common situations: Typo in the resolv.conf path in the Corefile; running in a container where /etc/resolv.conf is absent; malformed resolv.conf (bad nameserver line).

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of coredns/coredns@558c9757a9 (2026-09-06). Data as JSON: /api/errors/d6fc2405dea3aac3. Report an issue: GitHub.