Skip to content

Commit dd6ee1c

Browse files
committed
Chore(cicd_bot): Tidy up failure output
1 parent 107fe25 commit dd6ee1c

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

sqlmesh/core/console.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,17 @@ def show_row_diff(
289289

290290
class BaseConsole(abc.ABC):
291291
@abc.abstractmethod
292-
def log_error(self, message: str) -> None:
292+
def log_error(self, message: str, *args: t.Any, **kwargs: t.Any) -> None:
293293
"""Display error info to the user."""
294294

295295
@abc.abstractmethod
296-
def log_warning(self, short_message: str, long_message: t.Optional[str] = None) -> None:
296+
def log_warning(
297+
self,
298+
short_message: str,
299+
long_message: t.Optional[str] = None,
300+
*args: t.Any,
301+
**kwargs: t.Any,
302+
) -> None:
297303
"""Display warning info to the user.
298304
299305
Args:
@@ -3082,15 +3088,23 @@ def consume_captured_errors(self) -> str:
30823088
finally:
30833089
self._errors = []
30843090

3085-
def log_warning(self, short_message: str, long_message: t.Optional[str] = None) -> None:
3091+
def log_warning(
3092+
self,
3093+
short_message: str,
3094+
long_message: t.Optional[str] = None,
3095+
*args: t.Any,
3096+
**kwargs: t.Any,
3097+
) -> None:
30863098
if short_message not in self._warnings:
30873099
self._warnings.append(short_message)
3088-
super().log_warning(short_message, long_message)
3100+
if kwargs.pop("print", True):
3101+
super().log_warning(short_message, long_message)
30893102

3090-
def log_error(self, message: str) -> None:
3103+
def log_error(self, message: str, *args: t.Any, **kwargs: t.Any) -> None:
30913104
if message not in self._errors:
30923105
self._errors.append(message)
3093-
super().log_error(message)
3106+
if kwargs.pop("print", True):
3107+
super().log_error(message)
30943108

30953109
def log_skipped_models(self, snapshot_names: t.Set[str]) -> None:
30963110
if snapshot_names:
@@ -3401,6 +3415,14 @@ def stop_promotion_progress(self, success: bool = True) -> None:
34013415
super().stop_promotion_progress(success)
34023416
self._print("\n")
34033417

3418+
def log_warning(
3419+
self, short_message: str, long_message: t.Optional[str] = None, print: bool = False
3420+
) -> None:
3421+
super().log_warning(short_message, long_message, print=print)
3422+
3423+
def log_error(self, message: str, print: bool = False) -> None:
3424+
super().log_error(message, print=print)
3425+
34043426
def log_success(self, message: str) -> None:
34053427
self._print(message)
34063428

@@ -3427,19 +3449,24 @@ def log_test_results(self, result: ModelTextTestResult, target_dialect: str) ->
34273449

34283450
def log_skipped_models(self, snapshot_names: t.Set[str]) -> None:
34293451
if snapshot_names:
3430-
msg = " " + "\n ".join(snapshot_names)
3431-
self._print(f"**Skipped models**\n\n{msg}")
3452+
self._print(f"**Skipped models**")
3453+
for snapshot_name in snapshot_names:
3454+
self._print(f"* `{snapshot_name}`")
3455+
self._print("")
34323456

34333457
def log_failed_models(self, errors: t.List[NodeExecutionFailedError]) -> None:
34343458
if errors:
3435-
self._print("\n```\nFailed models\n")
3459+
self._print("**Failed models**")
34363460

34373461
error_messages = _format_node_errors(errors)
34383462

34393463
for node_name, msg in error_messages.items():
3440-
self._print(f" **{node_name}**\n\n{msg}")
3464+
self._print(f"* `{node_name}`\n")
3465+
self._print(" ```")
3466+
self._print(msg)
3467+
self._print(" ```")
34413468

3442-
self._print("```\n")
3469+
self._print("")
34433470

34443471
def show_linter_violations(
34453472
self, violations: t.List[RuleViolation], model: Model, is_error: bool = False

sqlmesh/core/scheduler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ def _audit_snapshot(
726726
self.console.log_warning(
727727
f"\n{display_name}: {audit_error}.",
728728
f"{audit_error}. Audit query:\n{audit_error.query.sql(audit_error.adapter_dialect)}",
729+
print=True,
729730
)
730731

731732
return audit_results

sqlmesh/integrations/github/cicd/controller.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,11 @@ def _get_pr_environment_summary_action_required(
603603

604604
def _get_pr_environment_summary_failure(self, exception: t.Optional[Exception] = None) -> str:
605605
console_output = self._console.consume_captured_output()
606+
failure_msg = ""
606607

607608
if isinstance(exception, PlanError):
608-
failure_msg = f"Plan application failed.\n"
609609
if exception.args and (msg := exception.args[0]) and isinstance(msg, str):
610-
failure_msg += f"\n{msg}\n"
610+
failure_msg += f"*{msg}*\n"
611611
if console_output:
612612
failure_msg += f"\n{console_output}"
613613
elif isinstance(exception, (SQLMeshError, SqlglotError, ValueError)):
@@ -713,6 +713,7 @@ def update_pr_environment(self) -> None:
713713
Creates a PR environment from the logic present in the PR. If the PR contains changes that are
714714
uncategorized, then an error will be raised.
715715
"""
716+
self._console.consume_captured_output() # clear output buffer
716717
self._context.apply(self.pr_plan) # will raise if PR environment creation fails
717718

718719
# update PR info comment

tests/integrations/github/cicd/test_integration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,8 @@ def test_error_msg_when_applying_plan_with_bug(
15821582
assert GithubCheckConclusion(pr_checks_runs[2]["conclusion"]).is_failure
15831583
assert pr_checks_runs[2]["output"]["title"] == "PR Virtual Data Environment: hello_world_2"
15841584
summary = pr_checks_runs[2]["output"]["summary"].replace("\n", "")
1585-
assert 'Failed models **"memory"."sushi"."waiter_revenue_by_day"**' in summary
1585+
assert '**Skipped models*** `"memory"."sushi"."top_waiters"`' in summary
1586+
assert '**Failed models*** `"memory"."sushi"."waiter_revenue_by_day"`' in summary
15861587
assert 'Binder Error: Referenced column "non_existing_col" not found in FROM clause!' in summary
15871588

15881589
assert "SQLMesh - Prod Plan Preview" in controller._check_run_mapping

0 commit comments

Comments
 (0)