package org.basex.query;

import static org.basex.query.QueryError.ErrType.*;
import static org.basex.query.QueryText.*;

import org.basex.query.expr.*;
import org.basex.query.value.*;
import org.basex.query.value.item.*;
import org.basex.query.value.map.*;
import org.basex.query.value.type.*;
import org.basex.util.*;
import org.basex.util.hash.*;
import org.basex.util.list.*;

/**
 * This class contains all query error messages.
 *
 * @author BaseX Team, BSD License
 * @author Christian Gruen
 */
public enum QueryError {

  // BaseX errors

  /** Error code. */
  BASEX_ANN1_X(BASEX, "annotation", "Unknown annotation: %."),
  /** Error code. */
  BASEX_ANN2_X_X(BASEX, "annotation", "%: %."),
  /** Error code. */
  BASEX_ANN3_X(BASEX, "annotation", "Annotation % is declared twice."),
  /** Error code. */
  BASEX_ANN_X_X_X(BASEX, "annotation", "%: % expected, % found."),
  /** Error code. */
  BASEX_DBPATH1_X(BASEX, "doc", "Database path '%' yields no documents."),
  /** Error code. */
  BASEX_DBPATH2_X(BASEX, "doc", "Database path '%' yields more than one document."),
  /** Error code. */
  BASEX_FUNCTION_X(BASEX, "function", "Value is a function: %."),
  /** Error code. */
  BASEX_WHICH_X(BASEX, "function", "Function not found: %."),
  /** Error code. */
  BASEX_CLASSPATH_X_X(BASEX, "function", "Function % requires missing class: %."),
  /** Error code. */
  BASEX_ERROR_X(BASEX, "error", "%"),
  /** Error code. */
  BASEX_HTTP(BASEX, "http", "HTTP connection required."),
  /** Error code. */
  BASEX_LIMIT_X_X(BASEX, "limit", "Too many % (limit: %)."),
  /** Error code. */
  BASEX_STRIP_X(BASEX, "strip", "Duplicate attribute name: %."),
  /** Error code. */
  BASEX_OPTIONS_X(BASEX, "options", "%"),
  /** Error code. */
  BASEX_OPTIONSINV_X(BASEX, "options", "Unknown database option: %."),
  /** Error code. */
  BASEX_OPTIONSLIB_X(BASEX, "options", "Database option not allowed in library module: %."),
  /** Error code. */
  BASEX_OPTIONS_X_X(BASEX, "options", "Database option '%' cannot be set to '%'."),
  /** Error code. */
  BASEX_OVERFLOW(BASEX, "overflow", "Stack Overflow: Try tail recursion?"),
  /** Error code. */
  BASEX_PERMISSION_X_X(BASEX, "permission", "No % permission: %."),
  /** Error code. */
  BASEX_RESTXQ_X(BASEX, "restxq", "%"),
  /** Error code. */
  BASEX_WS_X(BASEX, "ws", "%"),
  /** Error code. */
  BASEX_UPDATE(BASEX, "update", "Update target was not created by transform expression."),
  /** Error code. */
  BASEX_WS(BASEX, "ws", "WebSocket connection required."),

  // Admin Module

  /** Error code. */
  ADMIN_DELETE_X(ADMIN, "delete", "Log file cannot be deleted: %."),
  /** Error code. */
  ADMIN_TODAY(ADMIN, "today", "Today's log file cannot be deleted."),
  /** Error code. */
  ADMIN_TYPE_X(ADMIN, "type", "Type string contains whitespace: '%'."),

  // Archive Module

  /** Error code. */
  ARCHIVE_NAME(ARCHIVE, "descriptor", "Name of ZIP entry must not be empty."),
  /** Error code. */
  ARCHIVE_LEVEL_X(ARCHIVE, "descriptor", "Invalid compression level: '%'."),
  /** Error code. */
  ARCHIVE_TIMESTAMP_X(ARCHIVE, "descriptor", "xs:dateTime value is invalid : '%'."),
  /** Error code. */
  ARCHIVE_ENCODE1_X(ARCHIVE, "encode", "%"),
  /** Error code. */
  ARCHIVE_ENCODE2_X(ARCHIVE, "encode", "String conversion: %."),
  /** Error code. */
  ARCHIVE_ERROR_X(ARCHIVE, "error", "Operation failed: %."),
  /** Error code. */
  ARCHIVE_FORMAT(ARCHIVE, "format", "Packing format not supported."),
  /** Error code. */
  ARCHIVE_FORMAT_X_X(ARCHIVE, "format", "% not supported: '%'."),
  /** Error code. */
  ARCHIVE_MODIFY_X(ARCHIVE, "modify", "Entries of % archive cannot be modified."),
  /** Error code. */
  ARCHIVE_NUMBER_X_X(ARCHIVE, "number", "Number of entries and contents differs: % vs. %."),
  /** Error code. */
  ARCHIVE_SINGLE_X(ARCHIVE, "single", "% archives are limited to a single entry."),
  /** Error code. */
  ARCHIVE_ZIP_X(ARCHIVE, "zip", "Local ZIP file expected: %."),

  // Binary Module

  /** Error code. */
  BIN_DLA_X_X(BIN, "differing-length-arguments", "Inputs are of different length (%/%)."),
  /** Error code. */
  BIN_IOOR_X_X(BIN, "index-out-of-range", "Index '%' is out of range (0-%)."),
  /** Error code. */
  BIN_ITL_X_X(BIN, "integer-too-large", "Index '%' is too large: %."),
  /** Error code. */
  BIN_NS_X(BIN, "negative-size", "Size '%' is negative."),
  /** Error code. */
  BIN_OOR_X(BIN, "octet-out-of-range", "Octet '%' is out of range."),
  /** Error code. */
  BIN_NNC(BIN, "non-numeric-character", "Invalid character in constructor string."),
  /** Error code. */
  BIN_UE_X(BIN, "unknown-encoding", "%"),
  /** Error code. */
  BIN_CE_X(BIN, "conversion-error", "%."),
  /** Error code. */
  BIN_USO_X(BIN, "unknown-significance-order", "Unknown octet-order value: '%'."),

  // Client Module

  /** Error code. */
  CLIENT_COMMAND_X(CLIENT, "command", "Command cannot be executed: %"),
  /** Error code. */
  CLIENT_CONNECT_X(CLIENT, "connect", "Connection failed: %"),
  /** Error code. */
  CLIENT_ERROR_X(CLIENT, "error", "An error occurred: %"),
  /** Error code. */
  CLIENT_FITEM_X(CLIENT, "function", "Result is a function item: %."),
  /** Error code. */
  CLIENT_ID_X(CLIENT, "id", "Session with ID % is not available or has been closed."),
  /** Error code. */
  CLIENT_QUERY_X(CLIENT, "query", "Query cannot be executed: %"),

  // Conversion Module

  /** Error code. */
  CONVERT_STRING_X(CONVERT, "string", "String conversion: %."),
  /** Error code. */
  CONVERT_BINARY_X_X(CONVERT, "binary", "Conversion of '%' to encoding '%' failed."),
  /** Error code. */
  CONVERT_ENCODING_X(CONVERT, "encoding", "%"),
  /** Error code. */
  CONVERT_BASE_X(CONVERT, "base", "Unsupported base: %."),
  /** Error code. */
  CONVERT_INTEGER_X_X(CONVERT, "integer", "Invalid digit for base %: %."),
  /** Error code. */
  CONVERT_KEY_X(CONVERT, "key", "Key cannot be decoded: %."),

  // Cryptographic Module

  /** Error code. */
  CX_CANINV(CX, 1, "Canonicalization algorithm is not supported."),
  /** Error code. */
  CX_DIGINV(CX, 2, "Digest algorithm is not supported."),
  /** Error code. */
  CX_SIGINV(CX, 3, "Signature algorithm is not supported."),
  /** Error code. */
  CX_XPINV(CX, 4, "XPath expression is invalid."),
  /** Error code. */
  CX_INVNM(CX, 5, "Invalid name for $digital-certificate root."),
  /** Error code. */
  CX_KSNULL_X(CX, 7, "Key store is null: %"),
  /** Error code. */
  CX_NOKEY(CX, 12, "Cannot find key for alias in given keystore."),
  /** Error code. */
  CX_INVHASH_X(CX, 13, "Hashing algorithm is not supported: %."),
  /** Error code. */
  CX_ENC_X(CX, 14, "The encoding method is not supported: %."),
  /** Error code. */
  CX_NOSIG(CX, 15, "Cannot find signature element."),
  /** Error code. */
  CX_NOPAD_X(CX, 16, "No such padding: %."),
  /** Error code. */
  CX_BADPAD_X(CX, 17, "Incorrect padding: %."),
  /** Error code. */
  CX_ENCTYP_X(CX, 18, "Encryption type is not supported: %."),
  /** Error code. */
  CX_KEYINV_X(CX, 19, "Secret key is invalid: %."),
  /** Error code. */
  CX_ILLBLO_X(CX, 20, "Illegal block size: %."),
  /** Error code. */
  CX_INVALGO_X(CX, 21, "Algorithm is not supported: %."),
  /** Error code. */
  CX_ALINV_X(CX, 23, "Invalid certificate alias %."),
  /** Error code. */
  CX_ALGEXC(CX, 24, "Invalid algorithm."),
  /** Error code. */
  CX_IOEXC(CX, 25, "IO Exception."),
  /** Error code. */
  CX_KSEXC(CX, 26, "Keystore exception."),
  /** Error code. */
  CX_SIGEXC(CX, 27, "Signature exception."),
  /** Error code. */
  CX_SIGTYPINV(CX, 28, "Signature type is not supported."),

  // CSV Module

  /** Error code. */
  CSV_PARSE_X(CSV, "parse", "%"),
  /** Error code. */
  CSV_SERIALIZE_X(CSV, "serialize", "%."),
  /** Error code. */
  CSV_SERIALIZE_X_X(CSV, "serialize", "%: %."),

  // Database Module

