Skip to content

Fix error handling when parsing XML via IO.pipe#221

Merged
kou merged 1 commit into
ruby:masterfrom
naitoh:fix_io_pipe_error
Nov 19, 2024
Merged

Fix error handling when parsing XML via IO.pipe#221
kou merged 1 commit into
ruby:masterfrom
naitoh:fix_io_pipe_error

Conversation

@naitoh

@naitoh naitoh commented Nov 16, 2024

Copy link
Copy Markdown
Contributor

Why?

If via IO.pipe, IOError exception is not raised, but Errno::ESPIPE or Errno::EPIPE or Errno::EINVAL exception is raised.

  • CRuby
@er_source.pos
#=> Errno::ESPIPE Exception: Illegal seek
  • CRuby (Windows (Ruby 2.6 or earlier))
@er_source.pos
#=> Errno::EINVAL: Invalid argument
  • JRuby
@er_source.pos
#=> Errno::EPIPE: Broken pipe - No message available
@naitoh naitoh changed the title Fix error handling when parsing XML files via IO.pipe Nov 16, 2024
@naitoh naitoh marked this pull request as ready for review November 16, 2024 13:17
Comment thread lib/rexml/source.rb Outdated
end
@er_source.seek(pos)
rescue IOError
rescue IOError, Errno::EPIPE, Errno::ESPIPE, Errno::EINVAL

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use SystemCallError that is an ancestor class of them:

Suggested change
rescue IOError, Errno::EPIPE, Errno::ESPIPE, Errno::EINVAL
rescue IOError, SystemCallError

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.
I see.

## Why?

If via IO.pipe, `IOError` exception is not raised, but `Errno::ESPIPE` or `Errno::EPIPE` or `Errno::EINVAL` exception is raised.

- CRuby
```
@er_source.pos
#=> Errno::ESPIPE Exception: Illegal seek
```

- CRuby (Windows (Ruby 2.6 or earlier))
```
@er_source.pos
#=> Errno::EINVAL: Invalid argument
```

- JRuby
```
@er_source.pos
#=> Errno::EPIPE: Broken pipe - No message available
```

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
@naitoh naitoh requested a review from kou November 18, 2024 11:46
@kou kou merged commit 963ccdf into ruby:master Nov 19, 2024
@kou

kou commented Nov 19, 2024

Copy link
Copy Markdown
Member

Thanks.

@naitoh naitoh deleted the fix_io_pipe_error branch January 26, 2025 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants