Bug 3715 - [review] Conf::Parser double counts certain errors, etc.
Summary: [review] Conf::Parser double counts certain errors, etc.
Status: RESOLVED FIXED
Alias: None
Product: Spamassassin
Classification: Unclassified
Component: Libraries (show other bugs)
Version: SVN Trunk (Latest Devel Version)
Hardware: Other other
: P5 normal
Target Milestone: 3.0.0
Assignee: SpamAssassin Developer Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 3699
  Show dependency tree
 
Reported: 2004-08-22 11:42 UTC by Theo Van Dinter
Modified: 2004-08-24 13:23 UTC (History)
0 users



Attachment Type Modified Status Actions Submitter/CLA Status
suggested patch patch None Theo Van Dinter [HasCLA]
uses MISSING_REQUIRED_VALUE, nicer errors patch None Justin Mason [HasCLA]

Note You need to log in before you can comment on or make changes to this bug.
Description Theo Van Dinter 2004-08-22 11:42:49 UTC
While working on another issues, I found this in parse():

[...]
      if ($ret && $ret eq $Mail::SpamAssassin::Conf::INVALID_VALUE) {
        warn "invalid value for \"$key\": $value\n";
        $conf->{errors}++;
      } else {
        next;
      }
[...]
failed_line:
[...]
    $conf->{errors}++;
[...]

So if a configuration code call returns INVALID_VALUE, errors++, then the parse
continues down to failed_line which tries to have a plugin deal with it, and if
it still fails, errors++ again.

IMO, there are 2 issues here.

1) errors++ is called twice for a single failure, which is obviously wrong.
2) if INVALID_VALUE is returned, parse() tries to have plugins deal with the
option which we already know isn't for plugins, then we throw a second error:


as an example, add a config option "add_header blarg" to a cf file, then run
--lint.  what you get out is:

invalid value for "add_header": blarg
Failed to parse line in SpamAssassin configuration, skipping: add_header blarg
lint: 2 issues detected.  please rerun with debug enabled for more information.
Comment 1 Theo Van Dinter 2004-08-22 11:58:16 UTC
Created attachment 2280 [details]
suggested patch

instead of just falling through, this patch makes another goto call (sorry)
past the plugin attempt if ret fails.  I also added in some comments...
Comment 2 Justin Mason 2004-08-22 15:26:56 UTC
-1, I'm not keen on that.  the error message

    invalid value for "add_header": blarg

is a lot more informative as to what the problem really was than

    Failed to parse line in SpamAssassin configuration, skipping: add_header blarg

A better fix would be to keep the "invalid value" error message, then skip to
failed_line, bypassing try_plugin as in your patch.

--j.
Comment 3 Justin Mason 2004-08-22 15:50:29 UTC
Created attachment 2281 [details]
uses MISSING_REQUIRED_VALUE, nicer errors

ok, here's an implementation of what I was suggesting.	this patch also
contains the fix for bug 3699, since they're inseparable.
Comment 4 Justin Mason 2004-08-22 15:55:06 UTC
so, for the "empty description" error case, you now get:

config: SpamAssassin failed to parse line, no value provided for "describe",
skipping: describe FOO
lint: 1 issues detected.  please rerun with debug enabled for more information.


the "add_header" case:

config: SpamAssassin failed to parse line, "blarg" is not valid for
"add_header", skipping: add_header blarg
lint: 1 issues detected.  please rerun with debug enabled for more information.

and an unrecognised command:

config: SpamAssassin failed to parse line, skipping: blarg
lint: 1 issues detected.  please rerun with debug enabled for more information.


note

(a) the use of a scoping "facility" name, as per Daniel's suggestions --
"config" ("lint" may be more appropriate? can be changed on checkin)

(b) clear error messages for all three cases