  /** Error code. */
  DB_ARGS_X_X(DB, "args", "Number of specified inputs and paths differs: % vs. %."),
  /** Error code. */
  DB_CONFLICT1_X_X(DB, "conflict", "Database '%' can only be % once."),
  /** Error code. */
  DB_CONFLICT2_X_X(DB, "conflict", "Backup '%' can only be % once."),
  /** Error code. */
  DB_CONFLICT3_X(DB, "conflict", "Database '%' cannot be both altered and dropped."),
  /** Error code. */
  DB_CONFLICT4_X(DB, "conflict", "Name of source and target is equal: %."),
  /** Error code. */
  DB_CONFLICT5_X(DB, "conflict", "Resource '%' can only be stored once."),
  /** Error code. */
  DB_LOCK1_X(DB, "lock", "Database '%' cannot be updated, it is opened by another process."),
  /** Error code. */
  DB_LOCK2_X(DB, "lock", "%"),
  /** Error code. */
  DB_MAINMEM_X(DB, "mainmem", "Database '%' is in main memory."),
  /** Error code. */
  DB_NAME_X(DB, "name", "Invalid name: %."),
  /** Error code. */
  DB_NOBACKUP_X(DB, "no-backup", "No backup exists for database '%'."),
  /** Error code. */
  DB_NODE_X(DB, "node", "No database node: %."),
  /** Error code. */
  DB_NOINDEX_X_X(DB, "no-index", "Database '%' has no % index."),
  /** Error code. */
  DB_GET1_X(DB, "get", "Database '%' not found."),
  /** Error code. */
  DB_GET2_X(DB, "get", "%"),
  /** Error code. */
  DB_OPTION_X(DB, "option", "Unknown option: %."),
  /** Error code. */
  DB_PATH_X(DB, "path", "Invalid path: %."),
  /** Error code. */
  DB_PROPERTY_X(DB, "property", "Unknown database property: %."),
  /** Error code. */
  DB_RANGE_X_X(DB, "range", "Database '%' value out of range: %."),

  // Fetch Module

  /** Error code. */
  FETCH_OPEN_X(FETCH, "open", "%"),
  /** Error code. */
  FETCH_ENCODING_X(FETCH, "encoding", "%"),

  // File Module

  /** Error code. */
  FILE_NOT_FOUND_X(FILE, "not-found", "'%' not found."),
  /** Error code. */
  FILE_EXISTS_X(FILE, "exists", "'%' already exists."),
  /** Error code. */
  FILE_NO_DIR_X(FILE, "no-dir", "'%' is no directory."),
  /** Error code. */
  FILE_IS_DIR_X(FILE, "is-dir", "'%' is a directory."),
  /** Error code. */
  FILE_IS_DIR2_X(FILE, "is-dir", "'%' is a non-empty directory."),
  /** Error code. */
  FILE_CYCLIC_X_X(FILE, "cyclic", "Target '%' is located inside source '%'."),
  /** Error code. */
  FILE_IS_RELATIVE_X(FILE, "is-relative", "Base directory is relative: '%'."),
  /** Error code. */
  FILE_UNKNOWN_ENCODING_X(FILE, "unknown-encoding", "%"),
  /** Error code. */
  FILE_OUT_OF_RANGE_X_X(FILE, "out-of-range", "Requested file chunk [%,%] exceeds file bounds."),
  /** Error code. */
  FILE_INVALID_PATH_X(FILE, "invalid-path", "Invalid file path: '%'."),
  /** Error code. */
  FILE_IO_ERROR_X(FILE, "io-error", "%"),
  /** Error code. */
  FILE_ACCESS_X(FILE, "io-error", "Access to '%' is denied."),

  // Fulltext Module

  /** Error code. */
  FT_OPTIONS(FT, "options", "Wildcards and fuzzy option cannot be specified both."),

  // HTTP Module

  /** Invalid URI. */
  HC_URI_X(HC, 1, "Invalid URI: %"),
  /** Error code. */
  HC_ERROR_X(HC, 1, "%"),
  /** Error code. */
  HC_PARSE_X(HC, 2, "Conversion failed: %"),
  /** Error code. */
  HC_ATTR(HC, 3, "No attribute allowed beside 'src' and 'media-type'."),
  /** Error code. */
  HC_REQ_X(HC, 4, "%."),
  /** Error code. */
  HC_URL(HC, 5, "No URL supplied."),

  // Inspection Module

  /** Error code. */
  INSPECT_UNKNOWN_X(INSPECT, "unknown", "Component '%' does not exist."),
  /** Error code. */
  INSPECT_PARSE_X(INSPECT, "parse", "%"),

  // Jobs Module

  /** Error code. */
  JOBS_ID_EXISTS_X(JOB, "id", "Job id already exists: %."),
  /** Error code. */
  JOBS_ID_INVALID_X(JOB, "id", "Invalid job name: %."),
  /** Error code. */
  JOBS_OPTIONS(JOB, "options", "Either 'cache' or 'interval' option is allowed."),
  /** Error code. */
  JOBS_OVERFLOW1_X(JOB, "overflow", "Too many jobs registered (%)."),
  /** Error code. */
  JOBS_OVERFLOW2_X(JOB, "overflow", "Too many job results cached (%)."),
  /** Error code. */
  JOBS_RANGE_X(JOB, "range", "Value out of range: %."),
  /** Error code. */
  JOBS_RUNNING_X(JOB, "running", "Result is not available yet: %."),
  /** Error code. */
  JOBS_SELF_X(JOB, "self", "Cannot wait for own job: %"),
  /** Error code. */
  JOBS_SERVICE(JOB, "service", "No variables allowed."),
  /** Error code. */
  JOBS_SERVICE_X_X(JOB, "service", "Cannot write service: %."),

  // JSON Module

  /** Error code. */
  JSON_PARSE_X(JSON, "parse", "%"),
  /** Error code. */
  JSON_SERIALIZE_X(JSON, "serialize", "%."),
  /** Error code. */
  JSON_OPTIONS_X(JSON, "options", "'%':'%' is not supported by the target format."),

  // Process Module

  /** Error code. */
  PROC_ENCODING_X(PROC, "encoding", "%"),
  /** Error code. */
  PROC_ERROR_X(PROC, "error", "%"),
  /** Error code. */
  PROC_TIMEOUT(PROC, "timeout", "The timeout was exceeded."),

  // Profiling Module

  // Random Module

  /** Error code. */
  RANDOM_BOUNDS_X(RANDOM, "bounds", "Maximum value is out of bounds: %."),
  /** Error code. */
  RANGE_NEGATIVE_X(RANDOM, "negative", "Number of values is negative: %."),

  // Repository Module

  /** Error code. */
  REPO_DELETE_X(REPO, "delete", "File '%' cannot be deleted."),
  /** Error code. */
  REPO_DELETE_X_X(REPO, "delete", "Package '%' depends on package '%'."),
  /** Error code. */
  REPO_DESCRIPTOR_X(REPO, "descriptor", "%."),
  /** Error code. */
  REPO_INSTALLED_X(REPO, "installed", "Module % is already installed within another package."),
  /** Error code. */
  REPO_NOTFOUND_X(REPO, "not-found", "Package '%' not found."),
  /** Error code. */
  REPO_PARSE_X_X(REPO, "parse", "%: %."),
  /** Error code. */
  REPO_VERSION(REPO, "version", "Package version is not supported."),

  // Request Module

  /** Error code. */
  REQUEST_PARAMETER(REQUEST, "parameter", "Query string cannot be decoded."),

  // Session Module

  /** Error code. */
  SESSION_NOTFOUND(SESSIONS, "not-found", "Session not available."),

  // Sessions Module

  /** Error code. */
  SESSIONS_NOTFOUND_X(SESSIONS, "not-found", "Session not available: %."),

  // SQL Module

  /** Error code. */
  SQL_ATTRIBUTE_X(SQL, "attribute", "Attribute not expected: %."),
  /** Error code. */
  SQL_INIT_X(SQL, "init", "Cannot find driver: %"),
  /** Error code. */
  SQL_ERROR_X(SQL, "error", "An SQL exception occurred: %"),
  /** Error code. */
  SQL_TIMEOUT_X(SQL, "timeout", "A query timeout has occurred: %"),
  /** Error code. */
  SQL_ID1_X(SQL, "id", "No connection with id %."),
  /** Error code. */
  SQL_ID2_X(SQL, "id", "No prepared statement with id %."),
  /** Error code. */
  SQL_PARAMETERS(SQL, "parameters", "No parameter type supplied."),
  /** Error code. */
  SQL_TYPE_X_X(SQL, "type", "Invalid type (%): %."),

  // Store Module

  /** Error code. */
  STORE_IO_X(STORE, "io", "%"),
  /** Error code. */
  STORE_NAME_X(STORE, "name", "Invalid name: %."),

  // String Module

  /** Error code. */
  STRING_FORMAT_X_X(STRING, "format", "%: %."),
  /** Error code. */
  STRING_BOUNDS_X(STRING, "bounds", "String exceeds maximum supported length of % characters."),
  /** Error code. */
  STRING_NGRAM_X(STRING, "ngram", "N-gram length must be positive: %."),

  // Unit Module

  /** Error code. */
  UNIT_FAIL(UNIT, "fail", "Assertion failed."),
  /** Error code. */
  UNIT_FAIL_X(UNIT, "fail", "%"),
  /** Error code. */
  UNIT_FAIL_X_X_X(UNIT, "fail", "Item %: % expected, % returned."),
  /** Error code. */
  UNIT_NOARGS_X(UNIT, "no-args", "Test function '%' must have no arguments."),
  /** Error code. */
  UNIT_PRIVATE_X(UNIT, "private", "Test function '%' must not be private."),

  // User Module

  /** Error code. */
  USER_ADMIN(USER, "admin", "User 'admin' cannot be modified."),
  /** Error code. */
  USER_CONFLICT_X(USER, "conflict", "User '%' cannot be both altered and dropped."),
  /** Error code. */
  USER_EQUAL_X(USER, "equal", "Name of old and new user is equal: %."),
  /** Error code. */
  USER_INFO_X(USER, "info", "Info can only be % once."),
  /** Error code. */
  USER_LOCAL(USER, "local", "Local permission can only be 'none', 'read' or 'write'."),
  /** Error code. */
  USER_LOGGEDIN_X(USER, "logged-in", "User '%' is currently logged in."),
  /** Error code. */
  USER_NAME_X(USER, "name", "Invalid username: '%'."),
  /** Error code. */
  USER_PASSWORD_X(USER, "password", "Wrong password supplied for user '%'."),
  /** Error code. */
  USER_PATTERN_X(USER, "pattern", "Invalid database pattern: '%'."),
  /** Error code. */
  USER_PERMISSION_X(USER, "permission", "Invalid permission: '%'."),
  /** Error code. */
  USER_UNKNOWN_X(USER, "unknown", "User '%' does not exist."),
  /** Error code. */
  USER_UPDATE1_X_X(USER, "update", "User '%' can only be % once."),
  /** Error code. */
  USER_UPDATE2_X(USER, "update", "Pattern '%' is specified more than once."),
  /** Error code. */
  USER_UPDATE3_X_X(USER, "update", "User '%' can only be % once."),

