[[feature-stackdir]] Rework error handling.

- Provide an error location stack.  This allows more precise error
  location information to be provided without having to explicitly
  pass a suitable path to every function that might log a stackdir
  error.

- Add specific error-generating functions for each location where an
  error can be returned (apart from OOM errors).