Report development without the need to restart GnuCash

Torsten Edeler torsten at edeler.org
Fri May 23 17:02:30 EDT 2008


Hi Charles.

Thank you for your answer.
I implemented the backtrace-if-exception method. Now an exception in options
doesn't crash the whole application but comes up with a minimal options
dialog.

This is the code (note the changes to your approach):

(define pagename-general "general")
(define (options-generator)
    (let ((options (gnc:new-options)))
        (gnc:backtrace-if-exception
            (lambda ()
                (load "/home/torsten/.gnucash/reports/myoptions.scm")
                (set! options (myoptions))
            )
        )
        options
    )
)


(define (renderer options)
    (load "/home/torsten/.gnucash/reports/renderer.scm")
    (myrenderer options)
)


(let ()
  (gnc:define-report
   'version 1
   'name (N_ "Trivial Example")
   'options-generator options-generator
   'renderer renderer)
)

I'm not very sure, if I just created a memory leak.... On every call to
options-generator the function gnc:new-options is called twice. Once outside
and once inside the myoptions function. I hope Scheme has some kind of
garbage collection to handle this.

Regards,
Torsten

2008/5/23 Charles Day <cedayiv at gmail.com>:

> On Fri, May 23, 2008 at 12:23 AM, Torsten Edeler <torsten at edeler.org>
> wrote:
>
>> Hi Charles.
>>
>> Well I didn't thing of a bug in the first place. I just thought my method
>> hasn't just been intended my the report framework.
>> I could open a bug if it is one (and not a feature) :-)
>>
>
> If I read your code correctly, you are passing your custom option loading
> procedure (named options-generator) and your custom renderer (named
> renderer), to a GnuCash reporting API procedure, gnc:define-report.  And
> apparently when these functions get called, an exception that occurs in the
> custom renderer is handled gracefully, but an exception that occurs in the
> custom option loader crashes the entire GnuCash application. From my way of
> thinking, the API should protect itself from any possible exception that
> might arise in the renderer OR the option loader.
>
> Regarding gnc-backtrace-if-exception: I don't have any clue what you are
>> talking about. As I wrote I'm very new to GnuCash and to Scheme. So if you
>> could describe your propose in more detail I could try to implement it.
>>
>
> Your code seems OK. I would think that the GnuCash reporting API should
> protect itself from exceptions that may arise in your custom code. But since
> I am not intimately familiar with reporting, perhaps one of the other
> developers could comment?
>
> If you want to try out exception handling, I would think that something
> like this would work. If an exception occurs, a backtrace is generated and
> (I think) the procedure returns #f:
>
> (define (options-generator)
>   (gnc:backtrace-if-exception
>     (lambda ()
>        (load "/home/torsten/.gnucash/reports/myoptions.scm")
>       (myoptions)))
> )
>
> By the way, I use vi for editing Scheme and C. It does do syntax
> highlighting, and parenthesis matching (% key) is really nice. But the
> learning curve is steep,and I am a vi diehard. :)
>
> Cheers,
> Charles
>
>
>> btw: I currently use Kate for editing Scheme files and I'm not really
>> satisfied with it. First of all there seems to be a bug in the bracket
>> matching and second it does not support code folding for Scheme. Could
>> somebody out there propose another (GUI) editor to me? I'm not gonna use
>> Emacs :-) I would use it too less to get familiar with all that cryptic key
>> combinations.
>>
>> Regards,
>> Torsten
>>
>> 2008/5/22 Charles Day <cedayiv at gmail.com>:
>>
>> On Thu, May 22, 2008 at 11:09 AM, Torsten Edeler <torsten at edeler.org>
>>> wrote:
>>>
>>>> Hi everybody.
>>>>
>>>> I'm quite new to GnuCash. Recently I felt the need to make my own report
>>>> adapted to my needs, since the existing reports were not suitable. After
>>>> taking a look to this obscure language Scheme - which I will probably
>>>> never
>>>> like :-) - the question rised how to develop reports without having the
>>>> need
>>>> to restart the whole application after a little bit of the report had to
>>>> be
>>>> changed. I searched the mailing list, but hadn't found anything usefull.
>>>>
>>>> I would like to present my solution to that problem to you. Perhaps it
>>>> has
>>>> already been solved (probably more elegant) by some of you or I missed
>>>> it in
>>>> the ml. Anyway this is what I use at the moment for development.
>>>>
>>>> I have the report file which is load by GnuCash on Startup:
>>>>
>>>> (define pagename-general "General")
>>>> (define (options-generator)
>>>>    (load "/home/torsten/.gnucash/reports/myoptions.scm")
>>>>    (myoptions)
>>>> )
>>>>
>>>>
>>>> (define (renderer options)
>>>>    (load "/home/torsten/.gnucash/reports/renderer.scm")
>>>>    (myrenderer options)
>>>> )
>>>>
>>>>
>>>> (let ()
>>>>  (gnc:define-report
>>>>   'version 1
>>>>   'name (N_ "Trivial Example")
>>>>   'options-generator options-generator
>>>>   'renderer renderer)
>>>> )
>>>>
>>>> As you can see the renderer and the options-generator include a file
>>>> load.
>>>> So everytime GnuCash executes one of the functions, a fresh version of
>>>> the
>>>> file is loaded and executet. The files itself defines a function
>>>> "myoption"
>>>> and "myrenderer" respectively. Note that the option-generator is only
>>>> executed after loading the report from the menu (or on startup), whereas
>>>> the
>>>> renderer is also executet after reloading or modification of the
>>>> options.
>>>>
>>>> Unfortunatly GnuCash is very sensible to errors in the option-generator,
>>>> since it simple terminates the whole application.
>>>
>>>
>>> This seems patently ungraceful. Why not include a
>>> gnc-backtrace-if-exception type of wrapper on options to prevent crashing?
>>> Is there a bug filed for this already? (Although I do a fair bit of work in
>>> Scheme, I plead ignorance to the report infrastructure.)
>>>
>>> Cheers,
>>> Charles
>>>
>>>
>>>> The renderer behaves more
>>>> nicely: Only an error message is displayed in the report window and one
>>>> has
>>>> the chance to modify the file and reload the report.
>>>>
>>>>
>>>> I hope this little texts helps some of you. At least it would have
>>>> helped me
>>>> :-)
>>>>
>>>> regards,
>>>> Torsten
>>>> _______________________________________________
>>>> gnucash-user mailing list
>>>> gnucash-user at gnucash.org
>>>> https://lists.gnucash.org/mailman/listinfo/gnucash-user
>>>> -----
>>>> Please remember to CC this list on all your replies.
>>>> You can do this by using Reply-To-List or Reply-All.
>>>>
>>>
>>>
>>
>


More information about the gnucash-user mailing list