gofr-dev/gofr · error

failed to process unified config

Error message

failed to process unified config: %w

What it means

The parsed RBAC config passed validation but processUnifiedConfig failed while converting the unified config into the internal role/permission maps. The internal error is wrapped and typically indicates inconsistent references between roles, permissions, or endpoints.

Solutions

  1. Inspect the wrapped inner error for the specific inconsistent entry.
  2. Verify every role/permission referenced by endpoints is defined in the config.
  3. Diff a previously working config against the current one to spot renamed or removed definitions.
  4. Reduce the config to a minimal working set and add entries back until the failure reappears.

Example fix

// before: endpoint references undefined role
{ "path": "/api/admin", "roles": ["superadmin"] } // 'superadmin' not defined
// after: define the role first
{ "roles": { "superadmin": ["*"] }, "endpoints": [{ "path": "/api/admin", "roles": ["superadmin"] }] }
Defensive patterns

Strategy: validation

Validate before calling

defined := map[string]bool{}
for _, r := range cfg.Roles { defined[r.Name] = true }
for i, ep := range cfg.Endpoints {
    for _, role := range ep.Roles {
        if !defined[role] {
            return fmt.Errorf("endpoint[%d] %s references undefined role %q", i, ep.Path, role)
        }
    }
}

Try / catch

if _, err := rbac.LoadPermissions(path, logger, metrics, tracer); err != nil {
    if strings.Contains(err.Error(), "failed to process unified config") {
        return fmt.Errorf("unified config references are inconsistent: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: EnableRBAC/LoadPermissions with a unified config whose roles/permission references are inconsistent (e.g. an endpoint or role referencing a permission that cannot be resolved while building internal maps).

Common situations: Renaming a role in one place but not another; typos in permission identifiers; a config merged from multiple sources where cross-references broke.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/95877c5c64962b69. Report an issue: GitHub.

Appendix: source

Thrown at pkg/gofr/rbac/config.go:173

	}

	// 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 {
		return nil, fmt.Errorf("failed to process unified config: %w", err)
	}

	return &config, nil
}

// validate validates the RBAC configuration.
func (c *Config) validate() error {
	// Validate endpoints: non-public endpoints must have RequiredPermissions
	// Also validate that paths use mux patterns only (no wildcards or old regex)
	for i, endpoint := range c.Endpoints {
		if !endpoint.Public && len(endpoint.RequiredPermissions) == 0 {
			return fmt.Errorf("endpoint[%d]: %w: %s", i, ErrEndpointMissingPermissions, endpoint.Path)
		}

		// Validate path pattern
		if err := c.validateEndpointPath(endpoint.Path, i); err != nil {
			return err
		}

View on GitHub (pinned to 187eb24962)