{"action":"created","issue":{"url":"https://api.github.com/repos/colszowka/simplecov/issues/406","labels_url":"https://api.github.com/repos/colszowka/simplecov/issues/406/labels{/name}","comments_url":"https://api.github.com/repos/colszowka/simplecov/issues/406/comments","events_url":"https://api.github.com/repos/colszowka/simplecov/issues/406/events","html_url":"https://github.com/colszowka/simplecov/issues/406","id":100956806,"number":406,"title":"Undefined method each for Nil in result_merger","user":{"login":"JanStevens","id":1540483,"avatar_url":"https://avatars.githubusercontent.com/u/1540483?v=3","gravatar_id":"","url":"https://api.github.com/users/JanStevens","html_url":"https://github.com/JanStevens","followers_url":"https://api.github.com/users/JanStevens/followers","following_url":"https://api.github.com/users/JanStevens/following{/other_user}","gists_url":"https://api.github.com/users/JanStevens/gists{/gist_id}","starred_url":"https://api.github.com/users/JanStevens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JanStevens/subscriptions","organizations_url":"https://api.github.com/users/JanStevens/orgs","repos_url":"https://api.github.com/users/JanStevens/repos","events_url":"https://api.github.com/users/JanStevens/events{/privacy}","received_events_url":"https://api.github.com/users/JanStevens/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-14T07:59:45Z","updated_at":"2015-11-28T19:21:33Z","closed_at":null,"body":"Hello,\r\n\r\nUsing latest ruby/simplecov/jenkins.\r\nOn our jenkins build system we sometimes see the following error returning when all specs passed and simplecov starts building its report:\r\n\r\n```\r\nCoverage report generated for  to /var/lib/jenkins/jobs/SpaceCII/workspace/coverage. 16478 / 19835 LOC (83.08%) covered.\r\n/var/lib/jenkins/jobs/SpaceCI/workspace/vendor/bundle/ruby/2.2.0/gems/simplecov-0.10.0/lib/simplecov/result_merger.rb:47:in `results': undefined method `each' for nil:NilClass (NoMethodError)\r\n\tfrom /var/lib/jenkins/jobs/SpaceCI/workspace/vendor/bundle/ruby/2.2.0/gems/simplecov-0.10.0/lib/simplecov/result_merger.rb:69:in `merged_result'\r\n\tfrom /var/lib/jenkins/jobs/SpaceCI/workspace/vendor/bundle/ruby/2.2.0/gems/simplecov-0.10.0/lib/simplecov.rb:61:in `result'\r\n\tfrom /var/lib/jenkins/jobs/SpaceCI/workspace/vendor/bundle/ruby/2.2.0/gems/simplecov-0.10.0/lib/simplecov/configuration.rb:159:in `block in at_exit'\r\n\tfrom /var/lib/jenkins/jobs/SpaceCI/workspace/vendor/bundle/ruby/2.2.0/gems/simplecov-0.10.0/lib/simplecov/defaults.rb:60:in `call'\r\n\tfrom /var/lib/jenkins/jobs/SpaceCI/workspace/vendor/bundle/ruby/2.2.0/gems/simplecov-0.10.0/lib/simplecov/defaults.rb:60:in `block in <top (required)>'\r\n```\r\n\r\nLooking at the code I see that `resultset` can return `nil` when the `stored_data` returns `nil`. For some reason the data is not written yet to the file so simplecov fails. I find this failing a bit ugly. Would it be more preferred to always return a Hash, even when the reading of JSON data fails?\r\n\r\nIn [result_merger.rb](https://github.com/colszowka/simplecov/blob/master/lib%2Fsimplecov%2Fresult_merger.rb?ts=2#L21)\r\n\r\n```\r\n# Loads the cached resultset from JSON and returns it as a Hash\r\n      def resultset\r\n        if stored_data\r\n          begin\r\n            JSON.parse(stored_data) || {}\r\n          rescue\r\n            {}\r\n          end\r\n        else\r\n          {}\r\n        end\r\n      end\r\n```\r\n\r\nThis would prevent simplecov to generate an error but wont generate any reporting. Willing to make a PR to fix this issue. I believe a race condition might exists, for large projects the system is not complete done writing to the file but simplecov already starts reading it, resulting in an empty file. Don't know how to solve that issue\r\n\r\nRegards"},"comment":{"url":"https://api.github.com/repos/colszowka/simplecov/issues/comments/160330337","html_url":"https://github.com/colszowka/simplecov/issues/406#issuecomment-160330337","issue_url":"https://api.github.com/repos/colszowka/simplecov/issues/406","id":160330337,"user":{"login":"xaviershay","id":1714,"avatar_url":"https://avatars.githubusercontent.com/u/1714?v=3","gravatar_id":"","url":"https://api.github.com/users/xaviershay","html_url":"https://github.com/xaviershay","followers_url":"https://api.github.com/users/xaviershay/followers","following_url":"https://api.github.com/users/xaviershay/following{/other_user}","gists_url":"https://api.github.com/users/xaviershay/gists{/gist_id}","starred_url":"https://api.github.com/users/xaviershay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xaviershay/subscriptions","organizations_url":"https://api.github.com/users/xaviershay/orgs","repos_url":"https://api.github.com/users/xaviershay/repos","events_url":"https://api.github.com/users/xaviershay/events{/privacy}","received_events_url":"https://api.github.com/users/xaviershay/received_events","type":"User","site_admin":false},"created_at":"2015-11-28T19:21:33Z","updated_at":"2015-11-28T19:21:33Z","body":"``` ruby\r\nJSON.parse(stored_data)\r\n```\r\n\r\nHow can you make this call return `nil`? Without using `quirks_mode`, I can't see a way to do it. Any empty or nil value will raise instead. Given I can't come up with a repro, I'm not convinced that just putting in a guard here will fix.\r\n\r\nGiven you only see this sometimes, it must be some kind of race condition. I just don't know what :/"}}