VMCAPIError now takes fn and res as args

This commit is contained in:
onyx-and-iris 2023-07-15 00:16:35 +01:00
parent 3c59c5d41c
commit 077a14fe62
2 changed files with 20 additions and 3 deletions

View File

@ -56,11 +56,11 @@ module Voicemeeter
res = send(fn, *args)
if exp.nil?
unless ok.include?(res)
raise Errors::VMCAPIError.new("#{fn} returned #{res}")
raise Errors::VMCAPIError.new(fn, res)
end
else
unless exp.call(res) && ok.include?(res)
raise Errors::VMCAPIError.new("#{fn} returned #{res}")
unless exp.call(res) || ok.include?(res)
raise Errors::VMCAPIError.new(fn, res)
end
end
res

View File

@ -1,9 +1,26 @@
require_relative "core_extensions/string/camelcase"
module Voicemeeter
module Errors
class VMError < StandardError
end
class VMCAPIError < VMError
attr_reader :code
def initialize(ruby_name, code)
@ruby_name = ruby_name
@code = code
super(message)
end
def message
"#{fn_name} returned #{code}"
end
def fn_name
"VBVMR_#{@ruby_name.to_s.delete_prefix("bind_").camelcase.sub("macro_button", "macrobutton")}"
end
end
end
end