fix(exception): NG1 fixed - 4 INTERNAL_OPTIONAL_RETURN violations migrated to Result[T]
This commit is contained in:
+17
-8
@@ -10,6 +10,7 @@ from pathlib import Path
|
||||
from typing import Optional, List, Dict, Any
|
||||
|
||||
from src.models import ExternalEditorConfig, TextEditorConfig
|
||||
from src.result_types import ErrorInfo, ErrorKind, Result
|
||||
|
||||
|
||||
class ExternalEditorLauncher:
|
||||
@@ -38,23 +39,31 @@ class ExternalEditorLauncher:
|
||||
"""
|
||||
[C: src/gui_2.py:App._open_patch_in_external_editor, tests/test_external_editor.py:TestExternalEditorLauncher.test_launch_diff_file_not_found, tests/test_external_editor.py:TestExternalEditorLauncher.test_launch_diff_missing_editor, tests/test_external_editor.py:TestExternalEditorLauncher.test_launch_diff_success]
|
||||
"""
|
||||
r = self.launch_diff_result(editor_name, original_path, modified_path)
|
||||
return r.data if r.ok else None
|
||||
|
||||
def launch_diff_result(self, editor_name: Optional[str], original_path: str, modified_path: str) -> Result[subprocess.Popen]:
|
||||
editor = self.get_editor(editor_name)
|
||||
if not editor:
|
||||
return None
|
||||
return Result(data=None, errors=[ErrorInfo(kind=ErrorKind.NOT_FOUND, message=f"No editor configured: {editor_name}", source="external_editor.launch_diff_result")])
|
||||
cmd = self.build_diff_command(editor, original_path, modified_path)
|
||||
try:
|
||||
return subprocess.Popen(cmd)
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
return Result(data=subprocess.Popen(cmd))
|
||||
except FileNotFoundError as e:
|
||||
return Result(data=None, errors=[ErrorInfo(kind=ErrorKind.NOT_FOUND, message=f"Editor binary not found: {cmd[0]}", source="external_editor.launch_diff_result", original=e)])
|
||||
|
||||
def launch_editor(self, editor_name: Optional[str], file_path: str) -> Optional[subprocess.Popen]:
|
||||
r = self.launch_editor_result(editor_name, file_path)
|
||||
return r.data if r.ok else None
|
||||
|
||||
def launch_editor_result(self, editor_name: Optional[str], file_path: str) -> Result[subprocess.Popen]:
|
||||
editor = self.get_editor(editor_name)
|
||||
if not editor:
|
||||
return None
|
||||
return Result(data=None, errors=[ErrorInfo(kind=ErrorKind.NOT_FOUND, message=f"No editor configured: {editor_name}", source="external_editor.launch_editor_result")])
|
||||
try:
|
||||
return subprocess.Popen([editor.path, file_path])
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
return Result(data=subprocess.Popen([editor.path, file_path]))
|
||||
except FileNotFoundError as e:
|
||||
return Result(data=None, errors=[ErrorInfo(kind=ErrorKind.NOT_FOUND, message=f"Editor binary not found: {editor.path}", source="external_editor.launch_editor_result", original=e)])
|
||||
|
||||
|
||||
_cached_vscode_config: Optional[TextEditorConfig] = None
|
||||
|
||||
Reference in New Issue
Block a user