  // Validation Module

  /** Error code. */
  VALIDATE_ERROR_X(ErrType.VALIDATE, "error", "Validation failed: %"),
  /** Error code. */
  VALIDATE_START_X(ErrType.VALIDATE, "init", "Validation cannot be started: %"),
  /** Error code. */
  VALIDATE_NOTFOUND_X(ErrType.VALIDATE, "not-found", "RelaxNG validation is not available."),

  // Web Module

  /** Error code. */
  WEB_STATUS_X(WEB, "status", "Invalid status code: %"),

  // WebSocket Module

  /** Error code. */
  WS_NOTFOUND_X(WS, "not-found", "Unknown WebSocket: %."),

  // XQuery Module

  /** Error code. */
  XQUERY_NOUPDATES(ErrType.XQUERY, "update", "No updating expression allowed."),
  /** Error code. */
  XQUERY_UPDATEEXPECTED(ErrType.XQUERY, "update", "Updating expression expected."),
  /** Error code. */
  XQUERY_PERM_X(ErrType.XQUERY, "permission", "%"),
  /** Error code. */
  XQUERY_NOPERM_X(ErrType.XQUERY, "permission", "No % permission."),
  /** Error code. */
  XQUERY_TIMEOUT(ErrType.XQUERY, "timeout", "The timeout was exceeded."),
  /** Error code. */
  XQUERY_MEMORY(ErrType.XQUERY, "memory", "The memory limit was exceeded."),
  /** Error code. */
  XQUERY_NESTED(ErrType.XQUERY, "nested", "Nested query evaluation is not allowed."),
  /** Error code. */
  XQUERY_UNEXPECTED_X(ErrType.XQUERY, "error", "Unexpected error: %"),

  // XSLT Module

  /** Error code. */
  XSLT_ERROR_X(XSLT, "error", "%"),

  // W3 Functions

  /** Error code. */
  APPLY_X_X(FOAP, 1, "% supplied to %: %."),

  /** Error code. */
  DIVZERO_X(FOAR, 1, "% cannot be divided by zero."),
  /** Error code. */
  INVIDIV(FOAR, 2, "Invalid integer division: %."),
  /** Error code. */
  RANGE_X(FOAR, 2, "Value out of range: %."),

  /** Error code. */
  ARRAYBOUNDS_X_X(FOAY, 1, "Array index % out of bounds (1..%)."),
  /** Error code. */
  ARRAYEMPTY(FOAY, 1, "Array has no entries."),
  /** Error code. */
  ARRAYNEG_X(FOAY, 2, "Length is negative: %."),

  /** Error code. */
  INVALUE_X_X(FOCA, 2, "Cannot convert to %: %."),
  /** Error code. */
  INTRANGE_X(FOCA, 3, "Integer value out of range: %."),
  /** Error code. */
  DATECALC_X_X(FOCA, 5, "Invalid % calculation: %."),

  /** Error code. */
  INVCODE_X(FOCH, 1, "Invalid XML character: %."),
  /** Error code. */
  WHICHCOLL_X(FOCH, 2, "%."),
  /** Error code. */
  NORMUNI_X(FOCH, 3, "Unsupported normalization form ('%')."),
  /** Error code. */
  CHARCOLL(FOCH, 4, "Collation does not operate on character-by-character basis."),
  /** Error code. */
  CHARINV_X(FOCH, 5, "Invalid name, glyph or codepoint value: %."),

  /** Error code. */
  CSV_ERROR_X(FOCV, 1, "CSV processing error: %."),
  /** Error code. */
  CSV_QUOTING_X(FOCV, 1, "CSV field quoting error: %."),
  /** Error code. */
  CSV_SINGLECHAR_X_X(FOCV, 2, "The value of '%' is not a single character: '%'."),
  /** Error code. */
  CSV_DELIMITER_X(FOCV, 3, "Duplicate CSV delimiter error: %."),
  /** Error code. */
  CSV_COLUMNNAME_X(FOCV, 4, "Argument supplied is not a known column name: %."),

  /** Error code. */
  IDDOC(FODC, 1, "Specified node has no document node as root."),
  /** Error code. */
  NODEERR_X_X(FODC, 2, "% cannot be created: %."),
  /** Error code. */
  NODEFCOLL(FODC, 2, "No default collection available."),
  /** Error code. */
  IOERR_X(FODC, 2, "%"),
  /** Error code. */
  WHICHRES_X(FODC, 2, "Resource '%' not found."),
  /** Error code. */
  RESDIR_X(FODC, 2, "URI '%' points to a directory."),
  /** Error code. */
  INVCOLL_X(FODC, 4, "Invalid collection URI: %."),
  /** Error code. */
  INVDOC_X(FODC, 5, "Invalid document URI: %."),
  /** Error code. */
  SAXERR_X(FODC, 6, "SAX: %"),
  /** Error code. */
  DTDVALIDATIONERR_X(FODC, 7, "DTD Validation error: %"),
  /** Error code. */
  INVALIDXSDOPT_X(FODC, 8, "Unsupported value of option 'xsd-validation': '%'."),
  /** Error code. */
  NOXSDVALIDATION_X(FODC, 9, "The internal parser does not support 'xsd-validation': '%'."),
  /** Error code. */
  NOXSDANDDTD_X(FODC, 9, "DTD validation must not be enabled when 'xsd-validation' is '%'."),
  /** Error code. */
  INVHTML_X(FODC, 11, "HTML parsing failed: %"),
  /** Error code. */
  NODTDVALIDATION(FODC, 13, "The internal parser does not support DTD validation."),
  /** Error code. */
  XSDVALIDATIONERR_X(FODC, 14, "XSD Validation error: %"),

  /** Error code. */
  FORMATWHICH_X(FODF, 1280, "Unknown decimal format: %."),
  /** Error code. */
  FORMATINV_X(FODF, 1290, "%"),
  /** Error code. */
  PICEMPTY(FODF, 1310, "The picture string must not be empty: '%'"),
  /** Error code. */
  PICNUM_X(FODF, 1310, "Invalid picture string: '%'."),
  /** Error code. */
  OPTAFTER_X(FODF, 1310, "Optional digit sign follows mandatory digit signs: '%'."),
  /** Error code. */
  OPTBEFORE_X(FODF, 1310, "Mandatory digit sign follows optional digit signs: '%'."),
  /** Error code. */
  INVGROUP_X(FODF, 1310, "Invalid position of grouping separator signs: '%'."),
  /** Error code. */
  DIFFMAND_X(FODF, 1310, "Mandatory digits is not of the same group: '%'."),
  /** Error code. */
  INVMODIFIER_X(FODF, 1310, "Invalid specification of ordinal/cardinal numbering: '%'."),
  /** Error code. */
  INVDDPATTERN_X(FODF, 1310, "Invalid decimal-digit-pattern: '%'."),

  /** Error code. */
  DATERANGE_X_X(FODT, 1, "%: '%' out of range."),
  /** Error code. */
  YEARRANGE_X(FODT, 1, "Year '%' out of range."),
  /** Error code. */
  SECRANGE_X(FODT, 1, "Seconds '%' out of range."),
  /** Error code. */
  DURRANGE_X_X(FODT, 2, "%: '%' out of range."),
  /** Error code. */
  MONTHRANGE_X(FODT, 2, "Months '%' out of range."),
  /** Error code. */
  SECDURRANGE_X(FODT, 2, "Seconds '%' out of range."),
  /** Error code. */
  DATEZERO_X_X(FODT, 2, "Invalid % calculation: %."),
  /** Error code. */
  INVALIDZONE_X(FODT, 3, "Timezone out of range (-14:00 to +14:00): %."),
  /** Error code. */
  ZONESEC_X(FODT, 3, "No seconds allowed in timezone: %."),
  /** Error code. */
  PLACE_X(FODT, 4, "Unknown place: %."),
  /** Error code. */
  INVDATETIMEFIELDS_X(FODT, 5, "Invalid combination of date/time fields: %"),

  /** Error code. */
  FUNERR1(FOER, 0, "Halted on error()."),

  /** Error code. */
  INVCOMPSPEC_X(FOFD, 1340, "Invalid variable marker: '[%]'."),
  /** Error code. */
  PICDATE_X(FOFD, 1340, "Invalid picture string: '%'."),
  /** Error code. */
  CALWHICH_X(FOFD, 1340, "Unknown calendar: '%'."),
  /** Error code. */
  INVFDPATTERN_X(FOFD, 1340, "%"),
  /** Error code. */
  PICINVCOMP_X_X_X(FOFD, 1350, "[%] not applicable to %: %."),

  /** Error code. */
  HASH_ALGORITHM_X(FOHA, 1, "Algorithm not supported: '%'."),

  /** Error code. */
  PARSE_JSON_X(FOJS, 1, "%"),
  /** Error code. */
  PARSE_JSON_X_X_X(FOJS, 1, "(%:%): %."),
  /** Error code. */
  DUPLICATE_JSON_X(FOJS, 3, "%"),
  /** Error code. */
  MERGE_DUPLICATE_X(FOJS, 3, "Key % occurs more than once."),
  /** Error code. */
  OPTION_JSON_X(FOJS, 5, "%"),
  /** Error code. */
  INVALID_JSON_X(FOJS, 6, "%"),
  /** Error code. */
  ESCAPE_JSON_X(FOJS, 7, "Invalid escape sequence: %."),
  /** Error code. */
  PLAN_X_X(FOJS, 8, "Layout '%' cannot be applied: %."),

  /** Error code. */
  NSDECL_X(FONS, 4, "Namespace prefix not declared: %."),

