Skip to main content

Errors

Every error the library throws is an AnonymaError with a machine-readable code. The classes are exported from anonyma, including those thrown by the other entry points:

ClassThrown when
ValidationErrorAn argument or option is invalid
UnsupportedStrategyErrorA rule names a strategy that does not exist
UnknownCategoryErrorA rule names a category that does not exist
PresetNotFoundErrorA preset name is unknown
AsyncStrategyErrortransform() meets a strategy that needs transformAsync()
CryptoNotAvailableErrorThe runtime has no Web Crypto
EncryptionErrorEncryption or decryption fails, as with a wrong key
AllowlistMatchErrorAn allowlist entry is invalid
BatchProcessingErrorReserved: the batch functions report each failure in its result
KeyManagementErrorA key ring operation fails, as with a destroyed key version
TokenVaultErrorA token vault operation fails
PolicyErrorA policy document is invalid or weaker than a regulation it extends
AuditIntegrityErrorAn audit chain cannot be extended or verified
import { AnonymaError, PolicyError } from "anonyma";
import { parsePolicy } from "anonyma/compliance";

try {
parsePolicy(document);
} catch (error) {
if (error instanceof PolicyError) {
for (const issue of error.issues) console.error(issue.path, issue.message);
} else if (error instanceof AnonymaError) {
console.error(error.code, error.message);
}
}