octave-maintainers
[Top][All Lists]
Advanced

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

improving error messages?


From: Jaroslav Hajek
Subject: improving error messages?
Date: Wed, 21 Oct 2009 12:38:24 +0200

hi,

I'm thinking about possible way to improve some error messages. The problem:
It is a good custom to prefix an error message with the name of the
originating function.
The problem is that some messages originate from procedures that have
no information about the invoking procedure.
In particular, this concerns functions from liboctave. Some of these
simply assume the calling function (e.g. sub2ind),
use something general (like "A(I):"), or use nothing (idx_vector).

cf. this:
octave:1> cellslices (1:3, 1, 4)
error: A(I): Index exceeds matrix dimension.

the problem is that the message doesn't show it originated in
"cellslices". This is primarily because Array<T>::index, which throws
it, doesn't know where it's being called from. Even though a traceback
will show the line number, if this occurs within a script, an user may
be easily confused.

Another instance of the same problem, within the interpreter, are
functions like octave_value::int_value, which gripe about "conversion
failed", but don't show the calling function.
Basically, there are three existing approaches currently in use to
face the problem:

1. ignore it
2. check for the error and display a supplemental message (on a new
line) with a correct prefix
3. try to pass the name down the call chain

1 is done for liboctave, as explained. 2 is used by some functions, e.g.
octave:1> any(1, 1.5)
error: conversion of 1.5 to int value failed
error: any: expecting dimension argument to be an integer

the problem is that this duplicates some information and requires a
lot of checking.
Approach 3 is used by some of the gripe_xxx functions. Still, it is
not reasonable to pass the name everywhere, especially to liboctave.

Looking for a relatively simple solution, I thought that error handler
simply can optionally query the current function name and insert it
into the message.
Since a lot of functions already do it in the first place, it can
first check whether the prefix is already there.

I ended up with the attached patch. This seems to mostly solve my problems:

octave:1> cellslices (1:3, 1, 4)
error: cellslices: A(I): Index exceeds matrix dimension.
octave:1> any(1, 1.5)
error: any: conversion of 1.5 to int value failed
error: any: expecting dimension argument to be an integer

I know this is no candidate for the best software design award, but it
works and is a relatively harmless change...

Comments?

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

Attachment: errors.diff
Description: Text Data


reply via email to

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