Skip to content

Commit 331adbc

Browse files
committed
refactor(native): raise the shared native stage mismatch error from the macro bridge
1 parent 66301fc commit 331adbc

4 files changed

Lines changed: 10 additions & 12 deletions

File tree

‎src/sqlbuild/compiler/compile/_helpers/macro_bridge/expansion.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
)
1515
from sqlbuild.compiler.compile.classes.macro_expansion_facts import MacroExpansionFacts
1616
from sqlbuild.compiler.compile.constants import MACRO_TOKEN
17-
from sqlbuild.compiler.compile.exceptions import CompileInputError, NativeRenderMismatchError
17+
from sqlbuild.compiler.compile.exceptions import CompileInputError
1818
from sqlbuild.compiler.compile.models import (
1919
DeclarationResolutionContext,
2020
ExpansionSpan,
2121
MacroExpansionState,
2222
)
23+
from sqlbuild.compiler.frontier.exceptions import NativeStageMismatchError
2324
from sqlbuild.compiler.macro_bridge.classes.macro_bridge import MacroBridge
2425
from sqlbuild.compiler.macro_bridge.constants import (
2526
ARGUMENT_REFERENCE_EVENT,
@@ -139,7 +140,7 @@ def _bridged_call_output( # noqa: PLR0913
139140
"directly in SQL"
140141
)
141142
if next_index != site.end:
142-
raise NativeRenderMismatchError(
143+
raise NativeStageMismatchError(
143144
f"Native macro call scan of '{consumer_path}' ended at {site.end}, Python at "
144145
f"{next_index}"
145146
)
@@ -177,7 +178,7 @@ def _replay_macro_call_event(
177178
)
178179
elif tag == DECLARATION_READ_EVENT:
179180
if declarations is None:
180-
raise NativeRenderMismatchError("Replayed a declaration read without declarations")
181+
raise NativeStageMismatchError("Replayed a declaration read without declarations")
181182
_record_macro_declaration_usage(
182183
name=second, kind=DeclarationKind(first), declarations=declarations, state=state
183184
)
@@ -198,4 +199,4 @@ def _replay_macro_call_event(
198199
(SqlResourceRef(kind=SqlResourceRefKind(first), name=second),)
199200
)
200201
else:
201-
raise NativeRenderMismatchError(f"Unknown macro call event {tag}")
202+
raise NativeStageMismatchError(f"Unknown macro call event {tag}")

‎src/sqlbuild/compiler/compile/exceptions.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ class MacroDeclarationLookupError(CompileInputError, KeyError):
1919
"""Retain authored diagnostics while honoring the Mapping lookup contract."""
2020

2121

22-
class NativeRenderMismatchError(RuntimeError):
23-
"""Raised when native rendering disagrees with Python, so the Python stage must re-run."""
24-
25-
2622
class NativeSqlTestResponseError(CompileInputError):
2723
"""Raised when native SQL-test extraction returns malformed data."""
2824

‎src/sqlbuild/compiler/macro_bridge/main/run_with_macro_bridge.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from contextvars import Token
1010

1111
import sqlbuild._native as _native
12-
from sqlbuild.compiler.compile.exceptions import NativeRenderMismatchError
12+
from sqlbuild.compiler.frontier.exceptions import NativeStageMismatchError
1313
from sqlbuild.compiler.macro_bridge.classes.macro_bridge import MacroBridge
1414
from sqlbuild.compiler.macro_bridge.constants import ACTIVE_MACRO_BRIDGE
1515

@@ -46,7 +46,7 @@ def run_with_macro_bridge[T](*, stage: Callable[[], T]) -> T:
4646
finally:
4747
ACTIVE_MACRO_BRIDGE.reset(token)
4848
_ = stage()
49-
raise NativeRenderMismatchError(
49+
raise NativeStageMismatchError(
5050
"The native macro bridge failed where the Python render succeeded; "
5151
"run with SQLBUILD_COMPILER_ENGINE=python"
5252
) from native_error

‎tests/unit/src/sqlbuild/compiler/macro_bridge/main/test_run_with_macro_bridge.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import pytest
66

7-
from sqlbuild.compiler.compile.exceptions import CompileInputError, NativeRenderMismatchError
7+
from sqlbuild.compiler.compile.exceptions import CompileInputError
8+
from sqlbuild.compiler.frontier.exceptions import NativeStageMismatchError
89
from sqlbuild.compiler.macro_bridge.main.active_macro_bridge import active_macro_bridge
910
from sqlbuild.compiler.macro_bridge.main.run_with_macro_bridge import run_with_macro_bridge
1011
from tests.unit.src.sqlbuild.compiler.macro_bridge.main._test_types import (
@@ -58,7 +59,7 @@ def test_given_succeeding_stage_when_running_with_macro_bridge_then_runs_once_br
5859
description="native-only failure is reported as a divergence",
5960
stage_with_bridge=failed,
6061
stage_without_bridge=rendered,
61-
expected_error=NativeRenderMismatchError,
62+
expected_error=NativeStageMismatchError,
6263
expected_bridged_runs=[True, False],
6364
),
6465
],

0 commit comments

Comments
 (0)