  /** Error code. */
  MODULE_URI_EMPTY(FOQM, 1, "Module URI is a zero-length string."),
  /** Error code. */
  MODULE_NOT_FOUND_X(FOQM, 2, "Module not found: '%'"),
  /** Error code. */
  MODULE_FOUND_MAIN_X(FOQM, 2, "Found main module instead of library module '%'."),
  /** Error code. */
  MODULE_FOUND_OTHER_X(FOQM, 2, "Did not find expected module '%'."),
  /** Error code. */
  MODULE_FOUND_OTHER_X_X(FOQM, 2, "Did not find expected module '%' in '%'."),
  /** Error code. */
  MODULE_STATIC_ERROR_X_X(FOQM, 3, "Static error in dynamically loaded XQuery module '%': %"),
  /** Error code. */
  MODULE_PARAMETER_TYPE_X_X(FOQM, 5,
      "Parameter for dynamically loaded XQuery module '%' has incorrect type: %"),
  /** Error code. */
  MODULE_CONTEXT_TYPE_X_X(FOQM, 5,
      "The context item for dynamically loaded XQuery module '%' has incorrect type: %"),
  /** Error code. */
  MODULE_XQUERY_VERSION_X(FOQM, 6, "XQuery version '%' not supported."),

  /** Error code. */
  PATH_X(FOPA, 1, "Node is not contained in path: %."),

  /** Error code. */
  INVALIDVALUE_X_X(FORG, 1, "Invalid % value: %."),
  /** Error code. */
  MISSINGZONE_X(FORG, 1, "xs:dateTimeStamp value must have a timezone: %."),
  /** Error code. */
  FUNCCAST_X_X(FORG, 1, "Cannot convert to %: %."),
  /** Error code. */
  FUNCCAST_X_X_X(FORG, 1, "Cannot convert % to %: %."),
  /** Error code. */
  DATEFORMAT_X_X_X(FORG, 1, "Wrong % format: '%' (try e.g. '%')."),
  /** Error code. */
  URIARG_X(FORG, 2, "Invalid URI: %."),
  /** Error code. */
  ZEROORONE(FORG, 3, "Zero or one item expected."),
  /** Error code. */
  ONEORMORE(FORG, 4, "One or more item expected."),
  /** Error code. */
  EXACTLYONE(FORG, 5, "Exactly one item expected."),
  /** Error code. */
  ARGTYPE_X_X_X(FORG, 6, "% expected, % found: %."),
  /** Error code. */
  NUMDUR_X_X(FORG, 6, "Number or duration expected, % found: %."),
  /** Error code. */
  FUNZONE_X_X(FORG, 8, "% and % have different timezones."),
  /** Error code. */
  IETF_PARSE_X_X_X(FORG, 10, "Invalid input (% expected, '%' found): '%'."),
  /** Error code. */
  IETF_INV_X(FORG, 10, "Invalid input: '%'."),
  /** Error code. */
  INTRADIX_X(FORG, 11, "Radix out of range (2-36): %."),
  /** Error code. */
  INTINVALID_X_X(FORG, 12, "Cannot parse input with radix %: %."),

  /** Error code. */
  REGFLAG_X(FORX, 1, "Invalid regular flag: '%'."),
  /** Error code. */
  REGINVALID_X(FORX, 2, "Invalid regular expression: %."),
  /** Error code. */
  REGBACKSLASH_X(FORX, 4, "Invalid backslash in replacement string: %."),
  /** Error code. */
  REGDOLLAR_X(FORX, 4, "Invalid dollar sign in replacement string: %."),

  /** Error code. */
  FIATOMIZE_X(FOTY, 13, "Atomic item required, function item found: %."),
  /** Error code. */
  FISTRING_X(FOTY, 14, "Function item has no string value: %."),

  /** Error code. */
  UPFOTYPE_X(FOUP, 1, "Document or element expected, % found."),
  /** Error code. */
  UPDOCTYPE_X(FOUP, 1, "Document expected, % found."),
  /** Error code. */
  UPFOURI_X(FOUP, 2, "Invalid URI: %."),
  /** Error code. */
  UPPUTERR_X(FOUP, 2, "File '%' cannot be written."),
  /** Error code. */
  UPDBPUT_X(FOUP, 2, "Resource '%' cannot be written."),
  /** Error code. */
  UPDROPBACK_X_X(FOUP, 2, "Backup '%' cannot be %."),
  /** Error code. */
  UPDBERROR_X_X(FOUP, 2, "Database '%' cannot be %."),
  /** Error code. */
  UPDBERROR_X(FOUP, 2, "%"),

  /** Error code. */
  PARSE_URI_X(FOUR, 1, "Invalid IPv6/IPvFuture authority: %."),

  /** Error code. */
  RESWHICH_X(FOUT, 1170, "Resource cannot be retrieved: %."),
  /** Error code. */
  RESFRAG_X(FOUT, 1170, "URI contains a fragment identifier: %."),
  /** Error code. */
  RESURI_X(FOUT, 1170, "URI is invalid: %"),
  /** Error code. */
  RESENCODING_X(FOUT, 1190, "%"),
  /** Error code. */
  RESINPUT_X(FOUT, 1190, "%."),
  /** Error code. */
  RECDECODING_X(FOUT, 1200, "%."),

  /** Error code. */
  FTWEIGHT_X(FTDY, 16, "Weight value out of range: %."),
  /** Error code. */
  FTMILD(FTDY, 17, "Invalid 'mild not' selection."),
  /** Error code. */
  FTWILDCARD_X(FTDY, 20, "Invalid wildcard syntax: '%'."),

  /** Error code. */
  FTIGNORE(FTST, 7, "Ignore option not supported."),
  /** Error code. */
  NOSTOPFILE_X(FTST, 8, "Stop word file not found: '%'."),
  /** Error code. */
  FTNOSTEM_X(FTST, 9, "No stemmer available for language '%'."),
  /** Error code. */
  FTNOTOK_X(FTST, 9, "No tokenizer available for language '%'."),
  /** Error code. */
  NOTHES_X(FTST, 18, "Thesaurus not found: %."),
  /** Error code. */
  FTDUP_X(FTST, 19, "Match option '%' is declared twice."),

  /** Error code. */
  IXML_GRM_X_X_X(FOIX, 1, "Failed to parse ixml grammar: cannot match % at line %, column %."),
  /** Error code. */
  IXML_GEN_X(FOIX, 1, "Failed to generate ixml parser: %"),
  /** Error code. */
  IXML_INP_X_X_X(FOIX, 2, "Failed to parse ixml input: cannot match % at line %, column %."),
  /** Error code. */
  IXML_RESULT_X(FOIX, 2, "Failed to process ixml parser result: %"),

  /** Error code. */
  SERATTR_X(SENR, 1, "Attributes cannot be serialized:%."),
  /** Error code. */
  SERNS_X(SENR, 1, "Namespaces cannot be serialized:%."),
  /** Error code. */
  SERFUNC_X(SENR, 1, "% items cannot be serialized."),
  /** Error code. */
  SERSA(SEPM, 4, "If 'standalone' is specified, the root must be a single element."),
  /** Error code. */
  SERDT(SEPM, 4, "If 'doctype-system' is specified, the root must be a single element."),
  /** Error code. */
  SERENCODING_X(SESU, 7, "%"),
  /** Error code. */
  SERENC_X_X(SERE, 8, "Character '#x%;' cannot be mapped to '%'."),
  /** Error code. */
  SERSTAND(SEPM, 9, "Invalid combination of omit-xml-declaration and other parameters."),
  /** Error code. */
  SERUNDECL(SEPM, 10, "XML 1.0: undeclaring prefixes not allowed."),
  /** Error code. */
  SERNORM_X(SESU, 11, "Normalization form not supported: %."),
  /** Error code. */
  SERNOTSUPP_X(SESU, 13, "%"),
  /** Error code. */
  SERILL_X(SERE, 14, "Illegal HTML character found: #x%;."),
  /** Error code. */
  SERPI(SERE, 15, "Processing construction contains '>'."),
  /** Error code. */
  SERPARAM_X(SEPM, 16, "%"),
  /** Error code. */
  SERDOC_X(SEPM, 17, "%"),
  /** Error code. */
  SERCHARDUP_X(SEPM, 18, "Character '%' is specified twice."),
  /** Error code. */
  SERDUP_X(SEPM, 19, "Serialization parameter '%' is specified twice."),
  /** Error code. */
  SERNUMBER_X(SERE, 20, "Numeric value cannot be represented: '%'"),
  /** Error code. */
  SERJSONFUNC_X(SERE, 21, "% items cannot be serialized."),
  /** Error code. */
  SERDUPL_X(SERE, 22, "Duplicate name found: '%'"),
  /** Error code. */
  SERJSON(SERE, 23, "Only one item can be serialized with JSON."),
  /** Error code. */
  SERJSONSEQ(SERE, 23, "Value has more than one item."),
  /** Error code. */
  SERCANONURI(SERE, 24, "Canonical XML serialization failed: found relative namespace URI: '%'"),
  /** Error code. */
  SERCANONROOTS_X(SERE, 24, "Canonical XML serialization failed: not wellformed: '%'"),

  /** Error code. */
  NOCTX_X(XPDY, 2, "%: Context value is undefined."),
  /** Error code. */
  VAREMPTY_X(XPDY, 2, "No value assigned to %."),
  /** Error code. */
  NODOC_X(XPDY, 50, "Input has no root node: %."),
  /** Error code. */
  NOTREAT_X_X_X(XPDY, 50, "Cannot treat % as %: %."),
  /** Error code. */
  MAX_SIZE_X_X(XPDY, 130, "Maximum size (%) exceeded: %."),

