Erb location of exception in template

Hiya!

Does anyone know how I can find the location in an Erb template file
of a line that caused an exception?

The result of calling erb.result(binding) in build.rb looks like this:

./dgp_api.rb:199:in type': ArgumentError (ArgumentError) from (erb):285:ininterpret’
from (erb):285:in each' from (erb):285:ininterpret’
from build.rb:26:in `interpret’
from build.rb:41

I want to know which template line caused the exception in dgp_api.rb.
If this can’t be done with erb, can it be done with eruby or erubis?

Leslie

Leslie V. wrote in post #956108:

Hiya!

Does anyone know how I can find the location in an Erb template file
of a line that caused an exception?

The result of calling erb.result(binding) in build.rb looks like this:

./dgp_api.rb:199:in type': ArgumentError (ArgumentError) from (erb):285:ininterpret’
from (erb):285:in each' from (erb):285:ininterpret’
from build.rb:26:in `interpret’
from build.rb:41

I want to know which template line caused the exception in dgp_api.rb.
If this can’t be done with erb, can it be done with eruby or erubis?

erb can definitely do it, at least the command line tool can:

$ erb
hello
world
<% foo %>
the
end
^D
-:3: undefined local variable or method `foo’ for main:Object
(NameError)

So try looking at the source for that (it’s /usr/bin/erb on my Ubuntu
box). The following code works for me:

require ‘erb’

src = <<EOS
hello
world
<% foo %>
the
end
EOS

erb = ERB.new(src)
puts erb.result

#Result:
#(erb):3: undefined local variable or method `foo’ for main:Object
(NameError)

This is with:
$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]

HTH,

Brian.

#Result:
#(erb):3: undefined local variable or method `foo’ for main:Object
(NameError)

This is with:
$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]

Thanks Brian!

On Thu, Oct 21, 2010 at 6:15 PM, Leslie V.
[email protected] wrote:

from (erb):285:in interpret' from build.rb:26:ininterpret’
from build.rb:41

I want to know which template line caused the exception in dgp_api.rb.
If this can’t be done with erb, can it be done with eruby or erubis?

Ah, never mind, the 285 is the line number in the template!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs