Skip to content

Commit

Permalink
Merge pull request #1270 from untergeek/fix/1237
Browse files Browse the repository at this point in the history
Fix YAML linting/error display
  • Loading branch information
untergeek committed Sep 11, 2018
2 parents a69dba1 + 5da43e1 commit 3c05d5d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
14 changes: 7 additions & 7 deletions curator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def single_constructor(loader,node):
else:
envvar = proto
return os.environ[envvar] if envvar in os.environ else default
yaml.add_constructor('!single', single_constructor)

raw = read_file(path)
yaml.add_constructor('!single', single_constructor)

try:
cfg = yaml.load(raw)
except yaml.scanner.ScannerError as e:
raise exceptions.ConfigurationError(
'Unable to parse YAML file. Error: {0}'.format(e))
return cfg
return yaml.load(read_file(path))
except yaml.scanner.ScannerError as err:
print('Unable to read/parse YAML file: {0}'.format(path))
print(err)
sys.exit(1)

def test_client_options(config):
"""
Expand Down
5 changes: 5 additions & 0 deletions docs/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Changelog
* The ``empty`` filter has been exposed for general use. This filter matches
indices with no documents. (jrask) #1264

**Bug Fixes**

* Fix YAML linting so that YAML errors are caught and displayed on the
command line. Reported in #1237 (untergeek)

**Documentation**

* Added Reindex example to the sidebar. (Nostalgiac) #1227
Expand Down
5 changes: 3 additions & 2 deletions test/unit/test_cli_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def test_read_file_pass(self):
self.assertEqual('localhost', cfg['client']['hosts'])
self.assertEqual(9200, cfg['client']['port'])
def test_read_file_corrupt_fail(self):
self.assertRaises(curator.ConfigurationError,
curator.get_yaml, self.args['invalid_yaml'])
with self.assertRaises(SystemExit) as get:
curator.get_yaml(self.args['invalid_yaml'])
self.assertEqual(get.exception.code, 1)
def test_read_file_missing_fail(self):
self.assertRaises(
curator.FailedExecution,
Expand Down

0 comments on commit 3c05d5d

Please sign in to comment.