stefankroes / scribble

Scribble is a customer facing template language similar to Liquid build in Ruby
MIT License
122 stars 7 forks source link

Objects that cannot be coerced into strings give bad error messages #8

Closed ryanong closed 9 years ago

ryanong commented 9 years ago

I'll try to get a working example of this soon.

stefankroes commented 9 years ago

Please, right now I don't really get what you mean.

Just out of curiosity, for what kind of project are you using Scribble?

ryanong commented 9 years ago

schoolkeep.com we are creating a custom templating feature so educators can have custom websites.

ryanong commented 9 years ago
Scribble::Template.new('{{ if true }}{{ no_to_string }}{{ end }}').render(variables: {no_to_string: Object.new})

will return

Class: <Scribble::Errors::Undefined>
Message: <"Undefined method 'if' at line 1 column 4">

Scribble::Template.new('{{ no_to_string }}').render(variables: {no_to_string: Object.new})

will return

Class: <Scribble::Support::Unmatched>
Message: <"Scribble::Support::Unmatched">

When it should return a different Error, like NoToString or UnCoerceable

stefankroes commented 9 years ago

Fixed in bd889cff108c1785cd28150763abd9b31782b44f

This now causes an informative RuntimeError as a missing cast method should cause a 500 in your application whereas subclasses of Scribble::Errors::Error are meant to be displayed to your users. You are supposed to only pass objects around Scribble that have both to_string and to_boolean and ideally also have a proper name. See lib/scribble/objects, this should also be implemented on Enumerable as we now support an each method.