gofr-dev/gofr · error
unsupported config file format
Error message
unsupported config file format
What it means
errUnsupportedFormat is returned by rbac.LoadPermissions when the RBAC permissions config file has an extension other than the supported .json, .yaml, or .yml. LoadPermissions detects the format via the file extension (strings.ToLower(filepath.Ext(path))) and refuses to parse anything else. This prevents silently mis-parsing config files with an unrecognized structure.
Source
Thrown at pkg/gofr/rbac/config.go:22
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
"path/filepath"
"strings"
"github.com/gorilla/mux"
"go.opentelemetry.io/otel/trace"
"gopkg.in/yaml.v3"
"gofr.dev/pkg/gofr/container"
"gofr.dev/pkg/gofr/datasource"
)
var (
// errUnsupportedFormat is returned when the config file format is not supported.
errUnsupportedFormat = errors.New("unsupported config file format")
// ErrEndpointMissingPermissions is returned when an endpoint doesn't specify requiredPermissions and is not public.
ErrEndpointMissingPermissions = errors.New("endpoint must specify requiredPermissions (or be public)")
// errWildcardPatternNotSupported is returned when a wildcard pattern is used.
errWildcardPatternNotSupported = errors.New("wildcard pattern '/*' is not supported, use mux patterns instead")
// errRegexPatternNotSupported is returned when an old regex pattern is used.
errRegexPatternNotSupported = errors.New("regex pattern '^...$' is not supported, use mux patterns instead")
// errRegexIndicatorNotSupported is returned when regex indicators are used outside variable constraints.
errRegexIndicatorNotSupported = errors.New("regex pattern is not supported, use mux patterns instead")
)
// RoleDefinition defines a role with its permissions and inheritance.
// Pure config-based: only role->permission mapping is supported.
type RoleDefinition struct {
// Name is the role name (required)View on GitHub (pinned to 187eb24962)
Solutions
- Convert the config file to JSON, YAML (.yaml), or YML (.yml).
- Rename the file to have the correct extension matching its actual content.
- If the file already IS JSON/YAML but misnamed, fix the extension — format detection is extension-based only.
Example fix
// before
roles, err := rbac.LoadPermissions("rbac.toml", logger, metrics, tracer)
// after
roles, err := rbac.LoadPermissions("rbac.yaml", logger, metrics, tracer) Defensive patterns
Strategy: validation
Validate before calling
func validateRBACPath(path string) error {
ext := strings.ToLower(filepath.Ext(path))
switch ext {
case ".json", ".yaml", ".yml":
return nil
default:
return fmt.Errorf("unsupported rbac config extension %q; use .json/.yaml/.yml", ext)
}
} Try / catch
cfg, err := rbac.LoadPermissions(path, logger, metrics, tracer)
if err != nil {
return fmt.Errorf("rbac config load failed: %w", err)
} Prevention
- Standardize on a single format (e.g. .yaml) across services.
- Add a CI check that all RBAC config files end in .json/.yaml/.yml.
- Never rename config files manually — re-export in a supported format.
- Document the format requirement next to where the path is configured.
When it happens
Trigger: Calling LoadPermissions(path, ...) or EnableRBAC with a file whose extension is e.g. .toml, .ini, .xml, .txt, or no extension.
Common situations: Teams exporting permissions from another tool as TOML/INI; config file renamed or copied without its extension; YAML file saved as .config; typo like permissons.ymlx.
Related errors
- validate func is empty
- endpoint must specify requiredPermissions (or be public)
- wildcard pattern '/*' is not supported, use mux patterns ins
- regex pattern '^...$' is not supported, use mux patterns ins
- regex pattern is not supported, use mux patterns instead
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/8ff63cd2ea9c8699.
Report an issue: GitHub.