[sane-devel] [SANE2 proposal] Error handling

Julien BLACHE jb at jblache.org
Fri Nov 28 17:12:19 GMT 2003


Hi,

Here's a proposal for SANE2 regarding error handling. As of now, error
handling is somewhat imprecise and often not meaningful, and we're
spending everyone's time debugging problems that could be solved
quickly if only the user was given the appropriate status/error
message.

I've got 2 alternatives to solve this, one is clearly better than the
other and there may be others.


Illustration:
-------------
 Trying to get a scanner to work with SANE and XSane, a user is given
"Invalid argument" as error message. Obviously, the backend returned
SANE_STATUS_INVAL for some reason.

 Now, to find out what's going on, debugging must be enabled in the
backend, and then you realize the backend's trying to open a device
which it can't open because of bad permissions.

That's 4 to 5 mails that could be avoided with proper error reporting.


Proposal 1:
-----------

Define SANE_Status as a struct :

typedef struct {
  int code;
  char *msg;
} SANE_Status;

SANE_Status.code is *always* a standard SANE status code.

If SANE_Status.msg is NULL, then the standard SANE status message is
printed, end of the story.

Otherwise, the custom SANE_Status.msg is printed, and the caller must
free SANE_Status.msg.


Proposal 2 (preferred) :
------------------------

Slightly redefine SANE_Status, as a 32bit integer where the 2 MSB are
a backend-specific error code and the 2 LSB are a standard SANE status
code.

The 2 LSB will always correspond to a SANE status.

If the 2 MSB are non-zero, they are passed to a sane_backend_status()
routine inside the backend that returns a proper status message that
is then echoed to the user. (depending on what we want to achieve,
we'd require the caller to free the message after use, think
sprintf(), etc...)

Otherwise, the standard SANE status message is echoed.


Thoughts ?

JB.

-- 
Julien BLACHE                                   <http://www.jblache.org> 
<jb at jblache.org> 




More information about the sane-devel mailing list