Log SQL-related errors with structured metadata.
(
logger_func: Callable[..., None],
*,
message: str,
exception: BaseException,
rule_code: str,
node: ast.expr | None = None,
sql_content: str = "",
context: str = "",
)
| 199 | |
| 200 | |
| 201 | def log_sql_error( |
| 202 | logger_func: Callable[..., None], |
| 203 | *, |
| 204 | message: str, |
| 205 | exception: BaseException, |
| 206 | rule_code: str, |
| 207 | node: ast.expr | None = None, |
| 208 | sql_content: str = "", |
| 209 | context: str = "", |
| 210 | ) -> None: |
| 211 | """Log SQL-related errors with structured metadata.""" |
| 212 | # Use centralized metadata creation |
| 213 | metadata = create_sql_error_metadata( |
| 214 | exception, |
| 215 | rule_code=rule_code, |
| 216 | node=node, |
| 217 | sql_content=sql_content, |
| 218 | context=context, |
| 219 | ) |
| 220 | |
| 221 | # Log clean SQL error without traces |
| 222 | log_msg = message if message else metadata["clean_message"] |
| 223 | if metadata["sql_line"] is not None and metadata["sql_col"] is not None: |
| 224 | log_msg += f" (Line {metadata['sql_line'] + 1}, Col {metadata['sql_col'] + 1})" |
| 225 | if metadata["sql_statement"]: |
| 226 | log_msg += f"\nSQL: {metadata['sql_statement']}" |
| 227 | |
| 228 | logger_func(log_msg, extra=metadata) |
| 229 | |
| 230 | |
| 231 | def create_sql_error_from_exception( |
no test coverage detected
searching dependent graphs…