How can I explicity return a failed promise?


I have a method that takes a file path, and try to open on atom if it is successful. The idea is like this:

    @open: (filePath) ->
      return null unless @goodFilePath(filePath)

So, this returns null when the file is bad, and returns a promise when the file is good. How can I return a failed promise instead of null?

I tried to require q and use q.reject, but it is not included directly on atom. Do I need to install it, or should I use promises another way?


Since atom/atom includes q, I decided to include it too. If I’m doing it wrong, please let me know.

  1. Add "q": "^1.0.1" on dependencies arary, inside package.json
  2. apm install
  3. require q, and use q.reject(rejectionObject)


That’s perfectly fine … I’ve done something similar in at least one of my packages.