Class: WGPU::GPUError

Inherits:
Data
  • Object
show all
Defined in:
lib/wgpu/error.rb,
sig/wgpu.rbs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, message) ⇒ void #initialize(type:, message:) ⇒ void

Creates a typed GPU error with its native category and diagnostic message.

Overloads:

  • #initialize(type, message) ⇒ void

    Parameters:

    • type (Symbol)
    • message (String)
  • #initialize(type:, message:) ⇒ void

    Parameters:

    • type: (Symbol)
    • message: (String)


79
80
# File 'sig/wgpu.rbs', line 79

def initialize: (Symbol type, String message) -> void
| (type: Symbol, message: String) -> void

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



33
34
35
# File 'lib/wgpu/error.rb', line 33

def message
  @message
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



33
34
35
# File 'lib/wgpu/error.rb', line 33

def type
  @type
end

Class Method Details

.from_hash(error) ⇒ GPUError?

Converts a native error-scope result into a typed error.

Parameters:

  • error (Hash, nil)

    native error result

Returns:



37
38
39
40
41
# File 'lib/wgpu/error.rb', line 37

def self.from_hash(error)
  return if error.nil? || error[:type].nil? || error[:type] == :no_error

  new(type: error[:type], message: error[:message].to_s)
end

Instance Method Details

#exception_classClass<Error>

Returns the Ruby exception class matching this GPU error type.

Returns:



45
46
47
48
49
50
51
52
# File 'lib/wgpu/error.rb', line 45

def exception_class
  {
    validation: ValidationError,
    out_of_memory: OutOfMemoryError,
    internal: InternalError,
    device_lost: DeviceLostError
  }.fetch(type, Error)
end

#raise!void

This method returns an undefined value.

Raises this error as its matching Ruby exception.

Raises:



57
58
59
# File 'lib/wgpu/error.rb', line 57

def raise!
  raise exception_class, "GPU error (#{type}): #{message}"
end

#to_hHash

Returns a serializable representation of the error.

Returns:

  • (Hash)


63
64
65
# File 'lib/wgpu/error.rb', line 63

def to_h
  { type:, message: }
end