Skip to content

Commit

Permalink
Return 404 when log files are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Feb 23, 2024
1 parent 5b08740 commit 5acd63e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/bartender/web/api/job/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,21 @@ async def get_completed_logs(
Raises:
ValueError: When job has no destination.
HTTPException: When a log file is not found.
Returns:
The standard output and error.
"""
if not job.destination or not job.internal_id:
raise ValueError("Job has no destination")
destination = context.destinations[job.destination]
return await destination.scheduler.logs(job.internal_id, job_dir)
try:
return await destination.scheduler.logs(job.internal_id, job_dir)
except FileNotFoundError as exc:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="File not found",
) from exc


CurrentLogs = Annotated[Tuple[str, str], Depends(get_completed_logs)]
Expand Down
19 changes: 19 additions & 0 deletions tests/web/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,25 @@ async def test_stderr(
assert response.headers["content-type"] == "text/plain; charset=utf-8"


@pytest.mark.anyio
async def test_stderr_missing(
fastapi_app: FastAPI,
client: AsyncClient,
auth_headers: Dict[str, str],
mock_ok_job: int,
job_root_dir: Path,
) -> None:
job_id = str(mock_ok_job)
fn = job_root_dir / str(job_id) / "stderr.txt"
fn.unlink()

url = fastapi_app.url_path_for("retrieve_job_stderr", jobid=job_id)
response = await client.get(url, headers=auth_headers)

assert response.status_code == status.HTTP_404_NOT_FOUND
assert response.json() == {"detail": "File not found"}


@pytest.mark.anyio
async def test_directories(
fastapi_app: FastAPI,
Expand Down

0 comments on commit 5acd63e

Please sign in to comment.