Exception: RightScale::Platform::Win32Error
- Inherits:
-
Exceptions::PlatformError
- Object
- StandardError
- Exceptions::PlatformError
- RightScale::Platform::Win32Error
- Defined in:
- lib/right_agent/platform/windows/platform.rb
Overview
exceptions
Instance Attribute Summary collapse
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
Instance Method Summary collapse
-
#error_message_for(error_code) ⇒ String
Queries raw error message for given error code.
-
#format_error_message(context, error_code) ⇒ String
Formats using system error message, if any.
-
#initialize(context, error_code = nil) ⇒ Win32Error
constructor
A new instance of Win32Error.
Constructor Details
#initialize(context, error_code = nil) ⇒ Win32Error
Returns a new instance of Win32Error.
48 49 50 51 |
# File 'lib/right_agent/platform/windows/platform.rb', line 48 def initialize(context, error_code = nil) @error_code = error_code || ::RightScale::Platform.windows_common.GetLastError() super((context, @error_code)) end |
Instance Attribute Details
#error_code ⇒ Object (readonly)
Returns the value of attribute error_code.
44 45 46 |
# File 'lib/right_agent/platform/windows/platform.rb', line 44 def error_code @error_code end |
Instance Method Details
#error_message_for(error_code) ⇒ String
Queries raw error message for given error code.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/right_agent/platform/windows/platform.rb', line 73 def (error_code) # this API won't respond with required buffer size if buffer is too # small; it returns zero and there is no way to tell if there is no # valid message or the buffer is too small. use a 4KB buffer to avoid # failure due to buffer size. buffer = 0.chr * 4096 flags = ::RightScale::Platform::WindowsCommon::FORMAT_MESSAGE_FROM_SYSTEM | ::RightScale::Platform::WindowsCommon::FORMAT_MESSAGE_IGNORE_INSERTS length = ::RightScale::Platform.windows_common.FormatMessage( flags, nil, error_code, 0, buffer, buffer.size, nil) buffer[0, length].strip end |
#format_error_message(context, error_code) ⇒ String
Formats using system error message, if any.
59 60 61 62 63 64 65 66 |
# File 'lib/right_agent/platform/windows/platform.rb', line 59 def (context, error_code) = (error_code) result = [] result << context.to_s if context && !context.empty? result << "Win32 error code = #{error_code}" result << if && !.empty? result.join("\n") end |