summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Singh <csingh43@bloomberg.net>2018-06-06 18:25:24 +0100
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2018-06-06 21:27:30 +0000
commit7df956547696092cb07082bc4f6ec12f6585cdd0 (patch)
treef09033e27f9c46cbadf656db3c0d1294beb0a2f8
parent55dc3b27ade5327d1723ed139e9e39cc47f9aae8 (diff)
downloadbuildstream-7df956547696092cb07082bc4f6ec12f6585cdd0.tar.gz
_loader/loader.py: Report element-path when failing to load elements
It can be confusing, especially to new BuildStream users, that the CLI expects targets to be specified relative to element-path and not the current directory. Previously, the CLI would give a generic message stating that the file could not be found but it was not obvious that it was looking in the `element-path` directory. Explicitly print the element-path in the summary. Also, try to check if the specified element exists in the elements directory and print a hint to use the element-path relative paths if that's the case. Fixes #396. This is is also related to #341. This commit aims to tackle that issue by trying to educate users about element-path.
-rw-r--r--buildstream/_loader/loader.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/buildstream/_loader/loader.py b/buildstream/_loader/loader.py
index e0ceb4fb9..1f3da35b9 100644
--- a/buildstream/_loader/loader.py
+++ b/buildstream/_loader/loader.py
@@ -207,7 +207,23 @@ class Loader():
# Load the data and process any conditional statements therein
fullpath = os.path.join(self._basedir, filename)
- node = _yaml.load(fullpath, shortname=filename, copy_tree=rewritable)
+ try:
+ node = _yaml.load(fullpath, shortname=filename, copy_tree=rewritable)
+ except LoadError as e:
+ if e.reason == LoadErrorReason.MISSING_FILE:
+ # If we can't find the file, try to suggest plausible
+ # alternatives by stripping the element-path from the given
+ # filename, and verifying that it exists.
+ message = "Could not find element '{}' in elements directory '{}'".format(filename, self._basedir)
+ detail = None
+ elements_dir = os.path.relpath(self._basedir, self.project.directory)
+ element_relpath = os.path.relpath(filename, elements_dir)
+ if filename.startswith(elements_dir) and os.path.exists(os.path.join(self._basedir, element_relpath)):
+ detail = "Did you mean '{}'?".format(element_relpath)
+ raise LoadError(LoadErrorReason.MISSING_FILE,
+ message, detail=detail) from e
+ else:
+ raise
self._options.process_node(node)
element = LoadElement(node, filename, self)