From 92a458f3f99d710e28cb8f0e3201ba0f7cbdd401 Mon Sep 17 00:00:00 2001 From: codeasier Date: Fri, 17 Apr 2026 20:49:01 +0800 Subject: [PATCH 1/2] fix: replace silent pass with warnings in template loading (#13) YAML template loading failures were silently swallowed by bare except Exception: pass blocks. Corrupted or malformed templates would disappear without any indication. Now warnings.warn() is used so failures are visible to users and developers. Closes #13 --- src/pt_snap_cli/query/executor.py | 7 +++++-- src/pt_snap_cli/query/registry.py | 9 +++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pt_snap_cli/query/executor.py b/src/pt_snap_cli/query/executor.py index 406ca65..82918de 100644 --- a/src/pt_snap_cli/query/executor.py +++ b/src/pt_snap_cli/query/executor.py @@ -2,6 +2,7 @@ from __future__ import annotations +import warnings from pathlib import Path from typing import Any @@ -57,8 +58,10 @@ def _load_templates(self) -> None: try: config = QueryConfig.load_yaml(yaml_file) self._configs[yaml_file.stem] = config - except Exception: - pass + except Exception as e: + warnings.warn( + f"Failed to load query template from {yaml_file}: {e}", stacklevel=2 + ) def render( self, diff --git a/src/pt_snap_cli/query/registry.py b/src/pt_snap_cli/query/registry.py index 38f1e26..cd93231 100644 --- a/src/pt_snap_cli/query/registry.py +++ b/src/pt_snap_cli/query/registry.py @@ -2,6 +2,7 @@ from __future__ import annotations +import warnings from collections.abc import Callable from pathlib import Path @@ -266,8 +267,8 @@ def _load_yaml_templates(template_dir: Path | str | None = None) -> None: config = QueryConfig.load_yaml(yaml_file) for _query_name, template in config.queries.items(): _registry.register(template) - except Exception: - pass + except Exception as e: + warnings.warn(f"Failed to load query template from {yaml_file}: {e}", stacklevel=2) def _load_all_templates() -> None: @@ -277,5 +278,5 @@ def _load_all_templates() -> None: try: _load_all_templates() -except Exception: - pass +except Exception as e: + warnings.warn(f"Failed to load query templates: {e}", stacklevel=2) From 79b9bf950f2be5b7542bd00a084b84f4fe6b1692 Mon Sep 17 00:00:00 2001 From: codeasier Date: Fri, 17 Apr 2026 20:56:51 +0800 Subject: [PATCH 2/2] fix: apply black formatting to executor.py --- src/pt_snap_cli/query/executor.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pt_snap_cli/query/executor.py b/src/pt_snap_cli/query/executor.py index 82918de..738dd63 100644 --- a/src/pt_snap_cli/query/executor.py +++ b/src/pt_snap_cli/query/executor.py @@ -59,9 +59,7 @@ def _load_templates(self) -> None: config = QueryConfig.load_yaml(yaml_file) self._configs[yaml_file.stem] = config except Exception as e: - warnings.warn( - f"Failed to load query template from {yaml_file}: {e}", stacklevel=2 - ) + warnings.warn(f"Failed to load query template from {yaml_file}: {e}", stacklevel=2) def render( self,