From 16a9064eb8af8bbe9ef884df1d975927a809ea01 Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Tue, 9 Jun 2026 23:27:45 +0800 Subject: [PATCH] Fix silent file write failure in write_compute_project_file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The inner try-except caught OSError/UnicodeEncodeError with 'pass', silently swallowing all write failures and returning HTTP 204 as if the file was written successfully. Remove the nested try-except and let errors propagate properly: - OSError → 500 with error detail - PermissionError → 403 (already handled) - FileNotFoundError → 404 (already handled) --- gns3server/api/routes/compute/projects.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gns3server/api/routes/compute/projects.py b/gns3server/api/routes/compute/projects.py index 68ad27dc5..f56094b07 100644 --- a/gns3server/api/routes/compute/projects.py +++ b/gns3server/api/routes/compute/projects.py @@ -194,17 +194,17 @@ async def write_compute_project_file( try: os.makedirs(os.path.dirname(path), exist_ok=True) - try: - with open(path, "wb+") as f: - async for chunk in request.stream(): - f.write(chunk) - except (UnicodeEncodeError, OSError) as e: - pass # FIXME + with open(path, "wb+") as f: + async for chunk in request.stream(): + f.write(chunk) except FileNotFoundError: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) except PermissionError: raise HTTPException(status_code=status.HTTP_403_FORBIDDEN) + except OSError as e: + log.error(f"Error writing file '{path}': {e}") + raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e)) @router.delete("/projects/{project_id}/files/{file_path:path}", status_code=status.HTTP_204_NO_CONTENT)