fix: install MEOS error handler so errors throw instead of exit()#7
Merged
nhungoc1508 merged 1 commit intomainfrom Apr 25, 2026
Merged
fix: install MEOS error handler so errors throw instead of exit()#7nhungoc1508 merged 1 commit intomainfrom
nhungoc1508 merged 1 commit intomainfrom
Conversation
MEOS's default error handler writes the message to stderr and calls exit(EXIT_FAILURE) on errlevel == ERROR (PG elog level 21 carried through via postgres.h). That tears down the whole DuckDB process on any invalid user input — a parse error on a malformed tstzset literal, a negative precision on asText, etc. — which (a) is user-hostile in production and (b) makes every `statement error` test kill the test runner before Catch2 can check it. PR #6 surfaced this by trying to exercise MEOS error paths in the parity harness and crashing CI on the first parse-error query. This PR installs `MobilityduckMeosErrorHandler` via `meos_initialize_error_handler(...)` in LoadInternal, right after `meos_initialize()`. The handler throws a DuckDB::InvalidInputException on errlevel >= 21 (ERROR/FATAL/PANIC), so MEOS errors surface as ordinary query failures with the MEOS message attached. Lower levels (WARNING/NOTICE/INFO) are silently ignored for now — can be wired to DuckDB's logger in a follow-up if useful. Parity file (`test/sql/parity/001_set.test`) consequences: - Deletes the top-of-file error-handler gap note (now obsolete). - Unwraps the 3 MEOS-error-specific `mode skip` blocks covering tstzset parse errors and asText negative-digits — they run as real `statement error` assertions. - Re-wraps ONE of those (`set('{}'::timestamptz[])`) in a skip block with a new gap note: that query fails at the DuckDB cast layer with a conversion error before MEOS sees it, because `'{}'` is PG array-literal syntax that DuckDB rejects as a string literal. The equivalent DuckDB form `set(ARRAY[]::TIMESTAMPTZ[])` reaches MEOS but the constructor wrapper in src/temporal/set_functions.cpp returns null instead of calling meos_error(...) on empty input — a separate gap, documented for a later follow-up. Verified locally (`TZ=UTC ./build/release/test/unittest "/path/to/test/*"`): 747 assertions pass across 13 test cases (up from 739 pre-handler), no regressions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 24, 2026
This was referenced Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MEOS's default error handler writes the message to stderr and calls
exit(EXIT_FAILURE)onerrlevel == ERROR(PG elog level 21, carried through viapostgres.h). That tears down the entire DuckDB process on any invalid user input — a malformed tstzset literal, a negative precision onasText, etc. — which is both user-hostile in production and made everystatement errortest in PR #6's parity harness kill the test runner before Catch2 could check it.This PR installs
MobilityduckMeosErrorHandlerviameos_initialize_error_handler(...)inLoadInternal, right aftermeos_initialize(). The handler throwsDuckDB::InvalidInputExceptiononerrlevel >= 21(ERROR/FATAL/PANIC), so MEOS errors surface as ordinary query failures with the MEOS message attached. Lower levels (WARNING/NOTICE/INFO) are silently ignored for now — can be wired to DuckDB's logger in a follow-up if useful.Parity file consequences
mode skipblocks coveringtstzsetparse errors andasTextnegative-digits — they now run as realstatement errorassertions.set('{}'::timestamptz[])) in a fresh skip block with a new gap note: that query fails at the DuckDB cast layer with aConversion Errorbefore MEOS sees it, because'{}'is PG array-literal syntax that DuckDB rejects as a string literal. The equivalent DuckDB formset(ARRAY[]::TIMESTAMPTZ[])reaches MEOS but the constructor wrapper insrc/temporal/set_functions.cppreturns null instead of callingmeos_error(...)on empty input — a separate gap, documented for a later follow-up.Test plan
TZ=UTC ./build/release/test/unittest \"<proj>/test/*\"locally: 747 assertions pass across 13 test cases (up from 739 pre-handler), no regressions.statement error.Notes
-fexceptionsenabled (which DuckDB and its extensions use). This is the same mechanism DuckDB-spatial uses for GDAL error handlers — precedent in the surrounding ecosystem.errcodeis currently unused in the handler. Could be mapped to more specific DuckDB exception types in a follow-up (e.g.MEOS_ERR_WKB_INPUT→InvalidTypeException), but one-size-fits-allInvalidInputExceptionis fine as a baseline.🤖 Generated with Claude Code