Erb location of exception in template

L

Leslie Viljoen

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:in `interpret'
from (erb):285:in `each'
from (erb):285:in `interpret'
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
 
L

Leslie Viljoen

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)
=A0 =A0 =A0 =A0from (erb):285:in `interpret'
=A0 =A0 =A0 =A0from (erb):285:in `each'
=A0 =A0 =A0 =A0from (erb):285:in `interpret'
=A0 =A0 =A0 =A0from build.rb:26:in `interpret'
=A0 =A0 =A0 =A0from 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!
 
B

Brian Candler

Leslie Viljoen 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:in `interpret'
from (erb):285:in `each'
from (erb):285:in `interpret'
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.
 
L

Leslie Viljoen

#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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top