[PR #1227] [MERGED] fix: make user data export download return 404 for nonexistent files #4809

Closed
opened 2026-04-16 13:16:48 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-vikunja/vikunja/pull/1227
Author: @Copilot
Created: 8/3/2025
Status: Merged
Merged: 8/3/2025
Merged by: @kolaente

Base: mainHead: copilot/fix-1226


📝 Commits (6)

  • f6fb0ea Initial plan
  • 3536bc9 Fix user data export download to return 404 for nonexistent files
  • d13e7ef Complete fix for user data export download 404 error handling
  • dd24f42 Address feedback: remove unit tests and add proper webtest coverage for 404 behavior
  • 179e347 Fix test fixtures to properly test 404 behavior for missing export files
  • 0ccff12 Address review feedback: revert fixture changes, fix error handling, and use consistent error messages

📊 Changes

2 files changed (+63 additions, -0 deletions)

View changed files

📝 pkg/routes/api/v1/user_export.go (+14 -0)
pkg/webtests/user_export_download_test.go (+49 -0)

📄 Description

The DownloadUserDataExport endpoint was causing a 500 Internal Server Error with message "file 0 does not exist" when users attempted to download a data export that didn't exist, instead of returning an appropriate 404 response.

Problem

When a user has no export file (ExportFileID = 0) or the export file exists in the database but the actual file is missing, the endpoint would attempt to load the file metadata without validation, resulting in:

files.ErrFileDoesNotExist: file 0 does not exist
*echo.HTTPError: code=500, message=Internal Server Error, internal=file 0 does not exist

Solution

Added proper validation to check file existence before attempting to load:

  1. Check for no export file: Return 404 "No user data export found." when ExportFileID = 0
  2. Handle missing files: Return 404 "No user data export found." when LoadFileMetaByID() fails with ErrFileDoesNotExist or when LoadFileByID() fails due to missing physical file
  3. Consistent error messaging: All 404 scenarios now return the same error message using a shared variable
  4. Updated Swagger docs: Added 404 response documentation

The fix follows the same pattern used in the existing GetUserExportStatus function and ensures users receive appropriate HTTP status codes for all missing file scenarios.

Changes

  • Modified DownloadUserDataExport function in /pkg/routes/api/v1/user_export.go
  • Added comprehensive test coverage for both scenarios in webtests
  • Updated API documentation to reflect new 404 responses
  • Used consistent error messages across all 404 cases

Fixes #1226.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-vikunja/vikunja/pull/1227 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 8/3/2025 **Status:** ✅ Merged **Merged:** 8/3/2025 **Merged by:** [@kolaente](https://github.com/kolaente) **Base:** `main` ← **Head:** `copilot/fix-1226` --- ### 📝 Commits (6) - [`f6fb0ea`](https://github.com/go-vikunja/vikunja/commit/f6fb0eae0537a0f9e6f597b55172b897055fc647) Initial plan - [`3536bc9`](https://github.com/go-vikunja/vikunja/commit/3536bc9ec09717c0c8e8a656f5fbe896151cce2d) Fix user data export download to return 404 for nonexistent files - [`d13e7ef`](https://github.com/go-vikunja/vikunja/commit/d13e7ef0eab87ce0f9e3ab526913f0d8cd009f0c) Complete fix for user data export download 404 error handling - [`dd24f42`](https://github.com/go-vikunja/vikunja/commit/dd24f421eb21e3f54b63dc99f604da22e8a67a01) Address feedback: remove unit tests and add proper webtest coverage for 404 behavior - [`179e347`](https://github.com/go-vikunja/vikunja/commit/179e3477b5e3987a40fd1a212a6234d1e8da23c8) Fix test fixtures to properly test 404 behavior for missing export files - [`0ccff12`](https://github.com/go-vikunja/vikunja/commit/0ccff12eb066733d323a5c39def8cb91f1374150) Address review feedback: revert fixture changes, fix error handling, and use consistent error messages ### 📊 Changes **2 files changed** (+63 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `pkg/routes/api/v1/user_export.go` (+14 -0) ➕ `pkg/webtests/user_export_download_test.go` (+49 -0) </details> ### 📄 Description The `DownloadUserDataExport` endpoint was causing a 500 Internal Server Error with message "file 0 does not exist" when users attempted to download a data export that didn't exist, instead of returning an appropriate 404 response. ## Problem When a user has no export file (`ExportFileID = 0`) or the export file exists in the database but the actual file is missing, the endpoint would attempt to load the file metadata without validation, resulting in: ``` files.ErrFileDoesNotExist: file 0 does not exist *echo.HTTPError: code=500, message=Internal Server Error, internal=file 0 does not exist ``` ## Solution Added proper validation to check file existence before attempting to load: 1. **Check for no export file**: Return 404 "No user data export found." when `ExportFileID = 0` 2. **Handle missing files**: Return 404 "No user data export found." when `LoadFileMetaByID()` fails with `ErrFileDoesNotExist` or when `LoadFileByID()` fails due to missing physical file 3. **Consistent error messaging**: All 404 scenarios now return the same error message using a shared variable 4. **Updated Swagger docs**: Added 404 response documentation The fix follows the same pattern used in the existing `GetUserExportStatus` function and ensures users receive appropriate HTTP status codes for all missing file scenarios. ## Changes - Modified `DownloadUserDataExport` function in `/pkg/routes/api/v1/user_export.go` - Added comprehensive test coverage for both scenarios in webtests - Updated API documentation to reflect new 404 responses - Used consistent error messages across all 404 cases Fixes #1226. <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-16 13:16:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#4809