Skip to content

Errors in File.open #69

@MSP-Greg

Description

@MSP-Greg

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions