Exception: Fluent::Win32Error

Inherits:
StandardError
  • Object
show all
Includes:
Windows::Error
Defined in:
lib/fluent/plugin/file_wrapper.rb

Constant Summary collapse

WSABASEERR =
10000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errcode, msg = nil) ⇒ Win32Error

Returns a new instance of Win32Error.



57
58
59
60
# File 'lib/fluent/plugin/file_wrapper.rb', line 57

def initialize(errcode, msg = nil)
  @errcode = errcode
  @msg = msg
end

Instance Attribute Details

#errcodeObject (readonly)

Returns the value of attribute errcode.



53
54
55
# File 'lib/fluent/plugin/file_wrapper.rb', line 53

def errcode
  @errcode
end

#msgObject (readonly)

Returns the value of attribute msg.



53
54
55
# File 'lib/fluent/plugin/file_wrapper.rb', line 53

def msg
  @msg
end

Instance Method Details

#==(other) ⇒ Object



81
82
83
84
# File 'lib/fluent/plugin/file_wrapper.rb', line 81

def ==(other)
  return false if other.class != Win32Error
  @errcode == other.errcode && @msg == other.msg
end

#format_english_message(errcode) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/fluent/plugin/file_wrapper.rb', line 62

def format_english_message(errcode)
  buf = 0.chr * 260
  flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY
  english_lang_id = 1033 # The result of MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)
  FormatMessageA.call(flags, 0, errcode, english_lang_id, buf, buf.size, 0)
  buf.force_encoding(Encoding.default_external).strip
end

#inspectObject



77
78
79
# File 'lib/fluent/plugin/file_wrapper.rb', line 77

def inspect
  "#<#{to_s}>"
end

#to_sObject



70
71
72
73
74
75
# File 'lib/fluent/plugin/file_wrapper.rb', line 70

def to_s
  msg = super
  msg << ": code: #{@errcode}, #{format_english_message(@errcode)}"
  msg << " - #{@msg}" if @msg
  msg
end

#wsaerr?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/fluent/plugin/file_wrapper.rb', line 86

def wsaerr?
  @errcode >= WSABASEERR
end