gEDA-dev: libgeda error reporting

Ivan Stankovic ivan.stankovic at fer.hr
Tue Jul 3 06:38:14 EDT 2007


On Mon, Jul 02, 2007 at 11:39:53PM -0700, Steve Meier wrote:
> g_error and g_warning are part of GLog which gtk itself uses.
> 
> So first determine what task you are trying to accomplish then use the
> best tool.

Alright, since it seems there is a confusion as to what I'm trying
to do, I'll try to explain the problem with an example.

In libgeda/src/a_basic.c there is 

void o_save_embedded(TOPLEVEL *w_current, OBJECT *object_list, FILE *fp)

with code like this:

switch (o_current->type) {

          case(OBJ_LINE):
            out = (char *) o_line_save(o_current);
            break;
                .
                .
                .

          default:
            fprintf(stderr, "Error type!\n");
            exit(-1);
            break;

This is plain wrong, because whatever the program calling
libgeda was doing, it should inform the user and display the
error string, not just die with a practically encrypted message.

I would rather see something like this:

/* Returns -1 on failure, 0 on success; I like this convention because
 * it is similar to the system calls convention, but of course we don't
 * have to do it this way */
int o_save_embedded(TOPLEVEL *w_current, OBJECT *object_list, FILE *fp)
                .
                .
                .

switch (o_current->type) {

          case(OBJ_LINE):
            out = (char *) o_line_save(o_current);
            break;
                .
                .
                .

          default:
            /* free whatever this function allocated... */
            /* then set the error string and return failure */
            libgeda_set_error(_("Unknown object type"));
            return -1;
            break;

Then the calling function would do

if(o_save_embedded(w_current, list, fp) < 0) {
        /* display error dialog with the string below*/
        gchar *str = libgeda_get_error();
        .
        .
        .
}

As another example, in o_read_buffer, we first check if the buffer
is NULL:

  if (buffer == NULL) {
    s_log_message("o_read_buffer: Received NULL buffer\n");
    return(NULL);
  }

Ales, I assume you were talking about this type of logging when
you said I shouldn't remove all logging calls. But I really think
the behaviour here should be just setting the error string and
returning NULL. In my opinion, either the library uses stdout/stderr
(or log file, doesn't matter) or it doesn't. So far I think it's 
pretty clear that I prefer the latter option. 

So, in short, the new approach I'm proposing would:

* get rid of printing/logging in libgeda (the log mechanism would
  still be present, just not used internally); this gives total 
  control to the calling program

* provide an familiar error mechanism

* make internationalization easy 

The only problems with this is making sure to be thread-safe
(by the way, anyone knows why is logfile_fd in s_log.c static and
what are the implications of that?) and the fact that this work
is huge, since there is lots of code involved, not to mention
the need to check all the calling functions etc. 

So I would really like to hear what everyone thinks before I
start coding.

PS. It is really funny how I got into all this, at first just
wanted to fix several gattrib bugs, then dugg deeper and now
look... 

-- 
Ivan Stankovic, ivan.stankovic at fer.hr

"Protect your digital freedom and privacy, eliminate DRM, 
learn more at http://www.defectivebydesign.org/what_is_drm"


More information about the geda-dev mailing list