Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

naitoh
Copy link
Contributor

@naitoh naitoh commented Nov 16, 2024

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 Fix error handling when parsing XML via IO.pipe Nov 16, 2024
@naitoh naitoh marked this pull request as ready for review November 16, 2024 13:17
@@ -321,7 +321,7 @@ def current_line
rescue
end
@er_source.seek(pos)
rescue IOError
rescue IOError, Errno::EPIPE, Errno::ESPIPE, Errno::EINVAL
Copy link
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
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 <[email protected]>
@naitoh naitoh requested a review from kou November 18, 2024 11:46
@kou kou merged commit 963ccdf into ruby:master Nov 19, 2024
61 checks passed
@kou
Copy link
Member

kou commented Nov 19, 2024

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants