Re: internal error

calmar <[email protected]> Sat, 17 Dec 2005 20:05:46 +0100
Newsgroups gmane.comp.tools.aap.devel
Message-ID <[email protected]>
On Sat, Dec 17, 2005 at 04:24:03PM +0100, Bram Moolenaar wrote:

Hi Bram,

> > ,------------------------------------------------------
> > | index_title =  whateverhere
> > |
> > | :rule %.php : %.part
> > |         tmpstring = _no.$(match)_title
> > |         @title = eval( tmpstring )
> > |
> > | files =
> > |     ./ddd/test.php
> > |     ./index.php
> > |
> > | all : $files
> > `---
> > 
> > It seems aap lets python evaluate a variable that does not
> > exist:   _no.test_title
> 
> Well, this happens in the eval() call, which is a Python function.  Thus
> you get a Python error message.
> 
> We could make an exception for errors in Scope.py, since this is
> probably a variable that doesn't exist.  Try this patch:

Yeah, that patch catches it.

There seems to be a bad(probably good anyway?) thing about it:

        tmpstring = _no.$(match)_title
        @try:
        @   title = eval(_no.tmpstring)
        @except:
        @   title = ""
        :print $title

that does not work anymore, because the error gets catched.

I think there is another way, to check if a variable exists:

       @if not hasattr(globals(), 'tmpstring'):
       @   print "variable is not defined"

That would work with checking for globals, but I think I would
need to check for the _no namespace? On #python they told me
something about dir(obj) but I can't get it to work.

How could I check if a variable is 'defined' without the @try:
@except: since that don't seems to work anymore with your patch?


Thanks a lot

marco

PS: I have that all, because I wanted to store 'some' variables
of some title of some pages at the top of the aap recipe, and
later 'trying' to get that value and replacing @TITLE@ with it,
if it exists. If it exists... that's the prob :)

PSII: I'm not even qualified to think about that, if it's ok to
catch all 'internal errors'.  But anyway (my thoughts): normally
'internal error' just sound 'bad', but it also seems to disable
that specific try constuct. But who (unless me) would need a
try/execpt construct? And when it's a user-failure to write
wrong python code with not defined variables, it's maybe ok to
get a normal python error output as you said it is. Called
internal or not.  It's not aap's fault so.

-- 
  calmar

          (o_  It rocks: LINUX + Command-Line-Interface
          //\
          V_/_                     http://www.calmar.ws


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click