dapr/dapr · error
input key/keyPrefix '%s' can't contain '%s'
Error message
input key/keyPrefix '%s' can't contain '%s'
What it means
checkKeyIllegal in the lock building block rejects lock keys, keyPrefix metadata, and keyPrefixStrategy values that contain the Dapr key separator '||' (pkg/components/lock/lock_config.go:18). The lock store composes final store keys as prefix + '||' + lock name, so an embedded '||' would make stored keys ambiguous, and input is rejected before reaching the backend.
Source
Thrown at pkg/components/lock/lock_config.go:101
// Acquire a write lock now to update the value in cache
locksConfigurationMu.Lock()
defer locksConfigurationMu.Unlock()
// Try checking the cache again after acquiring a write lock, in case another goroutine has created the object
c = lockConfiguration[storeName]
if c != nil {
return c
}
c = &StoreConfiguration{keyPrefixStrategy: strategyDefault}
lockConfiguration[storeName] = c
return c
}
func checkKeyIllegal(key string) error {
if strings.Contains(key, separator) {
return fmt.Errorf("input key/keyPrefix '%s' can't contain '%s'", key, separator)
}
return nil
}
View on GitHub (pinned to 74ad417027)
Solutions
- Replace '||' in the lock name with '-', '_', or another delimiter.
- If the offending value is the keyPrefix or keyPrefixStrategy metadata in the component YAML, edit it and re-apply/restart.
- Sanitize composite keys at the application boundary (strip or encode '||') before calling the lock API.
Example fix
# before (lock component metadata) - name: keyPrefix value: "orders||prod" # after - name: keyPrefix value: "orders-prod"
Defensive patterns
Strategy: validation
Validate before calling
const lockSeparator = "||" // pkg/components/lock/lock_config.go:18
func validLockKey(key string) bool { return !strings.Contains(key, lockSeparator) }
// use before TryLock/UnLock and before setting keyPrefix metadata:
if !validLockKey(lockName) || !validLockKey(keyPrefix) {
return errors.New("lock name/prefix must not contain '||'")
} Try / catch
resp, err := lockClient.TryLock(ctx, &lock.TryLockRequest{StoreName: store, ResourceID: resID})
if err != nil {
if strings.Contains(err.Error(), "can't contain") {
// reject the caller's identifier early, do not retry
return http.Error(w, "lock name contains illegal separator '||'", http.StatusBadRequest)
}
return err
} Prevention
- Treat '||' as reserved: normalize application identifiers (replace with '-' or '_') before any Dapr call
- Add a unit test asserting generated lock names/prefixes never contain '||'
- Document the reserved separator for anyone composing keyPrefix metadata
When it happens
Trigger: Calling TryLock/UnLock with a lock name containing '||' (e.g. 'order||123'), or configuring the lock component's keyPrefix/keyPrefixStrategy metadata with '||' (e.g. 'my||app').
Common situations: Using '||' as a visual delimiter in prefixes; passing composite application identifiers that happen to embed the separator; migrating keys from another system that permitted '||'.
Related errors
- input key/keyPrefix '%s' can't contain '%s'
- invalid header key{trimmedName}
- app id is empty
- field Message is nil
- value for the dapr.io/app-id annotation is empty
AI-assisted analysis of dapr/dapr@74ad417027 (2026-08-16).
Data as JSON: /api/errors/e6dc2f90be1ee4d2.
Report an issue: GitHub.