Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the error message for a missing file #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions code_submitter/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,26 @@ async def upload(request: Request) -> Response:
try:
zf.getinfo(filepath)
except KeyError:
return Response(
f"ZIP file must contain a file named exactly {filepath!r}.\n"
names = zf.namelist()
message = (
f"ZIP file must contain a file named exactly {filepath!r}.\n\n"
"Found the following files:\n " +
"\n ".join(zf.namelist()),
"\n ".join(zf.namelist())
)

search = '/' + filepath
for name in names:
if name.endswith(search):
prefix = name[:-len(filepath)]
message += (
"\n\n"
"It looks like you have included a similar file at "
f"{name!r}, perhaps you meant to include that file at "
f"{filepath!r} rather than within {prefix!r}?"
)

return Response(
message,
status_code=400,
)

Expand Down