Exception: UU::OS::IPC::IPCError

Inherits:
StandardError
  • Object
show all
Defined in:
uu_os_connection-2.2.4/lib/uu/os/ipc/ipc_error.rb

Overview

Ancestor of all errors caused by inter-process communication.

Direct Known Subclasses

Application::ApplicationError

Constant Summary

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (IPCError) initialize(*args)

Creates new instance of IPCError. If kind is not given, error is created as SERVER.

Parameters:

  • args (Array<Object>)

    Instantiation parameters. Possible values are:

    • code [String], message [String]

    • code [String], attributes [Hash]

    • code [String], cause [Exception]

    • kind [String], code [String], message [String]

    • kind [String], code [String], attributes [Hash]

    • kind [String], code [String], cause [Exception]

    • kind [String], code [String], message [String], attributes [Hash]

    • kind [String], code [String], message [String], cause [Exception]

    • kind [String], code [String], message [String], attributes [Hash], cause [Exception]

    • data [String, Hash] (To be used only for instantiation of error from remote response!)



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'uu_os_connection-2.2.4/lib/uu/os/ipc/ipc_error.rb', line 52

def initialize(*args)
  @kind = nil
  @code = nil
  @message = nil
  @attributes = nil
  @detail_messages = nil
  @remote = false
  if args.size == 1
    @remote = true
    if args[0].kind_of?(Hash)
      initialize_from_hash(args[0])
    else
      begin
        initialize_from_json(args[0])
      rescue JSON::ParserError
        @message = args[0]
      end
    end
  elsif args.size == 2
    @code = args[0].to_s if !args[0].nil?
    if args[1].kind_of?(Hash)
      @attributes = args[1].dup
    elsif args[1].kind_of?(Exception)
      process_cause(args[1])
    else
      @message = args[1].to_s if !args[1].nil?
    end
  elsif args.size == 3
    # In case of three arguments, we can have either
    # [kind, code, attributes] or [code, message, attributes].
    # The only way to distinguish these options (because type
    # is [String, String, Hash] for both cases) is by checking
    # value of first argument.
    kind_defined = false
    UU::OS::IPC::ErrorKind.constants.each do |kind|
      if UU::OS::IPC::ErrorKind.const_get(kind) == args[0]
        kind_defined = true
        break
      end
    end
    if kind_defined
      @kind = args[0].to_s if !args[0].nil?
      @code = args[1].to_s if !args[1].nil?
    else
      @code = args[0].to_s if !args[0].nil?
      @message = args[1].to_s if !args[1].nil?
    end
    if args[2].kind_of?(Hash)
      @attributes = args[2].dup
    elsif args[2].kind_of?(Exception)
      process_cause(args[2])
    else
      @message = args[2].to_s if !args[2].nil?
    end
  elsif args.size == 4
    @kind = args[0].to_s if !args[0].nil?
    @code = args[1].to_s if !args[1].nil?
    @message = args[2].to_s if !args[2].nil?
    if args[3].kind_of?(Hash)
      @attributes = args[3].dup if !args[3].nil?
    elsif args[3].kind_of?(Exception)
      process_cause(args[3])
    else
      raise ArgumentError, "no implicit conversion of #{args[3].class} to Hash or Exception" if !args[3].nil?
    end
  elsif args.size == 5
    raise ArgumentError, "no implicit conversion of #{args[3].class} to Hash" if !args[3].nil? && !args[3].kind_of?(Hash)
    raise ArgumentError, "no implicit conversion of #{args[4].class} to Exception" if !args[4].nil? && !args[4].kind_of?(Exception)
    @kind = args[0].to_s if !args[0].nil?
    @code = args[1].to_s if !args[1].nil?
    @message = args[2].to_s if !args[2].nil?
    @attributes = args[3].dup if !args[3].nil?
    process_cause(args[4])
  elsif args.size != 0
    raise ArgumentError, "wrong number of arguments (#{args.size} for 0..5)"
  end
  @kind ||= UU::OS::IPC::ErrorKind::SERVER
  @code ||= UU::OS::IPC::ErrorCodes::UNEXPECTED_PROBLEM
  # Call ancestor constructor with default message
  super(format_message(@code, @message, @attributes))
end

Instance Attribute Details

- (Hash) attributes (readonly)

Additional error attributes.

Returns:

  • (Hash)

    Error attributes.



25
26
27
# File 'uu_os_connection-2.2.4/lib/uu/os/ipc/ipc_error.rb', line 25

def attributes
  @attributes
end

- (String) code (readonly)

Vendor defined error code.

Returns:

  • (String)

    Error code.



21
22
23
# File 'uu_os_connection-2.2.4/lib/uu/os/ipc/ipc_error.rb', line 21

def code
  @code
end

- (String) kind (readonly)

Kind of error (see ErrorKind for possible values).

Returns:

  • (String)

    Kind of error.



17
18
19
# File 'uu_os_connection-2.2.4/lib/uu/os/ipc/ipc_error.rb', line 17

def kind
  @kind
end

Instance Method Details

- (void) add_detail_message(code, message, attributes = {})

This method returns an undefined value.

Adds additional message to error.

Parameters:

  • code (String)

    Message code.

  • message (String)

    Message text.

  • attributes (Hash) (defaults to: {})

    Additional message attributes.



139
140
141
142
143
144
145
146
147
148
# File 'uu_os_connection-2.2.4/lib/uu/os/ipc/ipc_error.rb', line 139

def add_detail_message(code, message, attributes = {})
  @detail_messages ||= []
  if code.kind_of?(Hash)
    msg = code
  else
    msg = {code: code, message: message, attributes: attributes.dup}
  end
  msg[:code] ||= UU::OS::IPC::ErrorCodes::UNEXPECTED_PROBLEM
  @detail_messages << msg
end

- (List<Hash>) detail_messages

Returns list of detail messages in raw (unformatted) form.

Returns:

  • (List<Hash>)

    List of raw messages where each message has :code, :message and :attributes.



172
173
174
# File 'uu_os_connection-2.2.4/lib/uu/os/ipc/ipc_error.rb', line 172

def detail_messages
  return @detail_messages
end

- (Hash) main_message

Returns main exception message in raw (unformatted) form.

Returns:

  • (Hash)

    Raw message with :code, :message and :attributes.



165
166
167
# File 'uu_os_connection-2.2.4/lib/uu/os/ipc/ipc_error.rb', line 165

def main_message
  return {code: @code, message: @message, attributes: @attributes}
end

- (String) message

Returns formatted message (including detail messages).

Returns:

  • (String)

    Formatted message.



152
153
154
155
156
157
158
159
160
# File 'uu_os_connection-2.2.4/lib/uu/os/ipc/ipc_error.rb', line 152

def message
  tmp = format_message(@code, @message, @attributes)
  if !@detail_messages.nil? && !@detail_messages.empty?
    @detail_messages.each do |msg|
      tmp << "\n" << format_message(msg[:code], msg[:message], msg[:attributes])
    end
  end
  return tmp
end