Closes #311. Show more informative error when beautifier not found

This commit is contained in:
Glavin Wiechert 2015-06-06 13:36:47 -03:00
parent 66867a78b2
commit c9159f2a92
3 changed files with 85 additions and 24 deletions

View File

@ -1,29 +1,67 @@
Beautify = require '../src/beautify'
Beautifiers = require "../src/beautifiers"
beautifiers = new Beautifiers()
Beautifier = require "../src/beautifiers/beautifier"
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
#
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
# or `fdescribe`). Remove the `f` to unfocus the block.
describe "AtomBeautify", ->
activationPromise = null
describe "Atom-Beautify", ->
beforeEach ->
atom.workspaceView = new WorkspaceView
activationPromise = atom.packages.activatePackage('atomBeautify')
# describe "when the beautify event is triggered", ->
# it "attaches and then detaches the view", ->
# expect(atom.workspaceView.find('.atom-beautify')).not.toExist()
#
# # This is an activation event, triggering it will cause the package to be
# # activated.
# atom.workspaceView.trigger 'beautify'
#
# waitsForPromise ->
# activationPromise
#
# Activate package
waitsForPromise ->
activationPromise = atom.packages.activatePackage('atom-beautify')
# Force activate package
pack = atom.packages.getLoadedPackage("atom-beautify")
pack.activateNow()
# Change logger level
# atom.config.set('atom-beautify._loggerLevel', 'verbose')
# Return promise
return activationPromise
describe "Beautifiers", ->
describe "Beautifier::run", ->
beautifier = null
beforeEach ->
beautifier = new Beautifier()
it "should error when beautifier's program not found", ->
expect(beautifier).not.toBe(null)
expect(beautifier instanceof Beautifier).toBe(true)
# waitsForRuns = (fn, message, timeout) ->
# isCompleted = false
# completed = ->
# console.log('completed')
# isCompleted = true
# runs ->
# expect(atom.workspaceView.find('.atom-beautify')).toExist()
# atom.workspaceView.trigger 'beautify'
# expect(atom.workspaceView.find('.atom-beautify')).not.toExist()
# console.log('runs')
# fn(completed)
# waitsFor(->
# console.log('waitsFor', isCompleted)
# isCompleted
# , message, timeout)
#
# waitsForRuns((cb) ->
# console.log('waitsForRuns', cb)
# setTimeout(cb, 2000)
# , "Waiting for beautification to complete", 5000)
waitsForPromise shouldReject: true, ->
p = beautifier.run("program", [])
expect(p).not.toBe(null)
expect(p instanceof beautifier.Promise).toBe(true)
cb = (v) ->
# console.log(v)
expect(v).not.toBe(null)
expect(v instanceof Error).toBe(true)
expect(v.code).toBe("CommandNotFound")
return v
p.then(cb, cb)
return p

View File

@ -135,7 +135,7 @@ module.exports = class Beautifier
###
Run command-line interface command
###
run: (executable, args, {ignoreReturnCode} = {}) ->
run: (executable, args, {ignoreReturnCode, help} = {}) ->
# Resolve executable
Promise.resolve(executable)
.then((exe) =>
@ -173,6 +173,29 @@ module.exports = class Beautifier
)
cmd.on('error', (err) =>
@debug('error', err)
# Check if error is ENOENT (command could not be found)
if err.code is 'ENOENT' or err.errno is 'ENOENT'
# Create new improved error
# notify user that it may not be installed or in path
message = "Could not find '#{exe}'. The program may not be installed."
er = new Error(message) # +(if help then "\n\n#{help}" else "")
if help?
if typeof help is "object"
helpStr = "See #{help.link} for program installation instructions.\n"
helpStr += "You can configure Atom Beautify with the absolute path \
to '#{help.program or exe}' by setting '#{help.pathOption}' in \
the Atom Beautify package settings.\n" if help.pathOption
helpStr += help.additional if help.additional
er.description = helpStr
else #if typeof help is "string"
er.description = help
er.code = 'CommandNotFound'
er.errno = er.code
er.syscall = 'beautifier::run'
er.file = exe
reject(er)
else
# continue as normal error
reject(err)
)
)

View File

@ -76,7 +76,7 @@ beautify = ({onSave}) ->
# console.log(e)
stack = error.stack
detail = error.message
detail = error.description or error.message
atom.notifications?.addError(error.message, {
stack, detail, dismissable : true})