Skip to content

Commit 969e408

Browse files
committed
add feature: include line number in toc parse error message
1 parent f312589 commit 969e408

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

pdftocio/tocparser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
from typing import IO, List
77
from fitzutils import ToCEntry
8-
from itertools import takewhile
8+
from itertools import count, takewhile
99

1010

11-
def parse_entry(entry: List) -> ToCEntry:
11+
def parse_entry(entry: List, nLine: int) -> ToCEntry:
1212
"""parse a row in csv to a toc entry"""
1313

1414
# a somewhat weird hack, csv reader would read spaces as an empty '', so we
@@ -24,7 +24,7 @@ def parse_entry(entry: List) -> ToCEntry:
2424
)
2525
return toc_entry
2626
except IndexError as e:
27-
print(f"Unable to parse toc entry {entry};",
27+
print(f"Unable to parse toc entry {entry} from line {nLine};",
2828
f"Need at least {indent + 2} parts but only have {len(entry)}.",
2929
"Make sure the page number is present.",
3030
file=sys.stderr)
@@ -35,4 +35,4 @@ def parse_toc(file: IO) -> List[ToCEntry]:
3535
"""Parse a toc file to a list of toc entries"""
3636
reader = csv.reader(file, lineterminator='\n',
3737
delimiter=' ', quoting=csv.QUOTE_NONNUMERIC)
38-
return list(map(parse_entry, reader))
38+
return list(map(parse_entry, reader, count(1)))

0 commit comments

Comments
 (0)