Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Show error message when load yaml file failed (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
SparkSnail authored Apr 24, 2019
1 parent 8531d80 commit ab9de20
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tools/nni_cmd/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ def get_yml_content(file_path):
try:
with open(file_path, 'r') as file:
return yaml.load(file, Loader=yaml.Loader)
except TypeError as err:
print('Error: ', err)
return None
except yaml.scanner.ScannerError as err:
print_error('yaml file format error!')
exit(1)
except Exception as exception:
print_error(exception)
exit(1)

def get_json_content(file_path):
'''Load json file content'''
try:
with open(file_path, 'r') as file:
return json.load(file)
except TypeError as err:
print('Error: ', err)
print_error('json file format error!')
return None

def print_error(content):
Expand Down

0 comments on commit ab9de20

Please sign in to comment.