Skip to content

Create FbError class representing Firebird exceptions (#1) - #170

Open
mariuz wants to merge 7 commits into
asfernandes:masterfrom
mariuz:master
Open

mariuz wants to merge 7 commits into
asfernandes:masterfrom
mariuz:master

Conversation

@mariuz

@mariuz mariuz commented Jul 10, 2026

Copy link
Copy Markdown
Contributor
  1. FbError Class Definition:
    • Created and exported the FbError class in the main driver package: index.ts.
    • It exposes gdsCodes , warnings , and messages arrays representing parsed elements of the Firebird status vector.
  2. Native API Updates ( node-firebird-native-api ):
    • C++ Addon: Implemented parseStatus and parseStatusVector helpers in fb-native.cpp to extract integer GDS codes, warnings, and messages directly from Firebird's IStatus* .
    • Synchronous Errors: Updated rethrowException to attach those properties to errors thrown synchronously by the C++ layer.
    • Asynchronous Promises: Updated the PromiseWorker in classes.h to retrieve status codes on the worker thread, and attach them as Napi Arrays and Strings to the rejected Node-API Error value on
    the main event-loop thread.
  3. Driver Integration:
    • Native Driver ( node-firebird-driver-native ): Updated statusAction in client.ts to intercept native errors containing those properties, wrapping and re-throwing them as instances of FbError .
    • Wire Driver ( node-firebird-driver-wire ): Uniffied exceptions by making the existing FirebirdWireError extend the new FbError and pass the parsed status vector elements to super(...) in
    status.ts.
  4. Test Coverage:
    • Added checks to tests.ts asserting that the thrown exception is an instance of FbError and contains the expected GDS status code (e.g. 335544569 for isc_dsql_error ). All 76 tests in the
    workspace pass successfully!

@mariuz

mariuz commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Hi @asfernandes,

I have updated the code to address all your feedback:

  1. Structured Error Statuses: Restructured FbError to expose a structured status array of type FbStatus[] instead of uncorrelated flat arrays. Each status entry contains its specific error/warning code alongside its associated args (number/string arguments). Both the C++ native addon and the wire driver now populate this structured vector. Added backward-compatible getters for gdsCodes, warnings, and messages to preserve the existing public API.
  2. Error Constants: Added a gdscodes namespace to node-firebird-driver exporting common error constants (like isc_dsql_error, isc_cancelled, etc.) and updated the test suite to use them instead of hardcoded numbers.
  3. Prototype / Subclassing cleanup: Removed the legacy ES5-style Object.setPrototypeOf prototype fixing and constructor name assignments. Since we target ES2020, we now cleanly use modern TS class field declarations with the override modifier.

@mariuz

mariuz commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Hi @asfernandes,

I have updated the PR to address your latest review feedback:

  1. Removed any Type Annotation:

    • In node-firebird-driver-native's client.ts, changed catch (e: any) to catch (e: unknown) with explicit type assertion/guard check.
  2. Standardized Error Status Type:

    • Updated FbStatus.type from 'gds' | 'warning' to 'error' | 'warning'.
    • Added an errors getter on FbError (get errors(): readonly number[]) returning codes for items where type === 'error'. Kept gdsCodes as a backward-compatible alias.
  3. Extracted Complete Firebird Error Codes:

    • Added error-codes.ts generated from iberror.h exporting all 1,260 error codes in UPPERCASE format (e.g. DSQL_ERROR, DSQL_TOKEN_UNK_ERR, CANCELLED) under the errorCodes namespace, while retaining gdscodes for backward compatibility.
  4. Native API Package Exports:

    • Defined and exported FbError, FbStatus, and errorCodes directly in node-firebird-native-api.
  5. C++ Formatting:

    • In fb-native.cpp, formatted single-line if statements without braces.

@asfernandes

Copy link
Copy Markdown
Owner

Two identical error-codes.ts?

@mariuz mariuz reopened this Nov 2, 2026
@mariuz

mariuz commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Removed the duplicate error-codes.ts from node-firebird-native-api (keeping it only in node-firebird-driver) and cleaned up the redundant gdscodes namespace inside error-codes.ts.

@mariuz

mariuz commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Hi @asfernandes,

I have updated the PR to address your review feedback:

  1. Removed gdsCodes alias: Removed the redundant gdsCodes getter from FbError in node-firebird-driver.
  2. Removed public status helper functions: Removed parseRawStatusVector and buildStatusFromFlat from the public exports of node-firebird-driver, keeping status vector conversion internal to node-firebird-driver-wire (with numeric arguments preserved as numbers).
  3. Single FbError implementation: Removed the duplicate error.ts in node-firebird-native-api, added node-firebird-driver as a workspace dependency, re-exported FbError, FbStatus, and errorCodes, and updated the C++ addon (fb-native.cpp / classes.h) to instantiate and throw/reject FbError directly (simplifying statusAction in node-firebird-driver-native).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants