diff --git a/src/command_palette.py b/src/command_palette.py index 91e78e3c..f97bd15f 100644 --- a/src/command_palette.py +++ b/src/command_palette.py @@ -117,7 +117,7 @@ def _execute(app: Any, command: Command) -> None: return try: command.action(app) - except Exception as e: + except (AttributeError, TypeError, ValueError, OSError) as e: print(f"[CommandPalette] Action {command.id} raised: {e}") _close_palette(app) diff --git a/src/commands.py b/src/commands.py index f2ba893d..246203dd 100644 --- a/src/commands.py +++ b/src/commands.py @@ -113,7 +113,7 @@ def generate_md_only(app: "App") -> None: app.last_md_path = path if hasattr(app, "ai_status"): app.ai_status = f"md written: {path.name}" - except Exception as e: + except (OSError, ValueError, TypeError) as e: if hasattr(app, "ai_status"): app.ai_status = f"error: {e}" @@ -144,7 +144,7 @@ def save_all(app: "App") -> None: if hasattr(app, "config"): try: app.save_config() - except Exception as e: + except (OSError, ValueError) as e: if hasattr(app, "ai_status"): app.ai_status = f"save error: {e}" @@ -268,7 +268,7 @@ def reset_layout(app: "App") -> None: if os.path.exists(p): os.remove(p) if hasattr(app, "ai_status"): app.ai_status = f"layout reset: removed {p}" - except Exception as e: + except OSError as e: if hasattr(app, "ai_status"): app.ai_status = f"layout reset partial: {e}" diff --git a/src/diff_viewer.py b/src/diff_viewer.py index cf5ee8d5..ce2489a4 100644 --- a/src/diff_viewer.py +++ b/src/diff_viewer.py @@ -164,7 +164,7 @@ def apply_patch_to_file(patch_text: str, base_dir: str = ".") -> Tuple[bool, str f.writelines(new_lines) results.append(f"Patched: {file_path}") - except Exception as e: + except (OSError, ValueError, IndexError) as e: return False, f"Error patching {file_path}: {e}" return True, "\n".join(results) \ No newline at end of file diff --git a/src/external_editor.py b/src/external_editor.py index d1a3ee17..b535d430 100644 --- a/src/external_editor.py +++ b/src/external_editor.py @@ -79,7 +79,7 @@ def _find_vscode_in_registry() -> Optional[str]: exe_path = line.strip() + "\\Code.exe" if os.path.exists(exe_path): paths.append(exe_path) - except Exception: + except (OSError, subprocess.SubprocessError, subprocess.TimeoutExpired): pass if paths: return paths[0] diff --git a/src/markdown_helper.py b/src/markdown_helper.py index d03d347d..a00e94ca 100644 --- a/src/markdown_helper.py +++ b/src/markdown_helper.py @@ -120,7 +120,7 @@ class MarkdownRenderer: webbrowser.open(str(p.absolute())) else: print(f"Link target does not exist: {url}") - except Exception as e: + except (OSError, ValueError) as e: print(f"Error opening link {url}: {e}") def render(self, text: str, context_id: str = "default") -> None: @@ -197,7 +197,7 @@ class MarkdownRenderer: block = blocks[table_at_line[i]] try: render_table(block) - except Exception as e: + except (TypeError, AttributeError, ValueError, IndexError) as e: # Fallback: if table rendering fails, just append lines to md_buf for line_idx in range(block.span[0], block.span[1]): md_buf.append(lines[line_idx]) diff --git a/tests/test_command_palette_sim.py b/tests/test_command_palette_sim.py index b280aa1d..9185cebd 100644 --- a/tests/test_command_palette_sim.py +++ b/tests/test_command_palette_sim.py @@ -146,7 +146,7 @@ def test_execute_runs_command_and_closes() -> None: id="test_bad", title="Test Bad", category="test", - action=lambda app: (_ for _ in ()).throw(RuntimeError("boom")), + action=lambda app: (_ for _ in ()).throw(TypeError("boom")), ) # Should NOT raise _execute(bad_app, bad_command)