Catch errors while evaluating node labels

This commit is contained in:
Michael Miller 2022-12-20 21:40:47 -07:00
parent 4a0bfc1cb2
commit 6a5e5b8f7a
No known key found for this signature in database
GPG Key ID: AC78B32D30CE34A2
2 changed files with 10 additions and 2 deletions

View File

@ -125,7 +125,11 @@ module Spectator::DSL
{% if what.is_a?(StringLiteral) || what.is_a?(NilLiteral) %}
{{what}}
{% elsif what.is_a?(StringInterpolation) %}
{{@type.name}}.new.eval { {{what}} }
{{@type.name}}.new.eval do
{{what}}
rescue e
"<Failed to evaluate example label - #{e.class}: #{e}>"
end
{% else %}
{{what.stringify}}
{% end %}

View File

@ -137,7 +137,11 @@ module Spectator::DSL
what.is_a?(NilLiteral) %}
{{what}}
{% elsif what.is_a?(StringInterpolation) %}
{{@type.name}}.new.eval { {{what}} }
{{@type.name}}.new.eval do
{{what}}
rescue e
"<Failed to evaluate context label - #{e.class}: #{e}>"
end
{% else %}
{{what.stringify}}
{% end %}