  /** Error code. */
  QUERYEMPTY(XPST, 3, "Empty query."),
  /** Error code. */
  MODLEINV_X(XPST, 3, "Module contains illegal character: %."),
  /** Error code. */
  NOQUOTE_X(XPST, 3, "Expecting quote%."),
  /** Error code. */
  NUMBER_X(XPST, 3, "Incomplete number: '%'."),
  /** Error code. */
  QUERYEND_X(XPST, 3, "Unexpected end of query: '%'."),
  /** Error code. */
  MODEXPR(XPST, 3, "No expression allowed in a library module."),
  /** Error code. */
  MAINMOD(XPST, 3, "Library modules cannot be evaluated."),
  /** Error code. */
  CMPEXPR(XPST, 3, "Comparison is incomplete."),
  /** Error code. */
  NOELEMNAME(XPST, 3, "Expecting element name."),
  /** Error code. */
  ELEMNAME_X(XPST, 3, "Element name expected, '%' found."),
  /** Error code. */
  NOATTNAME(XPST, 3, "Expecting attribute name."),
  /** Error code. */
  NONSNAME(XPST, 3, "Expecting name of namespace."),
  /** Error code. */
  NOPINAME(XPST, 3, "Expecting name of processing instruction."),
  /** Error code. */
  NOEXPR(XPST, 3, "Expecting expression."),
  /** Error code. */
  NOCOMMENT(XPST, 3, "Expecting comment."),
  /** Error code. */
  PIXML_X(XPST, 3, "Name of processing instruction is illegal: '%'."),
  /** Error code. */
  NOPI(XPST, 3, "Expecting processing instruction."),
  /** Error code. */
  NOCDATA(XPST, 3, "Expecting CDATA section."),
  /** Error code. */
  WRONGCHAR_X_X(XPST, 3, "Expecting '%'%."),
  /** Error code. */
  INVENTITY_X(XPST, 3, "Invalid entity: '%'."),
  /** Error code. */
  INCOMPLETE(XPST, 3, "Incomplete expression."),
  /** Error code. */
  MAPCONSTR(XPST, 3, "Incomplete map constructor."),
  /** Error code. */
  ARRAYCONSTR(XPST, 3, "Incomplete array constructor."),
  /** Error code. */
  EVALUNARY(XPST, 3, "Unary operator expects a numeric value."),
  /** Error code. */
  STEPMISS_X(XPST, 3, "Expecting step%."),
  /** Error code. */
  AXISMISS_X(XPST, 3, "Expecting node test after % axis."),
  /** Error code. */
  DECLINCOMPLETE(XPST, 3, "Expecting 'function', 'variable', ..."),
  /** Error code. */
  FUNCNAME(XPST, 3, "Expecting function name."),
  /** Error code. */
  TYPENAME(XPST, 3, "Expecting type name."),
  /** Error code. */
  RESERVED_X(XPST, 3, "'%' is a reserved keyword."),
  /** Error code. */
  NOVARNAME(XPST, 3, "Variable name expected, '%' found."),
  /** Error code. */
  NOVARDECL(XPST, 3, "Expecting variable declaration."),
  /** Error code. */
  NOFTSELECT_X(XPST, 3, "Expecting quote or opening curly brace%."),
  /** Error code. */
  FUNCARG_X(XPST, 3, "Expecting function argument%."),
  /** Error code. */
  MAPTAAT_X(XPST, 3, "Expecting atomic key type for map, found '%'."),
  /** Error code. */
  TYPEINVALID(XPST, 3, "Expecting type declaration."),
  /** Error code. */
  NOTYPESWITCH(XPST, 3, "Incomplete typeswitch expression."),
  /** Error code. */
  NOSWITCH(XPST, 3, "Incomplete switch expression."),
  /** Error code. */
  PRAGMAINV(XPST, 3, "Invalid pragma expression."),
  /** Error code. */
  CALCEXPR(XPST, 3, "Calculation is incomplete."),
  /** Error code. */
  INVMAPKEY(XPST, 3, "Invalid key, simple expression expected."),
  /** Error code. */
  INVMAPVAL(XPST, 3, "Invalid value, simple expression expected."),
  /** Error code. */
  NORETURN(XPST, 3, "Expecting return value."),
  /** Error code. */
  NOWHERE(XPST, 3, "Expecting valid expression after 'where'."),
  /** Error code. */
  NOWHILE(XPST, 3, "Expecting valid expression after 'while'."),
  /** Error code. */
  ORDERBY(XPST, 3, "Expecting valid expression after 'order by'."),
  /** Error code. */
  FLWORRETURN(XPST, 3, "Incomplete FLWOR expression, expecting 'return'."),
  /** Error code. */
  NOSOME(XPST, 3, "Incomplete quantifier expression."),
  /** Error code. */
  IFPAR(XPST, 3, "Expecting '(' after 'if' expression."),
  /** Error code. */
  NOIF(XPST, 3, "Incomplete 'if' expression."),
  /** Error code. */
  NOFOR(XPST, 3, "Incomplete 'for' expression."),
  /** Error code. */
  NOLET(XPST, 3, "Incomplete 'let' expression."),
  /** Error code. */
  NOWINDOW(XPST, 3, "Incomplete 'window' expression."),
  /** Error code. */
  NOCOUNT(XPST, 3, "Incomplete 'count' expression."),
  /** Error code. */
  NOCLOSING_X(XPST, 3, "Expecting closing tag </%>."),
  /** Error code. */
  COMCLOSE(XPST, 3, "Unclosed XQuery comment (: ..."),
  /** Error code. */
  EXPREMPTY(XPST, 3, "Unknown function or expression."),
  /** Error code. */
  WHICHTYPE_X(XPST, 3, "Unknown type: %."),
  /** Error code. */
  INVNAME_X(XPST, 3, "Invalid QName: '%'."),
  /** Error code. */
  QNAME_X(XPST, 3, "QName expected, '%' found."),
  /** Error code. */
  PROLOGORDER(XPST, 3, "Default declarations must be declared first."),
  /** Error code. */
  FTRANGE(XPST, 3, "Expecting full-text range."),
  /** Error code. */
  FTSTOP(XPST, 3, "Stop words expected."),
  /** Error code. */
  FTMATCH_X(XPST, 3, "Unknown match option '%...'."),
  /** Error code. */
  INTEXP(XPST, 3, "Integer expected."),
  /** Error code. */
  VARFUNC(XPST, 3, "Variable or function declaration expected."),
  /** Error code. */
  NOANN(XPST, 3, "No annotation allowed here."),
  /** Error code. */
  NOCATCH(XPST, 3, "Expecting catch clause."),
  /** Error code. */
  ANNVALUE_X(XPST, 3, "Literal expected, '%' found."),
  /** Error code. */
  UPDATINGVAR(XPST, 3, "Variable cannot be updating."),
  /** Error code. */
  UPDATINGTYPE(XPST, 3, "Type cannot be updating."),
  /** Error code. */
  SIMPLETYPE_X(XPST, 3, "Simple type expected, function found: %(."),
  /** Error code. */
  KEYSPEC_X(XPST, 3, "No specifier after lookup operator: '%'."),
  /** Error code. */
  ARROWSPEC_X(XPST, 3, "No specifier after arrow operator: '%'."),
  /** Error code. */
  FORMPROP_X(XPST, 3, "%."),
  /** Error code. */
  CASTTYPE_X(XPST, 3, "%"),
  /** Error code. */
  NOSTRNCN_X(XPST, 3, "Expecting string or NCName, found '%'."),
  /** Error code. */
  NONCNAME_X(XPST, 3, "Expecting NCName, found '%'."),
  /** Error code. */
  INVPLACEHOLDER_X(XPST, 3, "Method call must not have argument placeholders: '%'."),
  /** Error code. */
  STATIC_X(XPST, 5, "No XML Schema support: %."),
  /** Error code. */
  VARUNDEF_X(XPST, 8, "Undeclared variable: %."),
  /** Error code. */
  INVISIBLEVAR_X(XPST, 8, "Variable requires missing module import: %."),
  /** Error code. */
  VARPRIVATE_X(XPST, 8, "Variable % is private."),
  /** Error code. */
  TYPEUNDEF_X(XPST, 8, "Undefined type annotation: %."),
  /** Error code. */
  SCHEMAINV_X(XPST, 8, "Undefined schema name: %."),
  /** Error code. */
  FUNCPRIVATE_X(XPST, 17, "Function not visible: %."),
  /** Error code. */
  INVNARGS_X_X(XPST, 17, "%: %."),
  /** Error code. */
  WHICHFUNC_X(XPST, 17, "Unknown function: %."),
  /** Error code. */
  INVISIBLEFUNC_X(XPST, 17, "Function requires missing module import: %."),
  /** Error code. */
  PARAMMISSING_X_X(XPST, 17, "%: No argument supplied for parameter %."),
  /** Error code. */
  PARAMTWICE_X(XPST, 17, "Multiple arguments supplied for parameter %."),
  /** Error code. */
  PARAMTWICE_X_X(XPST, 17, "%: Multiple arguments supplied for parameter %."),
  /** Error code. */
  PARAMUNKNOWN_X_X(XPST, 17, "%: Unknown parameter: %."),
  /** Error code. */
  ABSTRACTFUNC_X(XPST, 17, "No function exists for abstract type: %."),
  /** Error code. */
  FUNCNOIMPL_X(XPST, 17, "External function not implemented: %."),
  /** Error code. */
  NO_OPTIONS_WITH_DB_X(XPST, 17, "No options allowed with database URI: %."),
  /** Error code. */
  JAVAINIT_X_X(XPST, 17, "%: %."),
  /** Error code. */
  JAVACLASS_X(XPST, 17, "Unknown class: %."),
  /** Error code. */
  JAVAMEMBER_X(XPST, 17, "Unknown method or field: %."),
  /** Error code. */
  DUPFIELD_X(XPST, 21, "Duplicate field name: '%'."),
  /** Error code. */
  TYPEUNKNOWN_X(XPST, 51, "Unknown type: %."),
  /** Error code. */
  INVALIDCAST_X(XPST, 80, "Invalid cast type: %."),
  /** Error code. */
  NOURI_X(XPST, 81, "Namespace prefix not declared: %."),
  /** Error code. */
  PREFIXNOURI_X(XPST, 154, "QName includes prefix, but no URI: %."),

  /** Error code. */
  JAVANOINSTANCE_X_X(XPTY, 4, "% instance expected as first argument, % found."),
  /** Error code. */
  JAVAEXEC_X_X_X(XPTY, 4, "%. Caused by: %%."),
  /** Error code. */
  JAVAMULTIPLE_X_X(XPTY, 4, "Multiple % candidates. Parameters: %."),
  /** Error code. */
  JAVANONE_X_X_X(XPTY, 4, "% cannot be called with %. Expected: %."),
  /** Error code. */
  JAVAARGS_X_X_X(XPTY, 4, "%% expected, % found."),
  /** Error code. */
  JAVAARGS_X_X(XPTY, 4, "% cannot be called with %."),

  /** Error code. */
  NONAME_X(XPTY, 4, "Name expected, '%' found."),
  /** Error code. */
  NONUMBER_X_X(XPTY, 4, "Number expected, % found: %."),
  /** Error code. */
  NODUR_X_X(XPTY, 4, "Duration expected, % found: %."),
  /** Error code. */
  NOSUBDUR_X(XPTY, 4, "Subtype of xs:duration expected: %."),
  /** Error code. */
  NOSUB_X_X(XPTY, 4, "Subtype of % expected: %."),
  /** Error code. */
  STRQNM_X_X(XPTY, 4, "String or QName expected, % found: %."),
  /** Error code. */
  STRNCN_X_X(XPTY, 4, "String or NCName expected, % found: %."),
  /** Error code. */
  INVTYPE_X(XPTY, 4, "%."),
  /** Error code. */
  CALCTYPE_X_X_X_X_X(XPTY, 4, "Arithmetics not defined for % and %: % % %."),
  /** Error code. */
  INVFUNCITEM_X_X(XPTY, 4, "Function expected, % found: %."),
  /** Error code. */
  CMPTYPE_X_X_X(XPTY, 4, "Items of type % cannot be compared: % vs. %."),
  /** Error code. */
  CMPTYPES_X_X_X_X(XPTY, 4, "% and % cannot be compared: % vs. %."),
  /** Error code. */
  DOCATTS_X(XPTY, 4, "Cannot add attributes to a document node: %."),
  /** Error code. */
  DOCNS_X(XPTY, 4, "Cannot add namespaces to a document node: %."),
  /** Error code. */
  INVARITY_X_X(XPTY, 4, "%: %."),
  /** Error code. */
  INVNCNAME_X(XPTY, 4, "Invalid NCName: '%'."),
  /** Error code. */
  VALUETYPES_X_X(XPTY, 4, "Incompatible types in context value declarations: % vs. %."),
  /** Error code. */
  LOOKUP_X(XPTY, 4, "Input of lookup must be map or array: %."),
  /** Error code. */
  EXP_FOUND_X_X(XPTY, 4, "% expected, % found."),
  /** Error code. */
  BINARY_X(XPTY, 4, "Binary expected, % found."),
  /** Error code. */
  STRBIN_X_X(XPTY, 4, "String or binary expected, % found: %."),
  /** Error code. */
  STRNOD_X_X(XPTY, 4, "String or node expected, % found: %."),
  /** Error code. */
  ELMMAP_X_X_X(XPTY, 4, "element(%) or map expected, % found: %."),
  /** Error code. */
  ELM_X_X_X(XPTY, 4, "element(%) expected, % found: %."),
  /** Error code. */
  FUNCUP_X(XPTY, 4, "Function is updating: %."),
  /** Error code. */
  FUNCNOTUP_X(XPTY, 4, "Function is not updating: %."),
  /** Error code. */
  UNKNOWNOP_X(XPTY, 4, "Unknown operator: %."),
  /** Error code. */
  INVALIDOPTION_X_X_X_X(XPTY, 4, "Option %: % expected, % found: %."),
  /** Error code. */
  INVALIDOPTION_X_X_X(XPTY, 4, "Option: % expected, % found: %."),
  /** Error code. */
  INVALIDOPTION_X(XPTY, 4, "%"),
  /** Error code. */
  UNKNOWNOPTION_X(XPTY, 4, "Unknown option '%'."),

  /** Error code. */
  JAVANULL(XPTY, 17, "Java array contains null values."),
  /** Error code. */
  MIXEDRESULTS(XPTY, 18, "Path returns both nodes and non-nodes."),
  /** Error code. */
  PATHNODE_X_X_X(XPTY, 19, "%: node expected, % found: %."),
  /** Error code. */
  NSSENS_X_X(XPTY, 117, "Cannot convert % to %."),

  /** Error code. */
  CATTDUPL_X(XQDY, 25, "Duplicate attribute name: %."),
  /** Error code. */
  CPICONT_X(XQDY, 26, "Processing instruction has invalid content: '%'."),
  /** Error code. */
  CPIINVAL_X(XQDY, 41, "Processing instruction has invalid name: '%'."),
  /** Error code. */
  CAXML(XQDY, 44, "XML prefix and namespace cannot be rebound."),
  /** Error code. */
  CAINV_(XQDY, 44, "Invalid attribute prefix/namespace: %."),
  /** Error code. */
  CIRCVAR_X(XQDY, 54, "Static variable depends on itself: %"),
  /** Error code. */
  CIRCCTX(XQDY, 54, "Context value is not defined."),
  /** Error code. */
  CPIXML_X(XQDY, 64, "Processing instruction has illegal name: %."),
  /** Error code. */
  COMINVALID(XQDY, 72, "Comment must not contain '--' or end with '-'."),
  /** Error code. */
  INVNSPREFIX_X(XQDY, 74, "Invalid namespace prefix: %."),
  /** Error code. */
  INVQNAME_X(XQDY, 74, "Invalid QName: %."),
  /** Error code. */
  NOQNNAMENS_X(XQDY, 74, "Namespace prefix not declared: %."),
  /** Error code. */
  CEXML(XQDY, 96, "XML prefix or namespace cannot be rebound: %/%."),
  /** Error code. */
  CEINV_X(XQDY, 96, "Invalid element prefix/namespace: %."),
  /** Error code. */
  CNXML(XQDY, 101, "XML prefix and namespace cannot be rebound."),
  /** Error code. */
  CNINV_X(XQDY, 101, "Invalid namespace prefix: %."),
  /** Error code. */
  CNINVNS_X(XQDY, 101, "Invalid namespace URI: '%'."),
  /** Error code. */
  EMPTYNSCONS(XQDY, 102, "Element is in no namespace, no namespace can be assigned."),
  /** Error code. */
  DUPLNSCONS_X(XQDY, 102, "Duplicate declaration of namespace '%'."),
  /** Error code. */
  MAPDUPLKEY_X(XQDY, 137, "Map contains duplicate key: %."),

  /** Error code. */
  IMPLSCHEMA(XQST, 9, "No XML Schema support."),
  /** Error code. */
  NSCONS(XQST, 22, "Constant namespace value expected."),
  /** Error code. */
  XQUERYVER_X(XQST, 31, "XQuery version '%' not supported."),
  /** Error code. */
  DUPLBASE(XQST, 32, "Duplicate 'base-uri' declaration."),
  /** Error code. */
  DUPLNSDECL_X(XQST, 33, "Duplicate declaration of prefix '%'."),
  /** Error code. */
  DUPLFUNC_X(XQST, 34, "Duplicate declaration of function '%'."),
  /** Error code. */
  DUPLCOLL(XQST, 38, "Duplicate 'collation' declaration."),
  /** Error code. */
  WHICHDEFCOLL_X(XQST, 38, "%."),
  /** Error code. */
  FUNCDUPL_X(XQST, 39, "Duplicate parameter name: %."),
  /** Error code. */
  ATTDUPL_X(XQST, 40, "Duplicate attribute name: %."),
  /** Error code. */
  FNRESERVED_X(XQST, 45, "Function is in reserved namespace: %."),
  /** Error code. */
  ANNRESERVED_X(XQST, 45, "Annotation is in reserved namespace: %."),
  /** Error code. */
  TYPERESERVED_X(XQST, 45, "Type is in reserved namespace: %."),
  /** Error code. */
  INVURI_X(XQST, 46, "Invalid URI: %."),
  /** Error code. */
  DUPLMODULE_X(XQST, 47, "Module namespace is declared twice: %."),
  /** Error code. */
  MODULENS_X(XQST, 48, "Declaration % does not match the module namespace."),
  /** Error code. */
  VARDUPL_X(XQST, 49, "Duplicate declaration of static variable $%."),
  /** Error code. */
  WHICHCAST_X(XQST, 52, "Unknown type: %."),
  /** Error code. */
  DUPLCOPYNS(XQST, 55, "Duplicate 'copy-namespace' declaration."),
  /** Error code. */
  NSEMPTY(XQST, 57, "Namespace URI cannot be empty."),
  /** Error code. */
  WHICHMOD_X(XQST, 59, "Module not found: %."),
  /** Error code. */
  WHICHMODCLASS_X(XQST, 59, "Java class not found: %."),
  /** Error code. */
  MODINIT_X_X_X(XQST, 59, "Cannot initialize %: % (%)."),
  /** Error code. */
  MODINST_X_X(XQST, 59, "Cannot instantiate %: %."),
  /** Error code. */
  WHICHMODFILE_X(XQST, 59, "Cannot retrieve module: %."),
  /** Error code. */
  WRONGMODULE_X_X_X(XQST, 59, "Imported module '%' has unexpected namespace: '%' vs '%'."),
  /** Error code. */
  DUPLORD(XQST, 65, "Duplicate 'ordering' declaration."),
  /** Error code. */
  DUPLNS(XQST, 66, "Duplicate 'default namespace' declaration."),
  /** Error code. */
  DUPLCONS(XQST, 67, "Duplicate 'construction' declaration."),
  /** Error code. */
  DUPLBOUND(XQST, 68, "Duplicate 'boundary-space' declaration."),
  /** Error code. */
  DUPLORDEMP(XQST, 69, "Duplicate 'order empty' declaration."),
  /** Error code. */
  BINDXML_X(XQST, 70, "Prefix '%' cannot be rebound."),
  /** Error code. */
  XMLNSDEF_X(XQST, 70, "'%' cannot be default namespace."),
  /** Error code. */
  BINDXMLURI_X_X(XQST, 70, "'%' can only be bound to '%'."),
  /** Error code. */
  ILLEGALEQNAME_X(XQST, 70, "Illegal namespace: %."),
  /** Error code. */
  DUPLNSDEF_X(XQST, 71, "Duplicate declaration of prefix '%'."),
  /** Error code. */
  IMPLVAL(XQST, 75, "Validation not supported."),
  /** Error code. */
  FLWORCOLL_X(XQST, 76, "%."),
  /** Error code. */
  NOPRAGMA(XQST, 79, "Expecting pragma expression."),
  /** Error code. */
  NSEMPTYURI(XQST, 85, "Namespace URI cannot be empty."),
  /** Error code. */
  XQUERYENC2_X(XQST, 87, "%"),
  /** Error code. */
  NSMODURI(XQST, 88, "Module namespace cannot be empty."),
  /** Error code. */
  DUPLVAR_X(XQST, 89, "Duplicate declaration of %."),
  /** Error code. */
  INVCHARREF_X(XQST, 90, "Invalid XML 1.0 character: %."),
  /** Error code. */
  CIRCMODULE(XQST, 93, "Circular module declaration."),
  /** Error code. */
  GVARNOTDEFINED_X(XQST, 94, "Undeclared grouping variable: %."),
  /** Error code. */
  INVDECFORM_X_X(XQST, 97, "Invalid decimal-format property: %='%'."),
  /** Error code. */
  INVDECSINGLE_X_X(XQST, 97, "Decimal-format property must be a single character: %='%'."),
  /** Error code. */
  INVDECZERO_X(XQST, 97, "Zero-digit property is no Unicode digit with value zero: %."),
  /** Error code. */
  DUPLDECFORM_X(XQST, 98, "Decimal-format character is assigned twice: '%'."),
  /** Error code. */
  DUPLVALUE(XQST, 99, "Duplicate context value declaration."),
  /** Error code. */
  DUPLWIND_X(XQST, 103, "Duplicate declaration: %."),
  /** Error code. */
  DUPLUPD(XQST, 106, "More than one updating annotation declared."),
  /** Error code. */
  DUPLFUNVIS(XQST, 106, "More than one visibility annotation declared."),
  /** Error code. */
  OUTPUTLIB_X(XQST, 108, "Declaration not allowed in library module: output:%."),
  /** Error code. */
  OUTPUT_X(XQST, 109, "%"),
  /** Error code. */
  OUTDUPL_X(XQST, 110, "Duplicate declaration: output:%."),
  /** Error code. */
  DECDUPL(XQST, 111, "Duplicate decimal-format declaration."),
  /** Error code. */
  DECITEM(XQST, 113, "Context value cannot be bound in library module."),
  /** Error code. */
  DECDUPLPROP_X(XQST, 114, "Property is defined twice: %."),
  /** Error code. */
  DUPLVARVIS(XQST, 116, "More than one visibility annotation declared."),
  /** Error code. */
  TAGWRONG_X_X(XQST, 118, "Different start and end tag: <%>...</%>."),
  /** Error code. */
  PARAMDOC_X(XQST, 119, "Parameter document: %."),
  /** Error code. */
  NOVISALLOWED(XQST, 125, "No visibility annotation allowed in inline function."),
  /** Error code. */
  NSAXIS(XQST, 134, "Namespace axis is not supported."),
  /** Error code. */
  DUPLTYPE_X(XQST, 146, "Duplicate declaration of type %."),
  /** Error code. */
  PARAMOPTIONAL_X(XQST, 148, "Parameter must be declared as optional: $%."),