(c) consistency; previous code would output "warn"s for invalid values, whereas
an unrecognized command in the conf file would be a "dbg"!  This now uses the
same output code for all 3 error cases so it's consistent (dbg, or warn if
--lint is being used).
Comment 5 Theo Van Dinter 2004-08-22 16:51:50 UTC
+1, sure. :)
Comment 6 Malte S. Stretz 2004-08-23 10:15:35 UTC
+0.9, two issues: 
 
1. Why is there a string compare via eq done instead of ==?  Both $ret and 
$INVALID_VALUE should be numbers and the string compare needs a "cast" of the 
numeric value to string first. 
 
2. I guess this one falls under "big API change for which its too late" ;)  But 
I don't like the fact that the success return value for the $cmd->{code}s is 
obviously undef.  That should be either 1 or something like $VALID_VALUE (== 
1); maybe <=0 -> error and >=1 -> success. 
 
btw, if I write +0.9 it means as much as "feel free to round this to +1 and 
commit, I just have some nitpicking issues with the code" :) 
Comment 7 Theo Van Dinter 2004-08-23 10:22:38 UTC
Subject: Re:  [review] Conf::Parser double counts certain errors, etc.

On Mon, Aug 23, 2004 at 10:15:36AM -0700, bugzilla-daemon@bugzilla.spamassassin.org wrote:
> 1. Why is there a string compare via eq done instead of ==?  Both $ret and 
> $INVALID_VALUE should be numbers and the string compare needs a "cast" of the 
> numeric value to string first. 

Because the return value, currently, can be anything, not just a number.
For instance, the hash_key return value is either a key=>value pair or
a number (for invalid/missing).  Some things return undef, some things return
strings, etc.

> 2. I guess this one falls under "big API change for which its too late" ;)  But 
> I don't like the fact that the success return value for the $cmd->{code}s is 
> obviously undef.  That should be either 1 or something like $VALID_VALUE (== 
> 1); maybe <=0 -> error and >=1 -> success. 

Yeah, I was thinking about that as I went through for the first patch.
Hence my comment above the code call.  It should be a bit better defined,
but yeah, that'll be 3.1 I think.  It requires modifying large chunks
of code in Conf/Conf::Parser to return numbers only and not undef
anywhere....

Comment 8 Justin Mason 2004-08-23 12:20:06 UTC
'Because the return value, currently, can be anything, not just a number.
For instance, the hash_key return value is either a key=>value pair or
a number (for invalid/missing).  Some things return undef, some things return
strings, etc.'

and treating it as a number when it could be a string results in horrible
warnings when "use strict" is on.   annoying...

'> 2. I guess this one falls under "big API change for which its too late" ;)  But 
> I don't like the fact that the success return value for the $cmd->{code}s is 
> obviously undef.  That should be either 1 or something like $VALID_VALUE (== 
> 1); maybe <=0 -> error and >=1 -> success. 

Yeah, I was thinking about that as I went through for the first patch.
Hence my comment above the code call.  It should be a bit better defined,
but yeah, that'll be 3.1 I think.  It requires modifying large chunks
of code in Conf/Conf::Parser to return numbers only and not undef
anywhere....'

the success return value could be anything.  it's only the failure cases that we
need to care about.

this was explicit (although I should document it ;).  I'll do that post-checkin
as a doc change.

reason why: there's lots of those 'code' subs, and adding "boilerplate" items to
them, like a required "return 1" line in each one, will just increase code size,
make it more annoying to write those subs, cause errors when people forget that,
and generally cause pain.   dealing with error return codes can be done more
easily in one place (Parser) rather than in 100 places (each of the code subs).
I'm not sure I like it -- 
Comment 9 Justin Mason 2004-08-23 12:21:07 UTC
(where did that "I'm not sure I like it --" come from?! anyway, ignore that ;)
Comment 10 Daniel Quinlan 2004-08-24 01:49:20 UTC
+1
Comment 11 Justin Mason 2004-08-24 21:23:52 UTC
thx, applied, r36836