Warden

Errors

Sentinel errors returned by Warden operations.

Warden defines sentinel errors for all failure cases. Use errors.Is() to check for specific errors.

Store Errors

ErrorDescription
ErrNotFoundEntity not found in store
ErrAlreadyExistsEntity with same unique key already exists
ErrStoreUnavailableStore backend is not reachable
ErrMigrationFailedDatabase migration failed

Authorization Errors

ErrorDescription
ErrAccessDeniedAuthorization check returned deny
ErrMissingSubjectCheck request has no subject
ErrMissingActionCheck request has no action
ErrMissingResourceCheck request has no resource type

Tenant Errors

ErrorDescription
ErrMissingTenantNo tenant ID in context
ErrMissingAppIDNo app ID in context

Entity Errors

ErrorDescription
ErrInvalidIDTypeID is malformed or has wrong prefix
ErrInvalidEffectPolicy effect is not "allow" or "deny"
ErrMaxDepthReachedReBAC graph traversal exceeded max depth
ErrCycleDetectedReBAC graph contains a cycle

Usage

import "github.com/xraph/warden"

err := store.GetRole(ctx, roleID)
if errors.Is(err, warden.ErrNotFound) {
    // Role doesn't exist
}

result, err := eng.Check(ctx, req)
if errors.Is(err, warden.ErrMissingTenant) {
    // Forgot to set tenant context
}

HTTP Error Mapping

When using the REST API, errors are mapped to HTTP status codes:

ErrorHTTP Status
ErrNotFound404 Not Found
ErrAlreadyExists409 Conflict
ErrAccessDenied403 Forbidden
ErrMissingSubject/Action/Resource400 Bad Request
ErrMissingTenant400 Bad Request
ErrInvalidID400 Bad Request
ErrStoreUnavailable503 Service Unavailable

On this page