Skip to content

Commit

Permalink
Parse error message when colno is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Mar 24, 2019
1 parent 2733ba4 commit 47b1bb4
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions jupytext/cell_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
import json
import re

try:
from json import JSONDecodeError
except ImportError:
JSONDecodeError = ValueError

from .languages import _JUPYTER_LANGUAGES

try:
Expand Down Expand Up @@ -279,9 +284,16 @@ def parse_md_code_options(options):
try:
value = json.loads(options)
options = ''
except json.JSONDecodeError as err:
value = json.loads(options[:(err.colno - 1)])
options = options[(err.colno - 1):]
except JSONDecodeError as err:
try:
split = err.colno - 1
except AttributeError:
# str(err) is like: "ValueError: Extra data: line 1 column 7 - line 1 column 50 (char 6 - 49)"
m = re.match(r'.*char ([0-9]*)', str(err))
split = int(m.groups()[0])

value = json.loads(options[:split])
options = options[split:]

metadata.append((name, value))

Expand Down

0 comments on commit 47b1bb4

Please sign in to comment.