lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Reporting errors with context


From: Vadim Zeitlin
Subject: Re: [lmi] Reporting errors with context
Date: Mon, 10 Jun 2019 18:31:07 +0200

On Tue, 4 Jun 2019 02:16:35 +0200 I wrote:

VZ> On Sun, 2 Jun 2019 22:33:03 +0000 Greg Chicares <address@hidden> wrote:
VZ> 
VZ> [...we agreed on including the current page name in all exceptions thrown
VZ>     by pdf_writer_wx...]
VZ> 
VZ> GC> My only objection here is to the macro. If adding a pdf-specific macro
VZ> GC> here is a good idea, then other sections of lmi should have their own
VZ> GC> section-specific macros, and we'll have lots of macros. But I don't
VZ> GC> think we want macros to proliferate. Couldn't the extra information be
VZ> GC> passed by reusing the existing LMI_ASSERT_WITH_MSG macro, perhaps
VZ> GC> enhancing it in a general way to take an optional "CONTEXT" parameter?
[...]
VZ>  The straightforward way of addressing both of these concerns at once would
VZ> be by adding "the current context", i.e. some global (or a global by any
VZ> other name, i.e. a singleton, a static member variable or whatever)
VZ> containing the extra information to be used by any LMI_ASSERT() invocation.
VZ> This could be then actually done even outside of pdf_writer_wx, in
VZ> pdf_command_wx.cpp itself and in a single place inside render_all() only.

 Thinking more about this, I have no idea what's wrong with doing it in the
following extremely simple way: just add try/catch block around the loops
iterating over the pages in pdf_command_wx.cpp and rethrow any exception
caught by it after appending the information about the page in which it
happened. This doesn't require any macros and all the changes are localized
in one place only. It also has the advantage of catching all errors, and
not only those generated by pdf_writer_wx.

 The only possible drawback I can see is that not doing it inside
pdf_writer_wx class means that any other users of this class would need to
do something similar, duplicating pdf_illustration code, if they wanted to
include information about the faulty page in their error messages. But the
only other existing user, group_quote_pdf_generator_wx, probably doesn't
need to do this at all (please correct me if I'm wrong), and I'm not sure
if we're going to have any more, so it doesn't seem wise to do something
more complicated today just in case we'll need it in the future.


 Of course, even this simple solution still requires assigning a name for
each page, so that it could be used in the diagnostic messages, but this is
something that seems useful to do anyhow (e.g. I'd like to see the name of
the current page under the debugger). I have a separate question about this
name: do you think we could just reuse the names of the template files, for
the pages using them, or would you prefer to use something more readable?
I.e. would you rather see "First logical notes page of a regular individual
illustration" or would "reg_d_indiv_notes1" be good enough?

 Thanks in advance,
VZ

Attachment: pgpHLvxY6b9g0.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]