Skip to content

fix(builtins): ERRORCODE returns a LONG, FILEERRORCODE a STRING - #871

Merged
msarson merged 1 commit into
msarson:version-1.0.11from
geircodes:fix/builtins-errorcode-return-type
Nov 25, 2026
Merged

msarson merged 1 commit into
msarson:version-1.0.11from
geircodes:fix/builtins-errorcode-return-type

Conversation

@geircodes

Copy link
Copy Markdown
Contributor

ERRORCODE returns a LONG, FILEERRORCODE a STRING (they were swapped)

What happened

Hovering ERRORCODE in

  GET(SomeQ, SomeQ.Key)
  IF ERRORCODE() = 0

showed:

Built-in Function: ERRORCODE

Returns the error code number as a string from the most recent file operation (OPEN, GET, ADD, etc.). Returns empty string if no error. Check after every file operation.

and signature help read ERRORCODE() → STRING. ERRORCODE returns a number, and the very line it is hovered on compares it with 0.

Root cause

server/src/data/clarion-builtins.json had the return types of ERRORCODE and FILEERRORCODE swapped:

{ "name": "ERRORCODE",     ... "returnType": "STRING", "description": "Returns the error code number as a string ... Returns empty string if no error. ..." }
{ "name": "FILEERRORCODE", ... "returnType": "LONG",   "description": "Returns the file driver-specific error code as a numeric value. ..." }

The Language Reference says the opposite:

  • ERRORCODE (return error code number): "returns the code number for any error that was posted. If no error was posted, ERRORCODE returns zero." Return Data Type: LONG. It is not limited to file operations.
  • FILEERRORCODE (return file driver error code number): "returns a string containing the code number for the 'native' error message from the file system (file driver) ... Valid only when ERRORCODE() = 90 or ERRORCODE() = 47." Return Data Type: STRING.

The fix

Both entries now carry the documented type and wording:

{ "name": "ERRORCODE", ... "returnType": "LONG",
  "description": "Returns the code number for any error that was posted (for example by OPEN, GET or ADD). Returns zero if no error was posted. Check it immediately after the statement that may post an error: any later statement that can post an error clears it." }
{ "name": "FILEERRORCODE", ... "returnType": "STRING",
  "description": "Returns a string containing the code number of the native error from the file system (file driver) used to access the data file. Valid only when ERRORCODE() = 90 or ERRORCODE() = 47." }

No code depends on either return type (checked: the only other references are the grammar's built-in list, the undeclared-variable built-in list and tests).

Testing

  • New server/src/test/BuiltinErrorCodeReturnType.test.ts, 3 tests: ERRORCODE() → LONG with "zero" and no "string" in its description; FILEERRORCODE() → STRING with the 90 / 47 condition; and a real hover on IF ERRORCODE() = 0 that must say "zero" and must not say "as a string" / "empty string".
  • Proven non-vacuous: with the old clarion-builtins.json in out/, all 3 fail.
  • Server suite: 4622 passing, 3 pending.

Scope

Only these two entries. ERROR() says "from the most recent file operation", which is narrower than the Language Reference ("any error that was posted"), but it is not wrong about the type, so I left it.

🤖 Generated with Claude Code

clarion-builtins.json had the two return types swapped. The hover card
on `IF ERRORCODE() = 0` said the code came back "as a string" and was
"empty string if no error", and the signature read ERRORCODE() -> STRING.
Language Reference: ERRORCODE() returns a LONG, zero when no error was
posted; FILEERRORCODE() returns a STRING with the file driver's native
error code, valid only when ERRORCODE() = 90 or 47. Both entries now
say so.

Test: BuiltinErrorCodeReturnType.test.ts, 3 tests (signature labels,
descriptions, the hover card); all 3 fail against the old data. Server
suite: 4622 passing, 3 pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@msarson
msarson merged commit ce70d26 into msarson:version-1.0.11 Nov 25, 2026
1 check passed
@geircodes
geircodes deleted the fix/builtins-errorcode-return-type branch November 25, 2026 13:46
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