  /** Error code. */
  NOATTALL_X(XQTY, 24, "Attribute does not follow root element: %."),
  /** Error code. */
  NONSALL_X(XQTY, 24, "Namespaces does not follow root element: %."),
  /** Error code. */
  CONSFUNC_X(XQTY, 105, "Invalid content: %."),
  /** Error code. */
  FINALLY_X(XQTY, 153, "Finally must not return a result: %."),

  /** Error code. */
  UPNOPAR_X(XUDY, 9, "Target has no parent: %."),
  /** Error code. */
  UPNOTCOPIED_X(XUDY, 14, "Node was not created by transform expression: %."),
  /** Error code. */
  UPMULTREN_X(XUDY, 15, "Node can only be renamed once: %."),
  /** Error code. */
  UPPATHREN_X(XUDY, 15, "Path can only be renamed once: %."),
  /** Error code. */
  UPMULTREPL_X(XUDY, 16, "Node can only be replaced once: %."),
  /** Error code. */
  UPMULTDOC_X_X(XUDY, 16, "Documents in path '%/%' can only be replaced once."),
  /** Error code. */
  UPMULTREPV_X(XUDY, 17, "Node can only be replaced once: %."),
  /** Error code. */
  UPATTDUPL_X(XUDY, 21, "Duplicate attribute name: %."),
  /** Error code. */
  UPNSCONFL_X_X(XUDY, 23, "Namespace conflicts: % vs. %."),
  /** Error code. */
  UPNSCONFL2_X_X(XUDY, 24, "Namespaces conflicts: % vs. %."),
  /** Error code. */
  UPPAREMPTY_X(XUDY, 29, "Target has no parent: %."),
  /** Error code. */
  UPATTELM_X(XUDY, 30, "Attribute cannot be added to %."),
  /** Error code. */
  UPURIDUP_X(XUDY, 31, "URI '%' is addressed multiple times."),

  /** Error code. */
  UPNOT_X(XUST, 1, "%: no updating expression allowed."),
  /** Error code. */
  UPALL(XUST, 1, "Expressions must all be updating or return an empty sequence."),
  /** Error code. */
  UPCTX(XUST, 1, "Context value may not declare an updating expression."),

  /** Error code. */
  UPMODIFY(XUST, 2, "Transformations must all be updating or return an empty sequence."),
  /** Error code. */
  UPEXPECTF(XUST, 2, "Expressions must all be updating or return an empty sequence."),
  /** Error code. */
  DUPLREVAL(XUST, 3, "Duplicate 'revalidation' declaration."),
  /** Error code. */
  NOREVAL(XUST, 26, "Revalidation mode not supported."),
  /** Error code. */
  UUPFUNCTYPE(XUST, 28, "No return type allowed in updating functions."),

  /** Error code. */
  UPNOATTRPER_X(XUTY, 4, "Attribute does not follow root element: %."),
  /** Error code. */
  UPTRGTYP_X(XUTY, 5, "Target is not an element or document: %."),
  /** Error code. */
  UPTRGTYP2_X(XUTY, 6, "Target is not an element, text, comment or pi: %."),
  /** Error code. */
  UPTRGDELEMPT_X(XUTY, 7, "Target is not a node: %."),
  /** Error code. */
  UPTRGNODE_X(XUTY, 8, "Target is not an element, text, attribute, comment or pi: %."),
  /** Error code. */
  UPWRELM_X(XUTY, 10, "Node cannot be replaced with attribute: %."),
  /** Error code. */
  UPWRATTR_X(XUTY, 11, "Target is no attribute: %."),
  /** Error code. */
  UPWRTRGTYP_X(XUTY, 12, "Target is not an element, attribute or pi: %."),
  /** Error code. */
  UPSOURCE_X(XUTY, 13, "Source is not a node: %."),
  /** Error code. */
  UPSINGLE_X_X(XUTY, 13, "Value of $% is not a single node: %."),
  /** Error code. */
  UPATTELM2_X(XUTY, 22, "Attribute cannot be added to %.");

  /** Error URI. */
  private final byte[] uri;
  /** Error prefix. */
  private final String prefix;
  /** Error code. */
  private final String code;
  /** Error message. */
  private final String message;

  /**
   * Constructor.
   * @param type error type
   * @param code error code
   * @param message message
   */
  QueryError(final ErrType type, final String code, final String message) {
    this.code = code;
    this.message = message;
    uri = type.uri;
    prefix = type.prefix;
  }

  /**
   * Constructor.
   * @param type error type
   * @param number error number
   * @param message message
   */
  QueryError(final ErrType type, final int number, final String message) {
    final String n = Integer.toString(number);
    code = type + "0".repeat(4 - n.length()) + n;
    uri = type.uri;
    prefix = type.prefix;
    this.message = message;
  }

  /**
   * Returns a query exception. If {@link InputInfo#internal()} returns {@code true},
   * a static error instance ({@link QueryException#ERROR}) will be returned.
   * @param info input info (can be {@code null})
   * @param ext extended info
   * @return query exception
   */
  public QueryException get(final InputInfo info, final Object... ext) {
    return info != null && info.internal() ? QueryException.ERROR :
      new QueryException(info, this, ext);
  }

  /**
   * Returns a query I/O exception without {@link InputInfo} reference.
   * @param ext extended info
   * @return query I/O exception
   */
  public QueryIOException getIO(final Object... ext) {
    return new QueryIOException(get(null, ext));
  }

  /**
   * Checks if the error code equals the specified QName.
   * @param name name to compare
   * @return result of check
   */
  public final boolean eq(final QNm name) {
    return Token.eq(name.uri(), uri) && Token.eq(name.local(), Token.token(code));
  }

  /**
   * Error types.
   * @author BaseX Team, BSD License
   * @author Leo Woerteler
   */
  public enum ErrType {
    // Project-specific errors

    /** Error type. */ ADMIN(ADMIN_PREFIX,       ADMIN_URI),
    /** Error type. */ BASEX(BASEX_PREFIX,       BASEX_URI),
    /** Error type. */ ARCHIVE(ADMIN_PREFIX,     ARCHIVE_URI),
    /** Error type. */ CLIENT(CLIENT_PREFIX,     CLIENT_URI),
    /** Error type. */ CONVERT(CONVERT_PREFIX,   CONVERT_URI),
    /** Error type. */ CSV(CSV_PREFIX,           CSV_URI),
    /** Error type. */ DB(DB_PREFIX,             DB_URI),
    /** Error type. */ FETCH(FETCH_PREFIX,       FETCH_URI),
    /** Error type. */ FT(FT_PREFIX,             FT_URI),
    /** Error type. */ INSPECT(INSPECT_PREFIX,   INSPECT_URI),
    /** Error type. */ JOB(JOB_PREFIX,           JOB_URI),
    /** Error type. */ JSON(JSON_PREFIX,         JSON_URI),
    /** Error type. */ PROC(PROC_PREFIX,         PROC_URI),
    /** Error type. */ RANDOM(RANDOM_PREFIX,     RANDOM_URI),
    /** Error type. */ REPO(REPO_PREFIX,         REPO_URI),
    /** Error type. */ REQUEST(REQUEST_PREFIX,   REQUEST_URI),
    /** Error type. */ SESSIONS(SESSIONS_PREFIX, SESSIONS_URI),
    /** Error type. */ SQL(SQL_PREFIX,           SQL_URI),
    /** Error type. */ STORE(STORE_PREFIX,       STORE_URI),
    /** Error type. */ STRING(STRING_PREFIX,     STRING_URI),
    /** Error type. */ UNIT(UNIT_PREFIX,         UNIT_URI),
    /** Error type. */ USER(USER_PREFIX,         USER_URI),
    /** Error type. */ VALIDATE(VALIDATE_PREFIX, VALIDATE_URI),
    /** Error type. */ WEB(WEB_PREFIX,           WEB_URI),
    /** Error type. */ WS(WS_PREFIX,             WS_URI),
    /** Error type. */ XQUERY(XQUERY_PREFIX,     XQUERY_URI),
    /** Error type. */ XSLT(XSLT_PREFIX,         XSLT_URI),

    // EXPath errors

    /** Error type. */ BIN(BIN_PREFIX,    BIN_URI),
    /** Error type. */ CX(EXPERR_PREFIX,  EXPERROR_URI),
    /** Error type. */ FILE(FILE_PREFIX,  FILE_URI),
    /** Error type. */ HC(EXPERR_PREFIX,  EXPERROR_URI),

    // W3 errors

