[ic] Usertag return value

gert at 3edge.com gert at 3edge.com
Wed Feb 11 06:57:35 UTC 2009


Grant writes: 

>>> > but that kills the whole page.  What is the correct way to do this
>>> > so I can evaluate whether or not the tag executed properly? 
>>>
>>> You could use exceptions with an Interchange [try] block (see
>>> etc/log_transaction for an example), but I think a simple return
>>> value would suffice in this case. If you want a "0" return value when
>>> one or more of the sizes fails, then use a return value variable and
>>> only set it to true if all three succeed.
>>
>> Hey, 
>>
>> Right, there's a bunch of ways to do this, depending on
>> whether you want to know which one failed (and exit immediately),
>> or you want to run all three anyway and just indicate the exit
>> status more as an information than an error. 
>>
>> If you want to exit immediately when one fails, use i.e.: 
>>
>> do_resize(....) or return 0;
> 
> I'm getting strange results from this now.  My usertag is set up like this: 
> 
> do-stuff;
> write-file1 or return 0;
> chmod-file1;
> do-stuff;
> write-file2 or return 0;
> chmod-file2;
> do-stuff;
> write-file3 or return 0;
> chmod-file3; 
> 
> The usertags exits and returns 0, the first 2 write-file commands
> execute, and none of the chmod-file commands execute.  If I remove the
> "or return 0;" portions, everything executes perfectly.  Does that
> make sense to anyone?

Do you have a 'return 1;'  after the chmod-file3? 

> - Grant 
> 
> 
>> (The above assumes do_resize() indicates success with non-zero value.
>> If it instead indicates failure with non-zero value, replace "or" with
>> "and"). 
>>
>> Another approach, if you want to run all three always, and just use
>> exit status as an information to see which one(s) failed: 
>>
>> $ret= 0;
>> do_resize1(...) or $ret+= 1;
>> do_resize2(...) or $ret+= 2;
>> do_resize3(...) or $ret+= 4;
>> return $ret; 
>>
>> So if the tag exits with 0, it worked. Otherwise, the exit
>> status will be a sum of all resizes that failed. I.e. if
>> exit value is 5, it means resizes 1 and 3 failed. 
>>
>> Cya,
>> -doc
> 
> _______________________________________________
> interchange-users mailing list
> interchange-users at icdevgroup.org
> http://www.icdevgroup.org/mailman/listinfo/interchange-users
 




More information about the interchange-users mailing list