Merge pull request #122 from sanmai-NL/JSON_arbitrary_indentation_separator
Fix exception raising logic to match validation issues
diff --git a/pre_commit_hooks/pretty_format_json.py b/pre_commit_hooks/pretty_format_json.py
index 605cbec..36a90eb 100644
--- a/pre_commit_hooks/pretty_format_json.py
+++ b/pre_commit_hooks/pretty_format_json.py
@@ -28,19 +28,20 @@
# type: (str) -> str
try:
int_indentation_spec = int(s)
+ except ValueError:
+ if not s.strip():
+ return s
+ else:
+ raise ValueError(
+ 'Non-whitespace JSON indentation delimiter supplied. ',
+ )
+ else:
if int_indentation_spec >= 0:
return int_indentation_spec * ' '
else:
raise ValueError(
'Negative integer supplied to construct JSON indentation delimiter. ',
)
- except ValueError:
- if s.strip() == '':
- return s
- else:
- raise ValueError(
- 'Non-whitespace JSON indentation delimiter supplied. ',
- )
def pretty_format_json(argv=None):