Skip to content

Commit 1e79fda

Browse files
fix: strip non-SQL lines from alembic stdout before linting
Some repos emit JSON structured logs to stdout during env.py loading. These get mixed into the alembic upgrade --sql output and cause squawk syntax errors. Filter out lines starting with { or [ before passing to squawk.
1 parent e80ff29 commit 1e79fda

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

squawk_alembic/hook.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,18 @@ def generate_sql(filepath):
133133
f"squawk-alembic: alembic upgrade --sql failed for {filepath}:\n{result.stderr}"
134134
)
135135

136-
return result.stdout
136+
return _strip_non_sql(result.stdout)
137+
138+
139+
def _strip_non_sql(output):
140+
"""Remove non-SQL lines (e.g. JSON logs) that env.py may emit to stdout."""
141+
lines = []
142+
for line in output.splitlines(keepends=True):
143+
stripped = line.lstrip()
144+
if stripped.startswith("{") or stripped.startswith("["):
145+
continue
146+
lines.append(line)
147+
return "".join(lines)
137148

138149

139150
def validate_branch(branch):

0 commit comments

Comments
 (0)