simplecov-html icon indicating copy to clipboard operation
simplecov-html copied to clipboard

Errors in File.open

Open MSP-Greg opened this issue 6 years ago • 2 comments

When working on Puma tests to mimic systemd, ran into a rather odd error. The following code: https://github.com/colszowka/simplecov-html/blob/9ec41504ab139fabfaddfc786dfdab5d6aca0bab/lib/simplecov-html.rb#L22-L24

threw errors as below:

Fabulous run in 2.374952s, 5.4738 runs/s, 29.4743 assertions/s.

13 runs, 70 assertions, 0 failures, 0 errors, 0 skips
SimpleCov.coverage_path puma/coverage
SimpleCov.coverage_path puma/coverage
Traceback (most recent call last):
        4: from simplecov-html-0.10.2/lib/simplecov-html.rb:22:in `format'
        3: from simplecov-html-0.10.2/lib/simplecov-html.rb:22:in `open'
        2: from simplecov-html-0.10.2/lib/simplecov-html.rb:23:in `block in format'
        1: from simplecov-html-0.10.2/lib/simplecov-html.rb:23:in `puts'
simplecov-html-0.10.2/lib/simplecov-html.rb:23:in `write': Bad file descriptor (Errno::EBADF)
        2: from simplecov-html-0.10.2/lib/simplecov-html.rb:22:in `format'
        1: from simplecov-html-0.10.2/lib/simplecov-html.rb:22:in `open'
simplecov-html-0.10.2/lib/simplecov-html.rb:22:in `close': Bad file descriptor @ fptr_finalize_flush - C:/Greg/GitHub/puma/coverage/index.html (Errno::EBADF)
rake aborted!
Command failed with status (1)

There's 'odd things' in the tests re fd's, etc, but the tests seem stable. When I changed the above code to the following, everything runs fine:

File.write(
  File.join(output_path, "index.html"),
  template("layout").result(binding),
  mode: "wb"
)

Why I'm getting the errors with File.open, but not File.write, I'm not sure, as I always considered them equivalent. Anyway, would this be accepted as a PR?

MSP-Greg avatar Oct 04 '19 19:10 MSP-Greg

That is.... more than strange. I'd probably accept it, however it seems like "programming by coincedence" to me a bit as I don't know or understand why that change fixes the bug which makes me rather uncomfortable :thinking:

PragTob avatar Oct 05 '19 14:10 PragTob

@MSP-Greg :wave:

Any updates from your side? A repo or something I can play around with this to see what's causing it?

PragTob avatar Feb 08 '20 16:02 PragTob