{"record":{"id":"ca5c3cd216453bb8","repo":"dutchcoders/transfer.sh","slug":"could-not-delete-file","errorCode":null,"errorMessage":"Could not delete file.","messagePattern":"Could not delete file\\.","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/handlers.go","lineNumber":962,"sourceCode":"\tvars := mux.Vars(r)\n\n\ttoken := vars[\"token\"]\n\tfilename := vars[\"filename\"]\n\tdeletionToken := vars[\"deletionToken\"]\n\n\tif err := s.checkDeletionToken(r.Context(), deletionToken, token, filename); err != nil {\n\t\ts.logger.Printf(\"Error metadata: %s\", err.Error())\n\t\thttp.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)\n\t\treturn\n\t}\n\n\terr := s.storage.Delete(r.Context(), token, filename)\n\tif s.storage.IsNotExist(err) {\n\t\thttp.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)\n\t\treturn\n\t} else if err != nil {\n\t\ts.logger.Printf(\"%s\", err.Error())\n\t\thttp.Error(w, \"Could not delete file.\", http.StatusInternalServerError)\n\t\treturn\n\t}\n}\n\nfunc (s *Server) zipHandler(w http.ResponseWriter, r *http.Request) {\n\tvars := mux.Vars(r)\n\n\tfiles := vars[\"files\"]\n\n\tzipfilename := fmt.Sprintf(\"transfersh-%d.zip\", uint16(time.Now().UnixNano()))\n\n\tw.Header().Set(\"Content-Type\", \"application/zip\")\n\tcommonHeader(w, zipfilename)\n\n\tzw := zip.NewWriter(w)\n\n\tfor _, key := range strings.Split(files, \",\") {\n\t\tkey = resolveKey(key, s.proxyPath)","sourceCodeStart":944,"sourceCodeEnd":980,"githubUrl":"https://github.com/dutchcoders/transfer.sh/blob/c37bfd95797fd6da8a6da53fc13d191994b3f687/server/handlers.go#L944-L980","documentation":"deleteHandler calls the storage backend's Delete and, for any error that is not a not-exist error, logs it and returns HTTP 500 'Could not delete file.'. This means the storage backend (local disk, S3, GCS, etc.) failed to delete the object for a reason other than the file being absent.","triggerScenarios":"s.storage.Delete returns a non-nil, non-IsNotExist error: permission denied on the storage dir/bucket, storage backend unreachable, request context canceled or timed out mid-delete, or a cloud API error other than NoSuchKey.","commonSituations":"Read-only mount or wrong permissions on the storage directory after a redeploy; expired/misconfigured cloud credentials lacking delete permission; network partition or throttling from the object store; client disconnecting and canceling the request context.","solutions":["Check server logs — the raw backend error is logged before the 500 is sent; fix the underlying storage error it reports.","Verify the storage directory/bucket permissions allow deletion for the user running the server (writable storage dir, IAM delete permission).","Confirm storage backend configuration (credentials, region, endpoint) is valid and the backend is reachable.","Increase timeouts or check for client-side cancellation; retry the delete."],"exampleFix":"// before\nerr := s.storage.Delete(r.Context(), token, filename)\n// after\nctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)\ndefer cancel()\nif err := s.storage.Delete(ctx, token, filename); err != nil && !s.storage.IsNotExist(err) {\n    s.logger.Printf(\"delete %s/%s: %v\", token, filename, err)\n}","handlingStrategy":"try-catch","validationCode":"// Verify the storage path is writable for deletes before calling the API:\nif f, err := os.CreateTemp(storageDir, \"probe\"); err == nil {\n    f.Close(); os.Remove(f.Name())\n} else {\n    // storage not writable: deletes will 500\n}","typeGuard":null,"tryCatchPattern":"// client side\nswitch resp.StatusCode {\ncase 404: // already gone — treat delete as idempotent success\ncase 500: // backend failure; check server logs, fix permissions/credentials, then retry\n}","preventionTips":["Run the server with write/delete permissions on the storage directory or bucket.","Keep cloud storage credentials valid and rotate before expiry.","Treat 404 on delete as success to make deletes idempotent.","Check the server log after a 500 — the real backend error is logged there."],"tags":["http-500","storage","delete"],"backgroundTag":"storage-delete-failed","analyzedSha":"c37bfd95797fd6da8a6da53fc13d191994b3f687","analyzedAt":"2026-09-05T10:21:07.548Z","contentChangedAt":"2026-09-05T10:21:07.548Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}