EDBMMErrorCodes

Central error code constants, structured error type, and exception class shared by all library units (EDBMMClient, EDBMMHttp, EDBMMUtils).

Add EDBMMErrorCodes to your uses clause when your code checks specific EC_* constants directly (e.g. if Script.LastError.Code = EC_HTTP_TIMEOUT then ...). The TAppError type itself is visible through EDBMMClient without explicitly listing this unit.


Contents

Name Kind
EC_* constants Integer constants
TAppError Record
EAppError Exception class
AppErrorMsg Function

## Error Code Ranges

Range Source
0 No error (EC_NONE)
1000–1999 PHP API (EC_PHP_*)
2000–2999 MySQL / MariaDB engine (EC_MYSQL_*)
3000–3999 ElevateDB engine (EC_EDB_*)
4000–4999 HTTP transport layer (EC_HTTP_*)
5000–5999 Internal serialisation utilities (EC_UTILS_*)
6000–6999 EDBMMClient library (EC_CLIENT_*)
7000–7999 URESTPipeline / SQL Console (EC_PIPELINE_*)
8000–8999 EDB2MySQL application (EC_APP_*)

The most commonly encountered constants in library use:

Constant Code Meaning
EC_NONE 0 No error; default-initialised TAppError
EC_PHP_UNAUTHORIZED 1004 Wrong or missing API key
EC_PHP_MEMORY_EXHAUSTED 1018 PHP memory_limit exceeded
EC_HTTP_CONNECTION 4001 Network connection failure
EC_HTTP_TIMEOUT 4002 HTTP request timed out
EC_HTTP_NON_JSON 4004 Non-JSON response (unclassified)
EC_CLIENT_NO_CONNECTION 6001 No TMMConnection assigned
EC_CLIENT_SCRIPT_EXEC 6005 script_run failed
EC_CLIENT_CANCELLED 6012 Cancel was called
EC_CLIENT_BLOB_CHUNK 6017 blob_chunk upload failed

The full list of EC_* constants is in the unit source. Each constant has a corresponding EM_* message template used internally when building TAppError values; EM_* templates are also declared in the unit but not normally referenced directly in application code.


## TAppError

TAppError = record
  Code      : Integer;  // EC_* constant; 0 = no error
  Msg       : string;   // human-readable description
  NativeCode: Integer;  // original engine error number (MySQL/EDB); 0 = n/a
  NativeMsg : string;   // original engine error message; '' = n/a

  function IsError: Boolean;  // True when Code <> 0

  class function Make(ACode: Integer; const AMsg: string;
    ANativeCode: Integer = 0; const ANativeMsg: string = ''): TAppError; static;

  class function MakeFmt(ACode: Integer; const Args: array of const;
    ANativeCode: Integer = 0; const ANativeMsg: string = ''): TAppError; static;

  class function FromException(ACode: Integer; E: Exception;
    ANativeCode: Integer = 0): TAppError; static;
end;

Value type (record). A default-initialised TAppError (all fields zero / empty) represents the absence of an error: IsError returns False and Code = EC_NONE.

NativeCode / NativeMsg are populated for MySQL (2xxx) and ElevateDB (3xxx) errors only; zero / empty for all other ranges.

Member Description
IsError Returns True when Code <> 0
Make Build from explicit code, message, and optional native error info
MakeFmt Build from a code and Format()-style arguments applied to the EM_* template
FromException Build from a caught exception: Msg := E.Message, Code := ACode

TAppError is exposed as a read-only property on all three classes: TMMConnection (via TMMHttpClient.LastError), TMMScript.LastError, TMMUpdater.LastError, and TMMUpdater.PrefetchError.


## EAppError

EAppError = class(Exception)
  constructor Create(const AError: TAppError); overload;
  constructor CreateCode(ACode: Integer; const AMsg: string;
    ANativeCode: Integer = 0; const ANativeMsg: string = ''); overload;
  property Error: TAppError read FError;
end;

Exception wrapper for TAppError. Used when a structured error must propagate across call boundaries (e.g. between pipeline stages). Exception.Message equals Error.Msg. Rarely needed in application code; the library catches EAppError internally and converts it to result properties.


## AppErrorMsg

function AppErrorMsg(ACode: Integer): string;

Returns the EM_* message template string for a given EC_* code. Falls back to EM_UNKNOWN for unrecognised codes. Used internally when building TAppError values; rarely needed in application code.


See Also

(C) 2026 Easygate, Lda