Shield

Error Handling

Sentinel errors returned by Shield operations.

Shield defines sentinel errors in the root shield package. All errors are created with errors.New and can be checked with errors.Is.

Store errors

ErrorDescription
ErrNoStoreNo store was configured on the engine
ErrStoreClosedThe store has been closed
ErrMigrateFailedDatabase migration failed

Not-found errors

ErrorDescription
ErrScanNotFoundScan result with the given ID does not exist
ErrPolicyNotFoundPolicy with the given ID does not exist
ErrInstinctNotFoundInstinct with the given ID does not exist
ErrJudgmentNotFoundJudgment with the given ID does not exist
ErrAwarenessNotFoundAwareness detector with the given ID does not exist
ErrValueNotFoundValue with the given ID does not exist
ErrReflexNotFoundReflex with the given ID does not exist
ErrBoundaryNotFoundBoundary with the given ID does not exist
ErrProfileNotFoundSafety profile with the given ID does not exist
ErrPIITokenNotFoundPII token with the given ID does not exist
ErrComplianceNotFoundCompliance report with the given ID does not exist

Conflict errors

ErrorDescription
ErrAlreadyExistsA resource with the same name already exists

Scan errors

ErrorDescription
ErrInputBlockedInput content was blocked by safety scan
ErrOutputBlockedOutput content was blocked by safety scan

Engine errors

ErrorDescription
ErrNoProfileNo safety profile configured for the scan
ErrInvalidConfigInvalid engine configuration

PII errors

ErrorDescription
ErrEncryptionKeyMissingPII encryption key not configured

State errors

ErrorDescription
ErrInvalidStateInvalid state transition

Error wrapping

Store implementations wrap these sentinel errors with additional context:

return fmt.Errorf("postgres: get scan %s: %w", scanID, shield.ErrScanNotFound)

Check errors using errors.Is:

result, err := eng.GetScan(ctx, scanID)
if errors.Is(err, shield.ErrScanNotFound) {
    // handle not found
}

On this page