Error Handling¶
Best practices for handling parse errors, understanding error messages, and recovering from parsing failures in GSP .NET.
The basics¶
TGSqlParser.parse() returns 0 on success and a non-zero integer on failure. Detailed errors are exposed through three properties:
| Property | Type | Use it for |
|---|---|---|
Errormessage |
string |
A pre-formatted multi-line error report. Good for logging. |
SyntaxErrors |
IList<TSyntaxError> |
One entry per error, with line/column/token context. |
ErrorCount |
int |
Quick count without iterating the list. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Per-statement error isolation¶
When a script contains multiple statements separated by ;, a syntax error in one statement does not abort the others. The parser still produces partial results for everything it could parse, and SyntaxErrors lists the specific failures.
Inside a stored procedure, however, a syntax error in one nested statement does abort the whole procedure — no AST will be built for the rest of that procedure body.
Distinguishing parse error from wrong-vendor error¶
The single most common cause of parse failures is using the wrong EDbVendor. Build a tiny helper:
1 2 3 4 5 6 7 8 9 | |
If your input parses cleanly for some other vendor, the error is in the user's choice of vendor — surface that as an actionable hint in your UI.
Partial parsing¶
For interactive tools (linters, IDE plugins) that need an AST even from broken SQL, set EnablePartialParsing = true before calling parse(). The parser then attempts to build a best-effort AST around the syntax errors instead of bailing out.
1 2 3 4 5 | |
Recoverable patterns¶
Retry with a different vendor¶
1 2 3 4 5 6 7 8 9 10 11 12 | |
Strip non-standard prefixes¶
Some users paste SQL with a EXPLAIN, EXPLAIN PLAN FOR, or SQL> prompt prefix. Strip these before parsing:
1 | |
Pre-validate identifier characters¶
If your input may contain forbidden characters (e.g. zero-width spaces from a chat client), normalise the string before parsing:
1 2 3 | |
Logging error messages¶
For server-side workloads, log both Errormessage (for humans reading the log) and the structured SyntaxErrors (for machine processing):
1 2 3 4 5 6 7 8 9 10 11 12 | |