Skip to content

Commit

Permalink
print errors to stderr instead of stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenlu committed Dec 29, 2024
1 parent 92411e5 commit 25c78f6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,18 @@ jobs:
git --no-pager diff
exit 1
fi
- name: Run Broken Models
working-directory: ./tests
run: |
# pipe the result of the next command into
stderr=$(atlas migrate diff --env sqlalchemy -c "file://atlas-standalone.hcl" --var dialect=mysql --var path="./broken" 2>&1);
exit_code=$?
# require the command to fail with exit code 1 and the error message
if [ $exit_code -ne 1 ] || [[ ! $stderr =~ "NameError: name 'DeclarativeBase' is not defined in broken/models.py" ]]; then
echo "Expected command to fail with exit code 1 and the error message 'NameError: name 'DeclarativeBase' is not defined in broken/models.py'";
echo "Exit code: $exit_code";
echo "Stderr: $stderr";
exit 1;
fi
env:
ATLAS_TOKEN: ${{ secrets.ATLAS_TOKEN }}
7 changes: 4 additions & 3 deletions atlas_provider_sqlalchemy/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
from enum import Enum
from pathlib import Path

Expand Down Expand Up @@ -38,11 +39,11 @@ def load(dialect: Dialect = Dialect.mysql,
try:
run(dialect, path, skip_errors)
except ModuleImportError as e:
print(e)
print("To skip on failed import, run: atlas-provider-sqlalchemy --skip-errors")
print(e, file=sys.stderr)
print("To skip on failed import, run: atlas-provider-sqlalchemy --skip-errors", file=sys.stderr)
exit(1)
except ModelsNotFoundError as e:
print(e)
print(e, file=sys.stderr)
exit(1)


Expand Down
7 changes: 6 additions & 1 deletion tests/atlas-standalone.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ variable "dialect" {
type = string
}

variable "path" {
type = string
default = "models"
}

locals {
dev_url = {
mysql = "docker://mysql/8/dev"
Expand All @@ -17,7 +22,7 @@ data "external_schema" "sqlalchemy" {
"run",
"python3",
"../atlas_provider_sqlalchemy/main.py",
"--path", "models",
"--path", var.path,
"--dialect", var.dialect, // mysql | postgresql | sqlite | mssql
]
}
Expand Down
7 changes: 7 additions & 0 deletions tests/broken/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# from typing import List, Optional
# from sqlalchemy import ForeignKey, String
# from sqlalchemy.orm import Mapped, mapped_column, relationship, DeclarativeBase

# This is a broken model file that will raise an error when trying to import it.
class Base(DeclarativeBase):

Check failure on line 6 in tests/broken/models.py

View workflow job for this annotation

GitHub Actions / ci-python

Ruff (F821)

tests/broken/models.py:6:12: F821 Undefined name `DeclarativeBase`
pass

0 comments on commit 25c78f6

Please sign in to comment.