[sane-devel] [SANE2 proposal] Error handling

Andi McLean andi.mclean@ntlworld.com
28 Nov 2003 21:07:35 +0000


Why not combine the two e.g.

typedef SANE_Status
{
  int code;
  int backend_code;
} SANE_Status;

SANE_Status.code is always a standard SANE status code,
SANE_Status.backend_code is a backend specific code that could be passed
to sane_backend_status(). 
that way the client code does not have to worry about freeing
SANE_Status.msg, or worry about backend_code if it doesn't need to.

You could always use a short instead of an int, which is almost the same
as proposal 2, but easier to access (No nasty bit manipulation)

Just an idea.

Andi

On Fri, 2003-11-28 at 17:12, Julien BLACHE wrote:
> 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@jblache.org>