gofr-dev/gofr · error
unsupported config file format: %s (supported: .json, .yaml,
Error message
unsupported config file format: %s (supported: .json, .yaml, .yml): %w
What it means
LoadPermissions only supports .json, .yaml, and .yml config files (extension-less files are treated as JSON). Any other extension — .toml, .conf, .txt, .xml — is rejected with errUnsupportedFormat and the RBAC config is not loaded.
Source
Thrown at pkg/gofr/rbac/config.go:154
if err != nil {
return nil, fmt.Errorf("failed to read RBAC config file %s: %w", path, err)
}
var config Config
// Detect file format by extension
ext := strings.ToLower(filepath.Ext(path))
switch ext {
case ".yaml", ".yml":
if err := yaml.Unmarshal(data, &config); err != nil {
return nil, fmt.Errorf("failed to parse YAML config file %s: %w", path, err)
}
case ".json", "":
if err := json.Unmarshal(data, &config); err != nil {
return nil, fmt.Errorf("failed to parse JSON config file %s: %w", path, err)
}
default:
return nil, fmt.Errorf("unsupported config file format: %s (supported: .json, .yaml, .yml): %w", ext, errUnsupportedFormat)
}
// Set dependencies
config.Logger = logger
config.Metrics = metrics
config.Tracer = tracer
// Initialize mux router for pattern matching
// Use StrictSlash(false) to match the application router's behavior
config.muxRouter = mux.NewRouter().StrictSlash(false)
// Validate config before processing
if err := config.validate(); err != nil {
return nil, fmt.Errorf("invalid RBAC config: %w", err)
}
// Process unified config to build internal maps
if err := config.processUnifiedConfig(); err != nil {View on GitHub (pinned to 187eb24962)
Solutions
- Rename the config file to one of the supported extensions (.json, .yaml, .yml).
- Convert unsupported formats (TOML/INI/XML) to JSON or YAML.
- If the file is intentionally extension-less, ensure its content is valid JSON since "" falls into the JSON branch.
Example fix
// before
config, err := rbac.LoadPermissions("configs/rbac.toml", ...)
// after
config, err := rbac.LoadPermissions("configs/rbac.yaml", ...) Defensive patterns
Strategy: validation
Validate before calling
ext := strings.ToLower(filepath.Ext(path))
switch ext {
case ".json", "", ".yaml", ".yml":
// ok
default:
return fmt.Errorf("config %s has unsupported extension %q; use .json/.yaml/.yml", path, ext)
} Try / catch
config, err := rbac.LoadPermissions(path, logger, metrics, tracer)
if err != nil && strings.Contains(err.Error(), "unsupported config file format") {
logger.Fatalf("rename %s to .json/.yaml/.yml", path)
} Prevention
- Standardize on a single supported extension (e.g. .yaml) in your repo.
- Check the extension in a startup preflight before calling EnableRBAC.
- Watch for deploy-time renames (.bak, timestamped suffixes).
When it happens
Trigger: Passing EnableRBAC/LoadPermissions a path ending in an extension outside {.json, .yaml, .yml}, e.g. /etc/app/rbac.toml or rbac.config.
Common situations: Reusing an existing TOML/INI config; a deployment renamed the file to .bak or added a timestamp suffix; writing config as .yml.txt due to editor auto-extension.
Related errors
- failed to parse YAML config file %s: %w
- failed to parse JSON config file %s: %w
- invalid RBAC config: %w
- failed to process unified config: %w
- endpoint[%d]: %w: %s
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/82bfaa05f6d10d3a.
Report an issue: GitHub.