gofr-dev/gofr · critical
%w : %v
Error message
%w : %v
What it means
At pkg/gofr/http_server.go:152, validateCertificateAndKeyFiles returns fmt.Errorf("%w : %v", errInvalidCertificateFile, certificateFile) when os.Stat on the certificate file reports it does not exist. The wrapped error preserves the sentinel for errors.Is checks while appending the offending path for diagnosis.
Solutions
- Stat/ls the exact path printed in the error message to confirm it is missing
- Correct the certificate path in config/env to an existing absolute path
- Ensure cert provisioning (cert-manager, secret mount, CI step) runs before the service starts
- Run the service from a working directory where relative cert paths resolve, or switch to absolute paths
Example fix
// before
certFile := "certs/server.crt" // relative; CWD differs in prod
// after
certFile := "/etc/gofr/tls/server.crt" // absolute, verified with os.Stat
if _, err := os.Stat(certFile); err != nil { log.Fatalf("missing cert: %v", err) } Defensive patterns
Strategy: validation
Validate before calling
if _, err := os.Stat(certPath); os.IsNotExist(err) {
return fmt.Errorf("certificate not found at %s", certPath)
}
if _, err := os.Stat(keyPath); os.IsNotExist(err) {
return fmt.Errorf("key not found at %s", keyPath)
} Type guard
func isCertFileMissing(err error) bool {
return errors.Is(err, errInvalidCertificateFile)
} Try / catch
if err := validateCertificateAndKeyFiles(cert, key); err != nil {
if errors.Is(err, errInvalidCertificateFile) {
// message suffix holds the offending path
log.Fatalf("certificate file missing: %v", err)
}
return err
} Prevention
- Call validateCertificateAndKeyFiles (or your own Stat check) before run()
- Prefer absolute cert paths; log os.Getwd() to debug relative paths
- Gate deployment on cert provisioning jobs completing successfully
- Keep per-environment TLS paths in config, not hardcoded
When it happens
Trigger: os.Stat(certificateFile) returns an error satisfying os.IsNotExist during server startup (run() calls validateCertificateAndKeyFiles); the formatted error names the exact missing path.
Common situations: Deploying to a fresh environment where cert provisioning step was skipped; wrong working directory making relative paths invalid; config drift between environments (staging paths hardcoded in prod).
Related errors
- invalid certificate file
- invalid key file
- failed to append CA certificate
- failed to read CA certificate from
- azure config is nil
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/6754f48abfdb5edf.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/gofr/http_server.go:152
func (s *httpServer) Shutdown(ctx context.Context) error {
s.srvMu.Lock()
srv := s.srv
s.srvMu.Unlock()
if srv == nil {
return nil
}
return ShutdownWithContext(ctx, func(ctx context.Context) error {
return srv.Shutdown(ctx)
}, func() error {
return srv.Close()
})
}
func validateCertificateAndKeyFiles(certificateFile, keyFile string) error {
if _, err := os.Stat(certificateFile); os.IsNotExist(err) {
return fmt.Errorf("%w : %v", errInvalidCertificateFile, certificateFile)
}
if _, err := os.Stat(keyFile); os.IsNotExist(err) {
return fmt.Errorf("%w : %v", errInvalidKeyFile, keyFile)
}
return nil
}
View on GitHub (pinned to 187eb24962)