Skip to content

Commit f44fbd4

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

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

sqlmesh/core/console.py

Lines changed: 36 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,12 @@ def stop_promotion_progress(self, success: bool = True) -> None:
34013415
super().stop_promotion_progress(success)
34023416
self._print("\n")
34033417

3418+
def log_warning(self, short_message: str, long_message: t.Optional[str] = None) -> None:
3419+
super().log_warning(short_message, long_message, print=False)
3420+
3421+
def log_error(self, message: str) -> None:
3422+
super().log_error(message, print=False)
3423+
34043424
def log_success(self, message: str) -> None:
34053425
self._print(message)
34063426

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

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

34333455
def log_failed_models(self, errors: t.List[NodeExecutionFailedError]) -> None:
34343456
if errors:
3435-
self._print("\n```\nFailed models\n")
3457+
self._print("**Failed models**")
34363458

34373459
error_messages = _format_node_errors(errors)
34383460

34393461
for node_name, msg in error_messages.items():
3440-
self._print(f" **{node_name}**\n\n{msg}")
3462+
self._print(f"* `{node_name}`\n")
3463+
self._print(" ```")
3464+
self._print(msg)
3465+
self._print(" ```")
34413466

3442-
self._print("```\n")
3467+
self._print("")
34433468

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

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)