Skip to content

Stack trace shown if you accidentially `bst COMMAND <directory>`

Summary

It's not uncommon to find elements with the same name (minus the file extension) as a subdirectory within the element path, especially when we're using stack elements.

Executing a bst COMMAND on a directory will produce a stack trace.

Steps to reproduce

If you execute the bst show command on a directory you'll receive something similar to the following:

 $ pwd
/home/jamesennis/autotools

 $ ls elements/
base  base.bst  hello.bst  importme.bst

 $ bst show base
[--:--:--][][] START   Loading pipeline
[--:--:--][][] BUG     [Errno 21] Is a directory: '/home/jamesennis/autotools/elements/base'

    Traceback (most recent call last):
      File "/home/jamesennis/.local/bin/bst", line 8, in <module>
        sys.exit(cli())
      File "/home/jamesennis/.local/lib/python3.5/site-packages/click/core.py", line 722, in __call__
        return self.main(*args, **kwargs)
      File "/home/jamesennis/buildstream/buildstream/_frontend/cli.py", line 162, in override_main
        standalone_mode=standalone_mode, **extra)
      File "/home/jamesennis/.local/lib/python3.5/site-packages/click/core.py", line 697, in main
        rv = self.invoke(ctx)
      File "/home/jamesennis/.local/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/home/jamesennis/.local/lib/python3.5/site-packages/click/core.py", line 895, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "/home/jamesennis/.local/lib/python3.5/site-packages/click/core.py", line 535, in invoke
        return callback(*args, **kwargs)
      File "/home/jamesennis/.local/lib/python3.5/site-packages/click/decorators.py", line 27, in new_func
        return f(get_current_context().obj, *args, **kwargs)
      File "/home/jamesennis/buildstream/buildstream/_frontend/cli.py", line 543, in show
        except_targets=except_)
      File "/home/jamesennis/buildstream/buildstream/_stream.py", line 114, in load_selection
        fetch_subprojects=False)
      File "/home/jamesennis/buildstream/buildstream/_stream.py", line 814, in _load
        fetch_subprojects=fetch_subprojects)
      File "/home/jamesennis/buildstream/buildstream/_pipeline.py", line 113, in load
        meta_elements = self._loader.load(rewritable, None)
      File "/home/jamesennis/buildstream/buildstream/_loader/loader.py", line 114, in load
        loader._load_file(name, rewritable, ticker)
      File "/home/jamesennis/buildstream/buildstream/_loader/loader.py", line 218, in _load_file
        node = _yaml.load(fullpath, shortname=filename, copy_tree=rewritable)
      File "/home/jamesennis/buildstream/buildstream/_yaml.py", line 182, in load
        with open(filename) as f:
    IsADirectoryError: [Errno 21] Is a directory: '/home/jamesennis/autotools/elements/base'

What is the expected correct behavior?

We should handle this exception better. Perhaps with a message along the lines of: "base is a directory, did you mean base.bst?".

This is similar to how the git command responds to typos:

 $ git feth
git: 'feth' is not a git command. See 'git --help'.

Did you mean this?
	fetch

Optional extra:

  1. A [y/n] option, whereupon y we execute: bst show base.bst
Edited by James Ennis
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information