{"action":"created","issue":{"url":"https://api.github.com/repos/ACRA/acra/issues/522","repository_url":"https://api.github.com/repos/ACRA/acra","labels_url":"https://api.github.com/repos/ACRA/acra/issues/522/labels{/name}","comments_url":"https://api.github.com/repos/ACRA/acra/issues/522/comments","events_url":"https://api.github.com/repos/ACRA/acra/issues/522/events","html_url":"https://github.com/ACRA/acra/issues/522","id":182455084,"number":522,"title":"Empty report files with size 0 are not deleted when they are failed to be sent","user":{"login":"kboyarshinov","id":1917615,"avatar_url":"https://avatars.githubusercontent.com/u/1917615?v=3","gravatar_id":"","url":"https://api.github.com/users/kboyarshinov","html_url":"https://github.com/kboyarshinov","followers_url":"https://api.github.com/users/kboyarshinov/followers","following_url":"https://api.github.com/users/kboyarshinov/following{/other_user}","gists_url":"https://api.github.com/users/kboyarshinov/gists{/gist_id}","starred_url":"https://api.github.com/users/kboyarshinov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kboyarshinov/subscriptions","organizations_url":"https://api.github.com/users/kboyarshinov/orgs","repos_url":"https://api.github.com/users/kboyarshinov/repos","events_url":"https://api.github.com/users/kboyarshinov/events{/privacy}","received_events_url":"https://api.github.com/users/kboyarshinov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-10-12T07:33:14Z","updated_at":"2016-10-12T14:33:56Z","closed_at":null,"body":"Hello. \r\n\r\nWe had another issue while trying to recover the reports from one device. At first we found that some reports are being rejected by CouchDB server with 400 response. Later we found that some reports in `app_ACRA-approved` folder in application internal storage had 0 bytes size. Probably those files were created but writing to them failed. And the problem was that they are not deleted after sending failed.\r\n\r\nHaving 0 sized reports that are not deleted lead to situation when no reports are sent at all. Since there is a limit of 5 reports to send having 5 empty non-deleted reports blocks others from being sent.\r\nDeleting them manually from device storage solved the problem.\r\n\r\nSteps to reproduce:\r\n\r\n1. go to application internal storage: `adb shell run-as <package_name>`\r\n2. go to `app_ACRA-approved`: `cd app_ACRA-approved`\r\n3. create empty file: `echo \"\" > testreport.stacktrace`\r\n4. launch the application with ACRA enabled as: `ACRA.init(application, acraConfiguration);`\r\n5. See the stacktrace:\r\n```\r\nE/ACRA: Failed to send crash report for /data/data/<package_name>/app_ACRA-approved/testreport.stacktrace\r\n                                                           org.acra.sender.ReportSenderException: Error while sending JSON report via Http POST\r\n                                                               at org.acra.sender.HttpSender.send(HttpSender.java:239)\r\n                                                               at org.acra.sender.ReportDistributor.sendCrashReport(ReportDistributor.java:102)\r\n                                                               at org.acra.sender.ReportDistributor.distribute(ReportDistributor.java:70)\r\n                                                               at org.acra.sender.SenderService.onHandleIntent(SenderService.java:69)\r\n                                                               at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)\r\n                                                               at android.os.Handler.dispatchMessage(Handler.java:110)\r\n                                                               at android.os.Looper.loop(Looper.java:193)\r\n                                                               at android.os.HandlerThread.run(HandlerThread.java:61)\r\n                                                            Caused by: java.io.IOException: Host returned error code 400\r\n                                                               at org.acra.util.HttpRequest.send(HttpRequest.java:181)\r\n                                                               at org.acra.sender.HttpSender.send(HttpSender.java:235)\r\n                                                               at org.acra.sender.ReportDistributor.sendCrashReport(ReportDistributor.java:102) \r\n                                                               at org.acra.sender.ReportDistributor.distribute(ReportDistributor.java:70) \r\n                                                               at org.acra.sender.SenderService.onHandleIntent(SenderService.java:69) \r\n                                                               at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) \r\n                                                               at android.os.Handler.dispatchMessage(Handler.java:110) \r\n                                                               at android.os.Looper.loop(Looper.java:193) \r\n                                                               at android.os.HandlerThread.run(HandlerThread.java:61) \r\n```\r\n\r\nI think ACRA client needs to check if report file is empty and delete it without trying to send. Maybe simple change in `ReportDistributor` like that:\r\n\r\n```\r\n    public void distribute(@NonNull File reportFile) {\r\n        ...\r\n\r\n        if (reportFile.length() == 0) {\r\n            deleteFile(reportFile);\r\n            return;\r\n        }\r\n\r\n        ...\r\n    }\r\n\r\n```\r\n\r\nLet me know what you think.\r\nThank you."},"comment":{"url":"https://api.github.com/repos/ACRA/acra/issues/comments/253230537","html_url":"https://github.com/ACRA/acra/issues/522#issuecomment-253230537","issue_url":"https://api.github.com/repos/ACRA/acra/issues/522","id":253230537,"user":{"login":"F43nd1r","id":10252708,"avatar_url":"https://avatars.githubusercontent.com/u/10252708?v=3","gravatar_id":"","url":"https://api.github.com/users/F43nd1r","html_url":"https://github.com/F43nd1r","followers_url":"https://api.github.com/users/F43nd1r/followers","following_url":"https://api.github.com/users/F43nd1r/following{/other_user}","gists_url":"https://api.github.com/users/F43nd1r/gists{/gist_id}","starred_url":"https://api.github.com/users/F43nd1r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/F43nd1r/subscriptions","organizations_url":"https://api.github.com/users/F43nd1r/orgs","repos_url":"https://api.github.com/users/F43nd1r/repos","events_url":"https://api.github.com/users/F43nd1r/events{/privacy}","received_events_url":"https://api.github.com/users/F43nd1r/received_events","type":"User","site_admin":false},"created_at":"2016-10-12T14:33:56Z","updated_at":"2016-10-12T14:33:56Z","body":"Once we switch to json as proposed in #517, we should probably just delete files which do not contain valid json. This would include empty files."}}
{"actor":{"display_login":"F43nd1r"}}