Skip to content

Commit 2f682ee

Browse files
committed
Improve error handling for missing source files
Raise `InvalidSourceList` error if new source file is not found Fixes #18111
1 parent 1a95964 commit 2f682ee

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

mypy/dmypy_server.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,11 @@ def cmd_run(
346346
)
347347
if current_plugins_snapshot != start_plugins_snapshot:
348348
return {"restart": "plugins changed"}
349+
return self.check(sources, export_types, is_tty, terminal_width)
349350
except InvalidSourceList as err:
350351
return {"out": "", "err": str(err), "status": 2}
351352
except SystemExit as e:
352353
return {"out": stdout.getvalue(), "err": stderr.getvalue(), "status": e.code}
353-
return self.check(sources, export_types, is_tty, terminal_width)
354354

355355
def cmd_check(
356356
self, files: Sequence[str], export_types: bool, is_tty: bool, terminal_width: int
@@ -856,6 +856,13 @@ def pretty_messages(
856856

857857
def update_sources(self, sources: list[BuildSource]) -> None:
858858
paths = [source.path for source in sources if source.path is not None]
859+
for path in paths:
860+
if not self.fscache.exists(path):
861+
raise InvalidSourceList(
862+
"mypy: can't read file '{}': No such file or directory\n".format(
863+
path.replace(os.getcwd() + os.sep, "")
864+
)
865+
)
859866
if self.following_imports():
860867
# Filter out directories (used for namespace packages).
861868
paths = [path for path in paths if self.fscache.isfile(path)]

0 commit comments

Comments
 (0)