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

SystemError: Fix inconsistent signature. #11002

Conversation

yxhuvud
Copy link
Contributor

@yxhuvud yxhuvud commented Jul 24, 2021

In .from_os_error the code looks like

message = self.build_message(message, **opts)
message =
  if message
    ..
  else
    ..
  end

which clearly doesn't make sense if build_message always return a
string.

In `.from_os_error` the code looks like
```
message = self.build_message(message, **opts)
message =
  if message
    ..
  else
    ..
  end
```
which clearly doesn't make sense if `build_message` always return a
string.
it "Can build an error from an errno" do
errno = Errno.new(11)
error = ::IO::Error.from_os_error(message: nil, os_error: errno)
error.message.should eq("Resource temporarily unavailable")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

LibC-specific. It will be interesting to see if it passes CI.

Copy link
Contributor Author

@yxhuvud yxhuvud Jul 24, 2021

Choose a reason for hiding this comment

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

It doesn't. On Mac it gives "Resource deadlock avoided". I'll change to match against /Resource/ unless someone has a better idea (like a suggestion for a more consistent errno to compare - I don't have access to a mac and I didn't find a list of errno messages it can give).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, it is a bit strange to get email about failed specs, but that it doesn't show up as broken in the github UI. Is that a known issue?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe the CI notification is for an older commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't be, I got two failure notifications and no obvious sign in the UI. But perhaps it was there but just not obvious enough 🤷

Copy link
Member

Choose a reason for hiding this comment

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

For the error messages, you can just compare the respective manpages (https://man7.org/linux/man-pages/man3/errno.3.html, https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/intro.2.html, https://www.freebsd.org/cgi/man.cgi?query=errno&sektion=2&format=html, etc.).

I suppose ENOENT should be pretty portable: No such file or directory.

@@ -85,7 +85,7 @@ module SystemError
#
# By default it returns the original message unchanged. But that could be
# customized based on the keyword arguments passed to `from_errno` or `from_winerror`.
protected def build_message(message, **opts) : String
protected def build_message(message, **opts) : String?
Copy link
Member

Choose a reason for hiding this comment

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

Could also add String? restriction to message like in from_os_error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. That won't affect functionality but I guess it ends up clearer.

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:system labels Jul 24, 2021
@yxhuvud yxhuvud force-pushed the fix/system_error_inconsistent_type_signatures branch from 7d4c515 to 559844d Compare July 24, 2021 12:58
Copy link
Member

@beta-ziliani beta-ziliani left a comment

Choose a reason for hiding this comment

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

Thanks @yxhuvud !

@beta-ziliani beta-ziliani added this to the 1.2.0 milestone Aug 10, 2021
@straight-shoota straight-shoota merged commit 7dabd57 into crystal-lang:master Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants