JuliusBrussee/caveman · error

%s: %w

Error message

%s: %w

What it means

rootsWithCAFile wraps any error from cabundle.Pool when loading the CA-file env var's PEM bundle, prefixing it with the env var name. The bundle is loaded fail-closed: unreadable, malformed, or truncated PEM blocks abort configuration instead of silently degrading to the system pool.

Solutions

  1. Check the wrapped cabundle.Pool error (after the '%s: ' prefix) for the root cause: missing file, permission, or parse failure.
  2. Verify the path in the CA-file env var exists and is readable inside the container/host (ls -l, cat the first lines).
  3. Ensure the file is a valid PEM bundle (-----BEGIN CERTIFICATE----- blocks, complete, not DER).
  4. Re-deploy/remount the secret or configmap if the file is missing in the runtime environment.

Example fix

// before
CLICKHOUSE_CA_FILE=/etc/certs/internal-ca.crt   // file never mounted
// after
CLICKHOUSE_CA_FILE=/etc/certs/internal-ca.pem   // valid PEM bundle, mounted
// or in code, fail fast at boot:
if _, err := chhttp.ValidateProduction(logger); err != nil {
    logger.Error("clickhouse tls config invalid", "err", err)
    os.Exit(1)
}
Defensive patterns

Strategy: validation

Validate before calling

if path := strings.TrimSpace(os.Getenv("CLICKHOUSE_CA_FILE")); path != "" {
    if _, err := os.Stat(path); err != nil {
        return fmt.Errorf("CLICKHOUSE_CA_FILE unreadable: %w", err)
    }
}

Try / catch

if err := chhttp.ValidateProduction(logger); err != nil {
    if strings.Contains(err.Error(), caFileEnv) {
        logger.Error("CA bundle unusable — check path, mounting, and PEM validity", "err", err)
        os.Exit(1)
    }
    return err
}

Prevention

When it happens

Trigger: Calling tlsClientConfig (via client construction or ValidateProduction) with the CA-file env var set to a path that doesn't exist, isn't readable, or contains invalid/truncated PEM.

Common situations: Typo in the CA file path; the secret/configmap not mounted in the container; the bundle exported as DER instead of PEM; a truncated file from an interrupted copy; wrong file mounted at the expected path.

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 JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/50eb7c52cf4b4ad3. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/chhttp/chhttp.go:151

		// warned about by ValidateProduction at startup.
		InsecureSkipVerify: skipVerify,
	}
	if caFile != "" {
		roots, err := rootsWithCAFile(caFile)
		if err != nil {
			return nil, err
		}
		cfg.RootCAs = roots
	}
	return cfg, nil
}

// rootsWithCAFile returns the system pool with the PEM bundle at path appended,
// failing CLOSED on any unusable or truncated block (see cabundle.Pool).
func rootsWithCAFile(path string) (*x509.CertPool, error) {
	roots, err := cabundle.Pool(path)
	if err != nil {
		return nil, fmt.Errorf("%s: %w", caFileEnv, err)
	}
	return roots, nil
}

// errTransport fails every request with the configuration error that produced
// it. A client constructor cannot return an error, and falling back to the
// default transport would silently trade a rejected TLS configuration for
// unpinned verification — so the client is built, and refuses to send.
type errTransport struct{ err error }

func (t errTransport) RoundTrip(*http.Request) (*http.Response, error) { return nil, t.err }

// queryTransport is the shared connection pool behind ClickHouse query clients.
//
// http.DefaultTransport keeps only DefaultMaxIdleConnsPerHost (2) idle
// connections per host, so the 3rd+ concurrent ClickHouse read dials a fresh
// connection and throws it away on completion — paying a TCP + TLS handshake per
// query. Report handlers fan several queries out at once and production reads

View on GitHub (pinned to 3ee70a1026)