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

Add Errno#errno_message getter #6702

Merged
merged 6 commits into from Jan 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/errno.cr
Expand Up @@ -204,8 +204,11 @@ class Errno < Exception
# Returns the numeric value of errno.
getter errno : Int32

# Creates a new Errno with the given message. The message will
# have concatenated the message denoted by `Errno#value`.
# Returns the message of errno.
getter errno_message : String

# Creates a new `Errno` with the given message. The message will
# have concatenated the errno message denoted by *errno*.
#
# Typical usage:
#
Expand All @@ -217,7 +220,8 @@ class Errno < Exception
# ```
def initialize(message, errno = Errno.value)
@errno = errno
super "#{message}: #{String.new(LibC.strerror(errno))}"
@errno_message = String.new(LibC.strerror(@errno))
super "#{message}: #{@errno_message}"
end

# Returns the value of libc's errno.
Expand All @@ -232,7 +236,7 @@ class Errno < Exception
LibC.__error.value
{% elsif flag?(:win32) %}
ret = LibC._get_errno(out errno)
raise Errno.new("get_errno", ret) unless ret == 0
raise Errno.new("_get_errno", ret) unless ret == 0
errno
{% end %}
end
Expand All @@ -249,7 +253,7 @@ class Errno < Exception
LibC.__error.value = value
{% elsif flag?(:win32) %}
ret = LibC._set_errno(value)
raise Errno.new("set_errno", ret) unless ret == 0
raise Errno.new("_set_errno", ret) unless ret == 0
value
{% end %}
end
Expand Down