Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve command not found error message #1736

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Next
- Improve command not found error message
- Add goimports beautifier for Go language
- ...
- Fixes [#1728](https://github.com/Glavin001/atom-beautify/issues/1728). Remove Shell-Env from Executable, use Atom's process.env instead. See [#1735](https://github.com/Glavin001/atom-beautify/pull/1735).
- ...

# v0.30.2 (2017-06-20)
- Fixes [#1030](https://github.com/Glavin001/atom-beautify/issues/1030). Add support for alpha versions of autopep8
Expand Down
7 changes: 5 additions & 2 deletions spec/atom-beautify-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ describe "Atom-Beautify", ->
expect(v).not.toBe(null)
expect(v instanceof Error).toBe(true)
expect(v.code).toBe("CommandNotFound")
expect(v.description).toBe(undefined, \
'Error should not have a description.')
expect(typeof v.description).toBe("string", \
'Error should have a description.')
expect(v.description
.indexOf("Executable - Beautifier - Path")).toBe(-1, \
"Error should not have pathOption.")
return v
p.then(cb, cb)
return p
Expand Down
5 changes: 5 additions & 0 deletions src/beautifiers/beautifier.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ module.exports = class Beautifier
installation: @link
cmd: executable
})
help ?= {
program: executable
link: @link
pathOption: undefined
}
exe.run(args, {cwd, ignoreReturnCode, help, onStdin})

###
Expand Down
40 changes: 11 additions & 29 deletions src/beautifiers/executable.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ class Executable
{ cmd, cwd, ignoreReturnCode, help, onStdin, returnStderr, returnStdoutOrStderr } = options
exeName = cmd or @cmd
cwd ?= os.tmpDir()
help ?= {
program: @cmd
link: @installation or @homepage
pathOption: "Executable - #{@name or @cmd} - Path"
}

# Resolve executable and all args
Promise.all([@shellEnv(), this.resolveArgs(args)])
Expand Down Expand Up @@ -276,45 +281,22 @@ class Executable
if help?
if typeof help is "object"
# Basic notice
helpStr = "See #{help.link} for program \
installation instructions.\n"
# Help to configure Atom Beautify for program's path
docsLink = "https://github.com/Glavin001/atom-beautify#beautifiers"
helpStr = "See #{exe} installation instructions at #{docsLink}#{if help.link then (' or go to '+help.link) else ''}\n"
# # Help to configure Atom Beautify for program's path
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
# Optional, additional help
helpStr += help.additional if help.additional
# Common Help
issueSearchLink =
"https://github.com/Glavin001/atom-beautify/\
search?q=#{exe}&type=Issues"
docsLink = "https://github.com/Glavin001/\
atom-beautify/tree/master/docs"
helpStr += "Your program is properly installed if running \
'#{if @isWindows() then 'where.exe' \
else 'which'} #{exe}' \
in your #{if @isWindows() then 'CMD prompt' \
else 'Terminal'} \
returns an absolute path to the executable. \
If this does not work then you have not \
installed the program correctly and so \
Atom Beautify will not find the program. \
Atom Beautify requires that the program be \
found in your PATH environment variable. \n\
Note that this is not an Atom Beautify issue \
if beautification does not work and the above \
command also does not work: this is expected \
behaviour, since you have not properly installed \
your program. Please properly setup the program \
and search through existing Atom Beautify issues \
before creating a new issue. \
See #{issueSearchLink} for related Issues and \
#{docsLink} for documentation. \
If you are still unable to resolve this issue on \
your own then please create a new issue and \
ask for help.\n"
returns an absolute path to the executable.\n"
# # Optional, additional help
helpStr += help.additional if help.additional
er.description = helpStr
else #if typeof help is "string"
er.description = help
Expand Down