Skip to content

Commit

Permalink
Made most type errors report the incorrect type
Browse files Browse the repository at this point in the history
  • Loading branch information
NullSoldier committed Aug 23, 2017
1 parent 13d9bb5 commit 3ec1d39
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions steamfiles/acf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def loads(data, wrapper=dict):
:return: An Ordered Dictionary with ACF data.
"""
if not isinstance(data, str):
raise TypeError('can only load a str as an ACF')
raise TypeError('can only load a str as an ACF but got ' + type(data).__name__)

parsed = wrapper()
current_section = parsed
Expand Down Expand Up @@ -59,7 +59,7 @@ def dumps(obj):
:return: ACF data.
"""
if not isinstance(obj, dict):
raise TypeError('can only dump a dictionary as an ACF')
raise TypeError('can only dump a dictionary as an ACF but got ' + type(obj).__name__)

return '\n'.join(_dumps(obj, level=0)) + '\n'

Expand Down
6 changes: 3 additions & 3 deletions steamfiles/appinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def loads(data, wrapper=dict):
:return: An Ordered Dictionary with Appinfo data.
"""
if not isinstance(data, (bytes, bytearray)):
raise TypeError('can only load a bytes-like object as an Appinfo')
raise TypeError('can only load a bytes-like object as an Appinfo but got ' + type(data).__name__)

return AppinfoDecoder(data, wrapper=wrapper).decode()

Expand All @@ -58,7 +58,7 @@ def dumps(obj):
:return:
"""
if not isinstance(obj, dict):
raise TypeError('can only dump a dictionary as an Appinfo')
raise TypeError('can only dump a dictionary as an Appinfo but got ' + type(obj).__name__)

return b''.join(AppinfoEncoder(obj).iter_encode())

Expand Down Expand Up @@ -271,7 +271,7 @@ def iter_encode_section(self, section_data, root_section=False):
elif isinstance(value, Integer):
yield from self.encode_integer(key, value)
else:
raise TypeError('Unknown value type')
raise TypeError('Unknown value type ' + type(value).__name__)

yield SECTION_END
if root_section:
Expand Down
4 changes: 2 additions & 2 deletions steamfiles/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def loads(data, wrapper=dict):
:return: A dictionary with Manifest data.
"""
if not isinstance(data, (bytes, bytearray)):
raise TypeError('can only load a bytes-like object as a Manifest')
raise TypeError('can only load a bytes-like object as a Manifest but got ' + type(data).__name__)

offset = 0
parsed = wrapper()
Expand Down Expand Up @@ -94,7 +94,7 @@ def dumps(obj):
:return: A file object.
"""
if not isinstance(obj, dict):
raise TypeError('can only dump a dictionary as a Manifest')
raise TypeError('can only dump a dictionary as a Manifest but got ' + type(obj).__name__)

data = []
int32 = struct.Struct('<I')
Expand Down

0 comments on commit 3ec1d39

Please sign in to comment.