Don't continue after a config parser error.
authorAdam Sampson <ats@offog.org>
Sun, 12 Jul 2015 13:41:20 +0000 (14:41 +0100)
committerAdam Sampson <ats@offog.org>
Sun, 12 Jul 2015 13:41:20 +0000 (14:41 +0100)
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.

NEWS
rawdoglib/rawdog.py
test-rawdog

diff --git a/NEWS b/NEWS
index 1905acfc4846a5cff445952878acd1c71e6832b5..4a29dcb932ef9d80f9bb57e8ffb9318e0f5ee282 100644 (file)
--- 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).
index ca66568e7d6396dc27ec2fbc6afa1e66fa920c78..c75bd65513f5d9fddf1bea707cb126bb7e2df678 100644 (file)
@@ -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)
index 9ee173679324b08c4c1792020ca1357dfa6b6554..7b3f77ec144430efcd39b961436a8a6bf89f2fb7 100755 (executable)
@@ -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 <<EOF
+import rawdoglib.plugins
+def startup(rawdog, config):
+    raise Exception("crash")
+rawdoglib.plugins.attach_hook("startup", startup)
+EOF
+runne "Bad line in config"
+
+begin "config error in --config"
+echo "foo" >$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"