diff --git a/examples/error_not_found.html b/examples/error_not_found.html new file mode 100644 index 0000000..24369f7 --- /dev/null +++ b/examples/error_not_found.html @@ -0,0 +1 @@ +{{foo}} \ No newline at end of file diff --git a/examples/error_not_found.js b/examples/error_not_found.js new file mode 100644 index 0000000..6cdbdb3 --- /dev/null +++ b/examples/error_not_found.js @@ -0,0 +1 @@ +var error_not_found = {bar: 2}; \ No newline at end of file diff --git a/examples/error_not_found.txt b/examples/error_not_found.txt new file mode 100644 index 0000000..fc8d6b7 --- /dev/null +++ b/examples/error_not_found.txt @@ -0,0 +1 @@ +ERROR: 'foo' not found in context diff --git a/mustache.js b/mustache.js index 4f4b0c4..fbbb715 100644 --- a/mustache.js +++ b/mustache.js @@ -136,7 +136,7 @@ var Mustache = function() { if(context[name] !== undefined) { return context[name]; } - throw("Can't find " + name + " in " + context); + throw({message: "'" + name + "' not found in context"}); }, // Utility methods diff --git a/test/mustache_spec.rb b/test/mustache_spec.rb index 9b94840..f4bbb22 100644 --- a/test/mustache_spec.rb +++ b/test/mustache_spec.rb @@ -34,10 +34,10 @@ describe "mustache" do try { print(Mustache.to_html("{{#list}}{{x}}{{/list}}", {list: [{}]})); } catch(e) { - print('ERROR: ' + e); + print('ERROR: ' + e.message); } JS - run_js(js).should == "ERROR: Can't find x in [object Object]\n" + run_js(js).should == "ERROR: 'x' not found in context\n" end non_partials.each do |testname|