PHP Luminova: Exception and Error Codes
Reference of built-in Luminova exception and error codes, including PHP, PDO SQLSTATE, MySQL, PostgreSQL, and custom application errors, with their descriptions, severity levels, and usage.
Luminova Error Codes are predefined identifiers used to classify errors, describe their severity, and provide consistent error handling across applications.
All error codes are defined as constants in the Luminova\Exceptions\ErrorCode class and cover the following categories:
- PHP error levels
- PDO SQLSTATE errors
- MySQL errors
- PostgreSQL errors
- SQLite errors
- Custom application errors
Class Definition
- Class namespace:
Luminova\Exceptions\ErrorCode
Using Error Codes
You can pass an error code when throwing exceptions.
use Luminova\Exceptions\ErrorCode;
use Luminova\Exceptions\RuntimeException;
throw new RuntimeException('Error message', ErrorCode::BAD_METHOD_CALL);Every Luminova exception accepts a string|int code as its second argument and falls back to its own default code when you omit it. See Default Exception Codes.
getName
Get a Human-Friendly Error Name
Translate internal error codes into descriptive names that are easier to understand.
public static function getName(string|int $severity, bool $long = false): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$severity | string|int | The error/exception code to get readable name. |
$long | bool | If true, returns the long descriptive name, otherwise returns the short name. |
Return:
string - Return the corresponding error name for the given code.
use Luminova\Exceptions\ErrorCode;
echo ErrorCode::getName(ErrorCode::INPUT_VALIDATION_ERROR);
// Output: Validation ErrorYou can also ask for a longer description:
use Luminova\Exceptions\ErrorCode;
echo ErrorCode::getName(ErrorCode::INPUT_VALIDATION_ERROR, true);
// Output: The provided input failed validationIf the code is not recognized, the short name is Unknown error and the long description is Unknown error code.
This is especially helpful when displaying error messages to developers or when logging meaningful details.
Codes are matched strictly by type and value. Pass
'08001'as a string and1500as an integer, exactly as the constants are defined. A PDO SQLSTATE such as'23000'returned as a string will not match23000, if it's an integer.
has
Check if a given error code is recognized by Luminova.
public static function has(string|int $severity): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$severity | string|int | The error or exception code to check. |
Return:
bool - Returns true if the code is recognized, otherwise false.
use Luminova\Exceptions\ErrorCode;
ErrorCode::has(ErrorCode::ERROR);A false result does not necessarily mean the code is invalid, only that Luminova does not recognize it. The same strict matching rules as getName apply.
isFatal
Check if an error code is fatal. Fatal errors are unrecoverable and halt script execution.
public static function isFatal(string|int $severity): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$severity | string|int | PHP error severity level (E_* constant). |
Return:
bool - Return true if the error is fatal, false otherwise.
use Luminova\Exceptions\ErrorCode;
ErrorCode::isFatal(ErrorCode::PARSE_ERROR); // true
ErrorCode::isFatal(ErrorCode::WARNING); // falseThe following codes are treated as fatal:
ErrorCode::ERRORErrorCode::PARSE_ERRORErrorCode::CORE_ERRORErrorCode::COMPILE_ERRORErrorCode::USER_ERRORErrorCode::CONNECTION_ERROR
The comparison is strict, so the code must have the same type as the constant.
getLevel
Get the log level used for an error code.
public static function getLevel(string|int $severity): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$severity | string|int | The error code or type. |
Return:
string - Return error log level by error code.
use Luminova\Exceptions\ErrorCode;
$level = ErrorCode::getLevel(ErrorCode::DATABASE_ERROR);The level is resolved from the logger. If the code cannot be resolved, error is returned.
Constants
All error codes are centralized in the ErrorCode class.Reference them directly whenever you need to identify or classify an error:
Luminova\Exceptions\ErrorCode::ERROR;PHP Error Codes
These constants map directly to standard PHP error types. You can use them for handling, logging, or categorizing errors in your application.
| Constant | Value | Description |
|---|---|---|
ERROR | E_ERROR | Fatal run-time errors. |
PARSE_ERROR | E_PARSE | Compile-time parse errors. |
CORE_ERROR | E_CORE_ERROR | Fatal errors that occur during PHP's initial startup. |
COMPILE_ERROR | E_COMPILE_ERROR | Fatal compile-time errors. |
WARNING | E_WARNING | Run-time warnings (non-fatal errors). |
CORE_WARNING | E_CORE_WARNING | Warnings that occur during PHP's initial startup. |
COMPILE_WARNING | E_COMPILE_WARNING | Compile-time warnings. |
USER_WARNING | E_USER_WARNING | User-generated warnings. |
NOTICE | E_NOTICE | Run-time notices (non-critical errors). |
USER_NOTICE | E_USER_NOTICE | User-generated notices. |
USER_ERROR | E_USER_ERROR | User-generated fatal errors. |
RECOVERABLE_ERROR | E_RECOVERABLE_ERROR | Errors that can be caught by a catch block. |
DEPRECATED | E_DEPRECATED | Notices of deprecated features. |
USER_DEPRECATED | E_USER_DEPRECATED | User-generated notices of deprecated features. |
Database Error Codes
PDO SQLSTATE Codes
These constants map to SQLSTATE error codes used by PDO. They help you detect and handle database connection problems or SQL execution errors more precisely.
| Constant | Value | Description |
|---|---|---|
UNABLE_TO_CONNECT | '08001' | Unable to connect to the database. |
CONNECTION_DENIED | '08004' | Connection denied due to invalid credentials. |
CONNECTION_ERROR | 2002 | Server unavailable, connection refused, or the socket file is missing. |
INTEGRITY_CONSTRAINT_VIOLATION | '23000' | Integrity constraint violation, such as foreign key issues. |
SQL_SYNTAX_ERROR_OR_ACCESS_VIOLATION | '42000' | SQL syntax error or access violation. |
MySQL Error Codes
These constants correspond to common MySQL error codes. They allow you to handle database issues specific to MySQL, such as duplicate entries, missing tables, or connection problems.
| Constant | Value | Description |
|---|---|---|
ACCESS_DENIED_FOR_USER | 1044 | Access denied for the user. |
ACCESS_DENIED_INVALID_PASSWORD | 1045 | Access denied due to invalid password. |
UNKNOWN_DATABASE | 1049 | Unknown database specified in the connection. |
SYNTAX_ERROR_IN_SQL_STATEMENT | 1064 | Syntax error in SQL statement. |
TABLE_DOES_NOT_EXIST | 1146 | The specified table does not exist. |
PostgreSQL Error Codes
These constants represent PostgreSQL-specific error codes. They are useful when handling authentication errors, missing databases, or other PostgreSQL issues.
| Constant | Value | Description |
|---|---|---|
INVALID_AUTHORIZATION_SPECIFICATION | '28000' | The authorization specification is invalid. |
INVALID_CATALOG_NAME | '3D000' | The specified database name is invalid. |
SQLite Error Codes
These constants represent SQLite-specific error codes. They are useful when handling storage, locking, or database file issues.
| Constant | Value | Description |
|---|---|---|
DATABASE_STORAGE_FULL | 5 | The database has run out of storage space. |
DATABASE_LOCKED | 6 | The database file is locked. |
CANNOT_OPEN_DATABASE_FILE | 14 | The database file could not be opened. |
Custom Luminova Error Codes
These constants are unique to the Luminova framework. They provide a standardized way to represent application-specific errors that go beyond PHP or database engine codes. You can use them to handle issues such as database failures, validation problems, or other framework-level exceptions in a consistent way.
Database
| Constant | Value | Description |
|---|---|---|
DATABASE_ERROR | 1500 | General database error. |
DATABASE_PERMISSION_DENIED | 13 | Database operation denied due to insufficient permissions. |
FAILED_ALL_CONNECTION_ATTEMPTS | 1503 | Failed all attempts to connect to the database. |
CONNECTION_LIMIT_EXCEEDED | 1509 | Connection limit exceeded. |
INVALID_DATABASE_DRIVER | 1406 | Invalid database driver specified. |
DATABASE_DRIVER_NOT_AVAILABLE | 1501 | Database driver not available. |
DATABASE_TRANSACTION_READONLY_FAILED | 1417 | Failed to execute a read-only transaction. |
DATABASE_TRANSACTION_FAILED | 1420 | Database transaction failed. |
TRANSACTION_SAVEPOINT_FAILED | 1418 | Failed to create a transaction savepoint. |
FAILED_TO_ROLLBACK_TRANSACTION | 1419 | Failed to rollback the transaction. |
NO_STATEMENT_TO_EXECUTE | 1499 | No SQL statement to execute. |
EXECUTION_FAILED | 1510 | The requested operation could not be completed. |
General
| Constant | Value | Description |
|---|---|---|
VALUE_FORBIDDEN | 1403 | Forbidden value encountered. |
INVALID_ARGUMENTS | 1001 | Invalid arguments provided to a function. |
INVALID | 1002 | General invalid error. |
INVALID_CONTROLLER | 1003 | Invalid controller specified. |
RUNTIME_ERROR | 5001 | General runtime error. |
CLASS_NOT_FOUND | 5011 | Class not found during execution. |
INPUT_VALIDATION_ERROR | 4070 | Input validation error occurred. |
LOGIC_ERROR | 4229 | Logical error in the application. |
SECURITY_ISSUE | 4973 | Security issue detected. |
AI_AGENT_ERROR | 153 | Error while processing an AI agent request. |
UNDEFINED | 8790 | Undefined error occurred. |
Routing and Templates
| Constant | Value | Description |
|---|---|---|
VIEW_NOT_FOUND | 4041 | The requested view could not be found. |
ROUTING_ERROR | 4161 | Error in routing the request. |
NOT_FOUND | 4040 | Requested resource not found. |
BAD_METHOD_CALL | 4051 | Method call failed due to invalid parameters. |
INVALID_METHOD | 4052 | Invalid method specified. |
INVALID_REQUEST_METHOD | 4053 | Invalid request method used. |
NOT_ALLOWED | 4061 | Operation not allowed. |
NOT_SUPPORTED | 4062 | Operation not supported. |
Filesystem and Storage
| Constant | Value | Description |
|---|---|---|
IO_ERROR | 4080 | An input/output operation failed. |
STORAGE_ERROR | 5079 | General storage error. |
FILESYSTEM_ERROR | 6204 | Filesystem error encountered. |
PERMISSION_DENIED | 6201 | Read, write, or execute access was denied. |
WRITE_PERMISSION_DENIED | 6205 | Denied write permission. |
READ_PERMISSION_DENIED | 6206 | Denied read permission. |
EXECUTE_PERMISSION_DENIED | 6209 | Denied execute permission. |
CREATE_DIR_FAILED | 6207 | Failed to create a directory. |
SET_PERMISSION_FAILED | 6208 | Failed to set permissions on a file/directory. |
Services and Utilities
| Constant | Value | Description |
|---|---|---|
CACHE_ERROR | 5071 | Error related to caching. |
COOKIE_ERROR | 4961 | Error related to cookies. |
DATETIME_ERROR | 2306 | Error in date/time operations. |
CRYPTOGRAPHY_ERROR | 3423 | Error related to cryptographic operations. |
JSON_ERROR | 4180 | JSON encoding/decoding error. |
MAILER_ERROR | 449 | Error related to mailer functionality. |
Process Control
| Constant | Value | Description |
|---|---|---|
TERMINATE | 1200 | The process was terminated. |
TIMEOUT_ERROR | 1201 | The operation exceeded its allowed execution time. |
PROCESS_ERROR | 1202 | A process execution error occurred. |
TERMINATED | 10001 | The operation was manually terminated. |
HTTP
| Constant | Value | Description |
|---|---|---|
HTTP_CLIENT_ERROR | 4974 | Client error occurred during an HTTP request. |
HTTP_CONNECTION_ERROR | 4975 | Connection error during HTTP request. |
HTTP_REQUEST_ERROR | 4976 | Error during HTTP request processing. |
HTTP_SERVER_ERROR | 4977 | Server error occurred while processing HTTP request. |
HTTP_RESPONSE_ERROR | 4978 | HTTP response error occurred while processing request. |
Default Exception Codes
Each exception class in Luminova\Exceptions uses a default code when you do not pass one.
| Exception | Default Code |
|---|---|
AIAgentException | AI_AGENT_ERROR |
BadMethodCallException | BAD_METHOD_CALL |
CacheException | CACHE_ERROR |
ClassException | CLASS_NOT_FOUND |
CookieException | COOKIE_ERROR |
DatabaseException | DATABASE_ERROR |
DatabaseLimitException | CONNECTION_LIMIT_EXCEEDED |
DateTimeException | DATETIME_ERROR |
EncryptionException | CRYPTOGRAPHY_ERROR |
ErrorException | ERROR |
FileException | FILESYSTEM_ERROR |
InvalidArgumentException | INVALID_ARGUMENTS |
InvalidException | INVALID |
InvalidObjectException | INVALID |
IOException | IO_ERROR |
JsonException | JSON_ERROR |
LogicException | LOGIC_ERROR |
MailerException | MAILER_ERROR |
NotFoundException | NOT_FOUND |
RouterException | ROUTING_ERROR |
RuntimeException | RUNTIME_ERROR |
SecurityException | SECURITY_ISSUE |
StorageException | STORAGE_ERROR |
UnexpectedValueException | VALUE_FORBIDDEN |
ValidationException | INPUT_VALIDATION_ERROR |
ViewNotFoundException | VIEW_NOT_FOUND |
The HTTP exceptions in Luminova\Exceptions\Http follow the same pattern.
| Exception | Default Code |
|---|---|
ClientException | HTTP_CLIENT_ERROR |
ConnectException | HTTP_CONNECTION_ERROR |
RequestException | HTTP_REQUEST_ERROR |
ResponseException | HTTP_RESPONSE_ERROR |
ServerException | HTTP_SERVER_ERROR |
HttpException is different. Its code is the HTTP status code (default 500), and an invalid status falls back to 500.
FileException also provides static helpers that set a more specific code: handleFile() uses WRITE_PERMISSION_DENIED, handleReadFile() uses READ_PERMISSION_DENIED, handleDirectory() uses CREATE_DIR_FAILED, and handlePermission() uses SET_PERMISSION_FAILED.