|
40 | 40 | module SystemError
|
41 | 41 | macro included
|
42 | 42 | extend ::SystemError::ClassMethods
|
| 43 | + |
| 44 | + # Builds an instance of the exception from the current system error value (`Errno.value`). |
| 45 | + # |
| 46 | + # The system message corresponding to the OS error value amends the *message*. |
| 47 | + # Additional keyword arguments are forwarded to the exception initializer `.new_from_os_error`. |
| 48 | + macro from_errno(message, **opts) |
| 49 | + # This is a macro in order to retrieve `Errno.value` first before evaluating `message` and `opts`. |
| 50 | + %errno = Errno.value |
| 51 | + ::\{{@type}}.from_os_error(\{{ message }}, %errno, \{{ opts.double_splat }}) |
| 52 | + end |
| 53 | + |
| 54 | + @[Deprecated("Use `.from_os_error` instead")] |
| 55 | + macro from_errno(message = nil, errno = nil, **opts) |
| 56 | + ::\{{@type}}.from_os_error(\{{ message }}, \{{ errno }}, \{{ opts.double_splat }}) |
| 57 | + end |
43 | 58 | end
|
44 | 59 |
|
45 | 60 | # The original system error wrapped by this exception
|
@@ -68,19 +83,6 @@ module SystemError
|
68 | 83 | end
|
69 | 84 | end
|
70 | 85 |
|
71 |
| - # Builds an instance of the exception from the current system error value (`Errno.value`). |
72 |
| - # |
73 |
| - # The system message corresponding to the OS error value amends the *message*. |
74 |
| - # Additional keyword arguments are forwarded to the exception initializer `.new_from_os_error`. |
75 |
| - def from_errno(message : String, **opts) |
76 |
| - from_os_error(message, Errno.value, **opts) |
77 |
| - end |
78 |
| - |
79 |
| - @[Deprecated("Use `.from_os_error` instead")] |
80 |
| - def from_errno(message : String? = nil, errno : Errno? = nil, **opts) |
81 |
| - from_os_error(message, errno, **opts) |
82 |
| - end |
83 |
| - |
84 | 86 | # Prepares the message that goes before the system error description.
|
85 | 87 | #
|
86 | 88 | # By default it returns the original message unchanged. But that could be
|
|
0 commit comments