Skip to content
Snippets Groups Projects
Commit 48848f4e authored by James Ennis's avatar James Ennis
Browse files

loader.py: Check whether the dir specified is also a <dir>.bst file

  - Slight modification to the wording of existing error message.
  - Closes #446
parent 463698ec
No related branches found
No related tags found
1 merge request!522Output a useful error message when trying to load a directory
Pipeline #24816089 passed
......@@ -229,6 +229,16 @@ class Loader():
detail = "Did you mean '{}'?".format(element_relpath)
raise LoadError(LoadErrorReason.MISSING_FILE,
message, detail=detail) from e
elif e.reason == LoadErrorReason.LOADING_DIRECTORY:
# If a <directory>.bst file exists in the element path,
# let's suggest this as a plausible alternative.
message = str(e)
detail = None
if os.path.exists(os.path.join(self._basedir, filename + '.bst')):
element_name = filename + '.bst'
detail = "Did you mean '{}'?\n".format(element_name)
raise LoadError(LoadErrorReason.LOADING_DIRECTORY,
message, detail=detail) from e
else:
raise
self._options.process_node(node)
......
......@@ -186,7 +186,7 @@ def load(filename, shortname=None, copy_tree=False):
"Could not find file at {}".format(filename)) from e
except IsADirectoryError as e:
raise LoadError(LoadErrorReason.LOADING_DIRECTORY,
"{} is a directory. bst command is expecting a .bst file"
"{} is a directory. bst command expects a .bst file."
.format(filename)) from e
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment