|
@@ -36,18 +36,14 @@ def parse_yaml(yaml_data):
|
|
|
@anvil.server.callable
|
|
@anvil.server.callable
|
|
|
def parse_json(json_data):
|
|
def parse_json(json_data):
|
|
|
try:
|
|
try:
|
|
|
- return pprint.pformat(json.loads(json_data), indent=2)
|
|
|
|
|
|
|
+ return (0,pprint.pformat(json.loads(json_data), indent=2))
|
|
|
except JSONDecodeError as exc:
|
|
except JSONDecodeError as exc:
|
|
|
- print(json_data)
|
|
|
|
|
- if hasattr(exc, 'problem_mark'):
|
|
|
|
|
- if exc.context != None:
|
|
|
|
|
- error_message = ('Error while parsing YAML file:\n'+
|
|
|
|
|
- 'parser says\n' + str(exc.problem_mark) + '\n ' +
|
|
|
|
|
- str(exc.problem) + ' ' + str(exc.context) +
|
|
|
|
|
- '\nPlease correct data and retry.')
|
|
|
|
|
- else:
|
|
|
|
|
- error_message = ('Error while parsing YAML file:\n'+' parser says\n' + str(exc.problem_mark) + '\n ' +
|
|
|
|
|
- str(exc.problem) + '\nPlease correct data and retry.')
|
|
|
|
|
- else:
|
|
|
|
|
- error_message = ("Something went wrong while parsing yaml file")
|
|
|
|
|
|
|
+ error_message = ""
|
|
|
|
|
+ if exc.lineno - 1 >= 0:
|
|
|
|
|
+ error_message = error_message.join(json_data.splitlines()[exc.lineno - 3])
|
|
|
|
|
+ if exc.lineno >= 0:
|
|
|
|
|
+ error_message = error_message.join(json_data.splitlines()[exc.lineno - 2])
|
|
|
|
|
+ error_message = error_message.join(json_data.splitlines()[exc.lineno - 1])
|
|
|
|
|
+ if len(json_data.splitlines()) != exc.lineno:
|
|
|
|
|
+ error_message = error_message.join(json_data.splitlines()[exc.lineno])
|
|
|
return (1,error_message)
|
|
return (1,error_message)
|