Skip to content

Commit

Permalink
utils: Safer error formatting in parse_json/xml.
Browse files Browse the repository at this point in the history
Resolves #440.
  • Loading branch information
chrippa committed Jul 12, 2014
1 parent 7a905d3 commit e4774d6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/livestreamer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def parse_json(data, name="JSON", exception=PluginError, schema=None):
try:
json_data = json.loads(data)
except ValueError as err:
if len(data) > 35:
snippet = data[:35] + "..."
snippet = repr(data)
if len(snippet) > 35:
snippet = snippet[:35] + " ..."
else:
snippet = data

Expand Down Expand Up @@ -82,10 +83,9 @@ def parse_xml(data, name="XML", ignore_ns=False, exception=PluginError, schema=N
try:
tree = ET.fromstring(data)
except Exception as err:
if len(data) > 35:
snippet = data[:35] + "..."
else:
snippet = data
snippet = repr(data)
if len(snippet) > 35:
snippet = snippet[:35] + " ..."

raise exception("Unable to parse {0}: {1} ({2})".format(name, err, snippet))

Expand Down

0 comments on commit e4774d6

Please sign in to comment.