From: Adam Sampson Date: Sun, 12 Jul 2015 13:41:20 +0000 (+0100) Subject: Don't continue after a config parser error. X-Git-Tag: v2.21~3 X-Git-Url: http://git.ozo.com/?a=commitdiff_plain;h=2c0055e7ae030353cb8f080bc83a6979d60472cd;p=rawdog%2F.git Don't continue after a config parser error. Commit 478f1bfa89c18e08c67115eb75b1148554a0162d introduced this bug; the "return" in load_config should actually return from main. A number of tests needed updating to match this, since rawdog now exits non-zero (correctly) in more cases. --- diff --git a/NEWS b/NEWS index 1905acf..4a29dcb 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,11 @@ Since feedparser's date parser is pretty liberal, it can occasionally interpret an invalid date incorrectly (e.g. treating a time zone as a year number). +When an error occurs while parsing the config file, exit with a non-zero +return code, rather than continuing with an incomplete config. This has +always been the intended behaviour, but rawdog 2.13 accidentally removed +the check. + - rawdog 2.20 Add a test for the maxage option (suggested by joelmo). diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index ca66568..c75bd65 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -1927,7 +1927,10 @@ def main(argv): return 1 if verbose: config["verbose"] = True - load_config("config") + return 0 + rc = load_config("config") + if rc != 0: + return rc global persister persister = Persister(config) @@ -1952,7 +1955,9 @@ def main(argv): config.reload() rawdog.sync_from_config(config) elif o in ("-c", "--config"): - load_config(a) + rc = load_config(a) + if rc != 0: + return rc rawdog.sync_from_config(config) elif o in ("-f", "--update-feed"): rawdog.update(config, a) diff --git a/test-rawdog b/test-rawdog index 9ee1736..7b3f77e 100755 --- a/test-rawdog +++ b/test-rawdog @@ -532,37 +532,56 @@ rune "No such feed" -f $httpurl/feed.rss begin "bad config syntax" add "foo" -rune "Bad line in config" +runne "Bad line in config" + +begin "config error is fatal" +add "foo" +cat >$statedir/plugins/crash.py <$statedir/extra.conf +runne "Bad line in config" --config extra.conf + +begin "config error in include" +echo "foo" >$statedir/extra.conf +add "include extra.conf" +runne "Bad line in config" begin "bad config directive" add "foo bar" -rune "Unknown config command" +runne "Unknown config command" begin "bad boolean value in config" add "sortbyfeeddate aubergine" -rune "Bad value" +runne "Bad value" begin "bad time value in config" add "timeout aubergine" -rune "Bad value" +runne "Bad value" begin "bad integer value in config" add "maxarticles aubergine" -rune "Bad value" +runne "Bad value" begin "bad inline feed argument" add "feed 0 $httpurl/feed.rss aubergine" -rune "Bad feed argument" +runne "Bad feed argument" begin "bad feed argument line" add "feed 0 $httpurl/feed.rss" add " aubergine" -rune "Bad argument line" +runne "Bad argument line" begin "feed argument line with no feed" : >$statedir/config add " allowduplicates true" -rune "First line in config cannot be an argument" +runne "First line in config cannot be an argument" begin "feeddefaults on one line" add "feeddefaults allowduplicates=true" @@ -576,23 +595,23 @@ runs begin "argument lines in the wrong place" add "tidyhtml false" add " allowduplicates true" -rune "Bad argument lines" +runne "Bad argument lines" begin "feed with no time" add "feed" -rune "Bad line in config" +runne "Bad line in config" begin "feed with no URL" add "feed 3h" -rune "Bad line in config" +runne "Bad line in config" begin "define with no name" add "define" -rune "Bad line in config" +runne "Bad line in config" begin "define with no value" add "define thing" -rune "Bad line in config" +runne "Bad line in config" begin "define" add "define myvar This is my variable!" @@ -603,7 +622,7 @@ contains $statedir/output.html "myvar(This is my variable!)" begin "missing config file" rm $statedir/config -rune "Can't read config file" -u +runne "Can't read config file" -u begin "empty config file" : >$statedir/config @@ -1172,7 +1191,7 @@ contains $statedir/output.html MAGIC1 MAGIC2 for template in page item feedlist feeditem; do begin "missing ${template} template file" add "${template}template ${template}" - rune "Can't read template file" -u + runne "Can't read template file" -u done begin "template conditionals" @@ -1196,7 +1215,7 @@ echo "char(ø)" >$statedir/item make_atom10 $httpdir/feed.atom add "feed 0 $httpurl/feed.atom" add "itemtemplate item" -rune "Character encoding problem" -uw +runne "Character encoding problem" -uw if [ -n "$utf8_LC_ALL" ]; then begin "UTF-8 in template, UTF-8 locale" @@ -1215,7 +1234,7 @@ echo "expand(__thing__)" >$statedir/item add "itemtemplate item" add "feed 0 $httpurl/feed.atom" add " define_thing char(ø)" -rune "Character encoding problem" -uw +runne "Character encoding problem" -uw if [ -n "$utf8_LC_ALL" ]; then begin "UTF-8 in define, UTF-8 locale"