# HG changeset patch # User Tero Marttila # Date 1233967896 -7200 # Node ID b538e1f7011cd834b920d8beec2500afcc3ec45b # Parent 4a40718c7b4baab0a4e7bb863eb9dc03147943f2 add some better error checking to the page_tree stuff diff -r 4a40718c7b4b -r b538e1f7011c lib/page_tree.py --- a/lib/page_tree.py Sat Feb 07 02:46:58 2009 +0200 +++ b/lib/page_tree.py Sat Feb 07 02:51:36 2009 +0200 @@ -7,6 +7,12 @@ # path to file containing the page metadata tree PAGE_TREE_FILE = "pages/list" +class PageTreeError (Exception) : + """ + Error parsing/loading the page tree + """ + + pass class PageInfo (object) : """ @@ -118,6 +124,9 @@ # parse tree tree = tree_parse.parse(path, ':') + if not tree : + raise PageTreeError("No root node found") + def _create_node (parent, item) : """ Creates and returns a PageInfo from the given parent node and (line_number, line, children) tuple item @@ -125,9 +134,15 @@ # unpack line_number, line, children = item + + # parse line + url = title = None + + try : + url, title = line.split(':') - # parse line - url, title = line.split(':') + except : + raise PageTreeError("Invalid line: %s:%d: %r" % (path, line_number, line)) # remove whitespace url = url.strip() diff -r 4a40718c7b4b -r b538e1f7011c lib/tree_parse.py --- a/lib/tree_parse.py Sat Feb 07 02:46:58 2009 +0200 +++ b/lib/tree_parse.py Sat Feb 07 02:51:36 2009 +0200 @@ -5,6 +5,13 @@ A file consists of a number of lines, and each line consists of indenting whitespace and data. Each line has a parent """ +class TreeParseError (Exception) : + """ + Error parsing a tree file + """ + + pass + def _read_lines (path, stop_tokens='') : """ Reads lines from the given path, ignoring empty lines, and yielding (line_number, indent, line) tuples, where @@ -109,7 +116,7 @@ break elif stack_indent < indent : - assert False, "Bad un-indent" + raise TreeParseError("Bad unindent on %s:%d, %d < %d" % (path, line_number, stack_indent, indent)) # add to parent? if parent :