Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Make file offset calculations more robust to different failure modes
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhendricks committed Dec 20, 2016
1 parent 7017fb6 commit 3a68b57
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/FlightCrew-plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
}

def generate_line_offsets(s):
if s is None:
return None
offlst = [0]
i = s.find('\n', 0)
while i >= 0:
Expand Down Expand Up @@ -174,15 +176,23 @@ def run(bk):
# generate file offsets once per file
if bk.launcher_version() >= 20160802 and filepath != lastfilepath:
text = None
with open(os.path.join(ebook_root, filepath), 'rb') as f:
text = f.read()
text = text.decode('utf-8', errors='replace')
afile = os.path.join(ebook_root, filepath)
if os.path.isfile(afile):
with open(afile, 'rb') as f:
text = f.read()
text = text.decode('utf-8', errors='replace')
offlst = generate_line_offsets(text)
lastfilepath = filepath

# generate column offset
if bk.launcher_version() >= 20160802 and lineno and colno:
coffset = charoffset(int(lineno), int(colno), offlst)
if bk.launcher_version() >= 20160802:
if lineno is not None and colno is not None and offlst is not None:
try:
nlineno = int(lineno)
ncolno = int(colno)
coffset = charoffset(nlineno, ncolno, offlst)
except ValueError:
coffset = None

msg = resid + ' : ' + msg + " near column " + colno
# since will be passed as attribute make sure to handle any embedded quotes
Expand Down

0 comments on commit 3a68b57

Please sign in to comment.