From 2f682ee60db86aa1195598d9ac79b19b22b65132 Mon Sep 17 00:00:00 2001 From: kcornw <141114704+kcornw@users.noreply.github.com> Date: Mon, 2 Dec 2024 17:02:18 +0800 Subject: [PATCH] Improve error handling for missing source files Raise `InvalidSourceList` error if new source file is not found Fixes #18111 --- mypy/dmypy_server.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mypy/dmypy_server.py b/mypy/dmypy_server.py index 70cfaa5b2fb9..62ea967fc944 100644 --- a/mypy/dmypy_server.py +++ b/mypy/dmypy_server.py @@ -346,11 +346,11 @@ def cmd_run( ) if current_plugins_snapshot != start_plugins_snapshot: return {"restart": "plugins changed"} + return self.check(sources, export_types, is_tty, terminal_width) except InvalidSourceList as err: return {"out": "", "err": str(err), "status": 2} except SystemExit as e: return {"out": stdout.getvalue(), "err": stderr.getvalue(), "status": e.code} - return self.check(sources, export_types, is_tty, terminal_width) def cmd_check( self, files: Sequence[str], export_types: bool, is_tty: bool, terminal_width: int @@ -856,6 +856,13 @@ def pretty_messages( def update_sources(self, sources: list[BuildSource]) -> None: paths = [source.path for source in sources if source.path is not None] + for path in paths: + if not self.fscache.exists(path): + raise InvalidSourceList( + "mypy: can't read file '{}': No such file or directory\n".format( + path.replace(os.getcwd() + os.sep, "") + ) + ) if self.following_imports(): # Filter out directories (used for namespace packages). paths = [path for path in paths if self.fscache.isfile(path)]