The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
Hey all
I'm trying to dynamically raise Exceptions from a macro, but when I instantiate the subclassed exception with a message, I get this error:Error: wrong number of arguments for 'Exception#initialize' (given 1, expected 2)
Can anyone see what i'm doing incorrectly?
macro generate_error_handling(klass_map)
{% for klass in klass_map.values %}
class {{ klass }} < Exception; end
{% end %}
private def handle_error(body)
if body["value"]? && body["value"].as_h? && body["value"]["error"]?
error = body["value"]
clazz = {{ klass_map }}[error["error"]?]
if clazz
raise clazz.new(error["message"].as_s)
end
end
end
generate_error_handling(
{
"invalid selector" => InvalidSelectorException,
"no such element" => ElementNotFoundException,
"invalid argument" => InvalidArgumentException,
#...
})
def handle_error(error)
{% begin %}
case error
{% for k, v in klass_map %}
when {{k}} then raise {{v}}.new(error)
{% end %}
end
{% end %}
end
raise UnknownMethodException.new
versus going thru the case at all
almost ready to beta my project!
https://github.com/skinnyjames/webdriver
It's a w3c compliant OO webdriver that pulls from the Watir api
cy.get('#username').click();
is what im familiar with