    /** Error type. */ FOAP,
    /** Error type. */ FOAR,
    /** Error type. */ FOAY,
    /** Error type. */ FOCA,
    /** Error type. */ FOCH,
    /** Error type. */ FOCV,
    /** Error type. */ FODC,
    /** Error type. */ FODF,
    /** Error type. */ FODT,
    /** Error type. */ FOFD,
    /** Error type. */ FOER,
    /** Error type. */ FOHA,
    /** Error type. */ FOIX,
    /** Error type. */ FOJS,
    /** Error type. */ FONS,
    /** Error type. */ FOPA,
    /** Error type. */ FORG,
    /** Error type. */ FOQM,
    /** Error type. */ FORX,
    /** Error type. */ FOTY,
    /** Error type. */ FOUP,
    /** Error type. */ FOUR,
    /** Error type. */ FOUT,
    /** Error type. */ FTDY,
    /** Error type. */ FTST,
    /** Error type. */ SENR,
    /** Error type. */ SEPM,
    /** Error type. */ SERE,
    /** Error type. */ SESU,
    /** Error type. */ XPDY,
    /** Error type. */ XPST,
    /** Error type. */ XPTY,
    /** Error type. */ XQDY,
    /** Error type. */ XQST,
    /** Error type. */ XQTY,
    /** Error type. */ XUDY,
    /** Error type. */ XUST,
    /** Error type. */ XUTY;

    /** This error type's prefix. */
    public final String prefix;
    /** This error type's URI. */
    public final byte[] uri;

    /**
     * Constructor for non-standard errors.
     * @param prefix QName prefix
     * @param uri error URI
     */
    ErrType(final byte[] prefix, final byte[] uri) {
      this.prefix = Token.string(prefix);
      this.uri = uri;
    }

    /**
     * Constructor for standard XQuery errors. The prefix is {@code err}, the URI is
     * {@code http://www.w3.org/2005/xqt-errors}.
     */
    ErrType() {
      this(ERR_PREFIX, ERROR_URI);
    }
  }

  /**
   * Returns the namespace URI of this error.
   * @return function
   */
  public final QNm qname() {
    return new QNm(Token.token(prefix), code, uri);
  }

  /**
   * Returns the error message.
   * @return message
   */
  public final String message() {
    return message;
  }

  /**
   * Returns an error for the specified name.
   * @param name error name
   * @param msg error message
   * @param info input info (can be {@code null})
   * @return exception or {@code null}
   */
  public static QueryException get(final String name, final String msg, final InputInfo info) {
    final QueryError err = Enums.get(QueryError.class, name);
    return err != null ? new QueryException(info, err.qname(), msg).error(err) : null;
  }

  /**
   * Returns a comparison exception.
   * @param item1 first item
   * @param item2 second item
   * @param info input info (can be {@code null})
   * @return query exception
   */
  public static QueryException compareError(final Item item1, final Item item2,
      final InputInfo info) {
    final Type type1 = item1.type, type2 = item2.type;
    return type1.eq(type2) ? CMPTYPE_X_X_X.get(info, type1, item1, item2) :
      CMPTYPES_X_X_X_X.get(info, type1, type2, item1, item2);
  }

  /**
   * Returns a type exception.
   * @param value value
   * @param type expected type
   * @param info input info (can be {@code null})
   * @return query exception
   */
  public static QueryException typeError(final Value value, final Type type, final InputInfo info) {
    return typeError(value, type.seqType(), info);
  }

  /**
   * Returns a type exception.
   * @param expr expression
   * @param st expected type
   * @param info input info (can be {@code null})
   * @return query exception
   */
  public static QueryException typeError(final Expr expr, final SeqType st, final InputInfo info) {
    return typeError(expr, st, null, info);
  }

  /**
   * Returns a type exception.
   * @param expr expression
   * @param st expected type
   * @param name name (can be {@code null})
   * @param info input info (can be {@code null})
   * @return query exception
   */
  public static QueryException typeError(final Expr expr, final SeqType st, final QNm name,
      final InputInfo info) {
    return typeError(st, expr.seqType(), expr, name, info);
  }

  /**
   * Returns a type exception.
   * @param est expected type
   * @param ist type of the input expression
   * @param expr expression (can be {@code null})
   * @param name name (can be {@code null})
   * @param info input info (can be {@code null})
   * @return query exception
   */
  public static QueryException typeError(final SeqType est, final SeqType ist, final Expr expr,
      final QNm name, final InputInfo info) {

    final TokenBuilder desc = new TokenBuilder();
    if(ist.occ.instanceOf(est.occ)) {
      // cardinality matches, focus on type:
      desc.add(est.occ == Occ.EXACTLY_ONE ? "Item" : "Value");
      desc.add(" of type ").add(est).add(" expected, ");
      // try to find missing record entry:
      boolean missing = false;
      if(est.type instanceof final RecordType rt && expr instanceof final XQMap map) {
        final TokenObjectMap<RecordField> fields = rt.fields();
        for(final byte[] key : fields) {
          if(map.value(Str.get(key)) != null || fields.get(key).isOptional()) continue;
          desc.add(QueryString.toQuoted(key)).add(" missing");
          missing = true;
          break;
        }
      }
      if(!missing) desc.add(ist).add(" found");
    } else {
      // add cardinality string
      desc.add(Strings.capitalize(est.occ.desc)).add(" expected");
      // add expected type if item type differs from input
      if(!ist.type.instanceOf(est.type)) {
        desc.add(" (").add(est).add(")");
      }
      // add number of results or type of input
      if(expr != null) {
        desc.add(", ");
        if(expr instanceof final Value value) desc.add(value.size());
        else desc.add(expr.seqType());
        desc.add(" found");
      }
    }
    // add input (variable, expression)
    if(name != null || !ist.eq(Types.EMPTY_SEQUENCE_Z)) {
      desc.add(": ");
      if(name != null) desc.add(name.varString());
      if(expr != null) {
        if(name != null) desc.add(" := ");
        desc.add(expr.toErrorString());
      }
    }
    return INVTYPE_X.get(info, desc);
  }

  /**
   * Returns an arity exception.
   * @param info input info (can be {@code null})
   * @param expr expression
   * @param supplied expected arity
   * @param expected supplied arity
   * @param param parameter/argument flag
   * @return query exception
   */
  public static QueryException arityError(final Expr expr, final int supplied, final int expected,
      final boolean param, final InputInfo info) {
    final String input = param ? "Function with " + parameters(supplied) : arguments(supplied);
    final String arity = arity(input, new IntList().add(expected));
    return INVARITY_X_X.get(info, arity, expr);
  }

  /**
   * Returns a test exception.
   * @param value value
   * @param pos positional predicate
   * @param info input info (can be {@code null})
   * @return query exception
   */
  public static QueryException testError(final Value value, final boolean pos,
      final InputInfo info) {
    final String expected, found;
    final Type type = value.seqType().type;
    if(type.instanceOf(BasicType.NUMERIC) || type.instanceOf(BasicType.STRING) ||
        type.oneOf(BasicType.BOOLEAN, BasicType.ANY_URI)) {
      expected = "Single " + type;
      found = "sequence";
    } else if(pos) {
      expected = "Numbers";
      found = value.itemAt(value.size() - 1).seqType().toString();
    } else {
      expected = "Number, string, boolean, URI or nodes";
      found = value.itemAt(0).seqType().toString();
    }
    return ARGTYPE_X_X_X.get(info, expected, found, value);
  }

  /**
   * Returns a number exception.
   * @param expr parsing expression
   * @param item item
   * @return query exception
   */
  public static QueryException numberError(final ParseExpr expr, final Item item) {
    return NONUMBER_X_X.get(expr.info(), item.type, item);
  }

  /**
   * Returns an invalid value exception.
   * @param type expected type
   * @param value value
   * @param info input info (can be {@code null})
   * @return query exception
   */
  public static QueryException valueError(final Type type, final byte[] value,
      final InputInfo info) {
    return INVALUE_X_X.get(info, type, value);
  }

  /**
   * Returns a singular or plural form for 'argument'.
   * @param number number of arguments
   * @return string
   */
  public static String arguments(final long number) {
    return number + " " + Strings.plural("argument", number);
  }

  /**
   * Returns a singular or plural form for 'argument'.
   * @param number number of parameters
   * @return string
   */
  public static String parameters(final long number) {
    return number + " " + Strings.plural("parameter", number);
  }

  /**
   * Returns an information string for the supplied input and the expected arity.
   * @param supplied arguments
   * @param arities allowed arities (if single arity is negative, function is variadic)
   * @return string
   */
  public static String arity(final String supplied, final IntList arities) {
    final String expected;
    final int as = arities.ddo().size();
    if(as == 1 && arities.peek() < 0) {
      expected = "at least " + -arities.peek();
    } else {
      int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
      for(int a = 0; a < as; a++) {
        final int m = arities.get(a);
        if(m < min) min = m;
        if(m > max) max = m;
      }
      final TokenBuilder tb = new TokenBuilder();
      if(as > 2 && max - min + 1 == as) {
        tb.addInt(min).add('-').addInt(max);
      } else {
        for(int a = 0; a < as; a++) {
          if(a != 0) tb.add(a + 1 < as ? ", " : " or ");
          tb.addInt(arities.get(a));
        }
      }
      expected = tb.toString();
    }
    return Util.info("% supplied, % expected", supplied, expected);
  }

  /**
   * Returns an info message for similar strings.
   * @param string original string
   * @param similar similar string (can be {@code null})
   * @return info message
   */
  public static String similar(final Object string, final Object similar) {
    return similar == null ? Util.info(string) : Util.info("% (maybe: %)", string, similar);
  }

  /**
   * Removes whitespace and chops the specified value to a maximum size.
   * @param value value
   * @param info input info (can be {@code null}; an empty token will be returned if
   * {@link InputInfo#internal()} returns {@code true})
   * @return chopped or empty token
   */
  public static byte[] normalize(final Object value, final InputInfo info) {
    if(info != null && info.internal()) return Token.EMPTY;

    final TokenBuilder tb = new TokenBuilder();
    int last = 0, c = 0;
    for(final TokenParser tp = new TokenParser(Token.token(value)); tp.more();) {
      if(c == 200) {
        tb.add(QueryText.DOTS);
        break;
      }
      final int cp = Math.max(tp.next(), ' ');
      if(cp != ' ' || last != ' ') {
        tb.add(cp);
        c++;
      }
      last = cp;
    }
    return tb.finish();
  }

  @Override
  public String toString() {
    return code;
  }
}
