Class: WGPU::GPUError
- Inherits:
-
Data
- Object
- Data
- WGPU::GPUError
- Defined in:
- lib/wgpu/error.rb,
sig/wgpu.rbs
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.from_hash(error) ⇒ GPUError?
Converts a native error-scope result into a typed error.
Instance Method Summary collapse
-
#exception_class ⇒ Class<Error>
Returns the Ruby exception class matching this GPU error type.
-
#initialize ⇒ GPUError
constructor
Creates a typed GPU error with its native category and diagnostic message.
-
#raise! ⇒ void
Raises this error as its matching Ruby exception.
-
#to_h ⇒ Hash
Returns a serializable representation of the error.
Constructor Details
#initialize(type, message) ⇒ void #initialize(type:, message:) ⇒ void
Creates a typed GPU error with its native category and diagnostic message.
79 80 |
# File 'sig/wgpu.rbs', line 79
def initialize: (Symbol type, String message) -> void
| (type: Symbol, message: String) -> void
|
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message
33 34 35 |
# File 'lib/wgpu/error.rb', line 33 def @message end |
#type ⇒ Object (readonly)
Returns the value of attribute 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.
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_class ⇒ Class<Error>
Returns the Ruby exception class matching this GPU error type.
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.
57 58 59 |
# File 'lib/wgpu/error.rb', line 57 def raise! raise exception_class, "GPU error (#{type}): #{}" end |
#to_h ⇒ Hash
Returns a serializable representation of the error.
63 64 65 |
# File 'lib/wgpu/error.rb', line 63 def to_h { type:, message: } end |