mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-31 09:42:28 +00:00
Log stdlib error on failed exec.LookPath
The error returned by exec.LookPath was never surfaced to the user. Without that detail, the user can't tell the difference between a non-existent path and a permissions issue. Additionally, when ExecuteCommand is an absolute path, we were still attempting to prepend the CommandWorkingDirectory if the ExecuteCommand was not found, which made it difficult to know which path the user intended to execute. This commit simplifies the logic to avoid multiple attempts with ExecuteCommand is an absolute path and changes the error message from: error locating command: '/path/to/file' to: error in exec: "/path/to/file": stat /path/to/file: no such file or directory error in exec: "/path/to/file": permission denied Fixes #457
This commit is contained in:
parent
c7a8fbc929
commit
dd5fa20415
2 changed files with 8 additions and 8 deletions
14
webhook.go
14
webhook.go
|
@ -581,16 +581,16 @@ func handleHook(h *hook.Hook, rid string, headers, query, payload *map[string]in
|
|||
var errors []error
|
||||
|
||||
// check the command exists
|
||||
cmdPath, err := exec.LookPath(h.ExecuteCommand)
|
||||
if err != nil {
|
||||
// give a last chance, maybe is a relative path
|
||||
relativeToCwd := filepath.Join(h.CommandWorkingDirectory, h.ExecuteCommand)
|
||||
// check the command exists
|
||||
cmdPath, err = exec.LookPath(relativeToCwd)
|
||||
var lookpath string
|
||||
if filepath.IsAbs(h.ExecuteCommand) || h.CommandWorkingDirectory == "" {
|
||||
lookpath = h.ExecuteCommand
|
||||
} else {
|
||||
lookpath = filepath.Join(h.CommandWorkingDirectory, h.ExecuteCommand)
|
||||
}
|
||||
|
||||
cmdPath, err := exec.LookPath(lookpath)
|
||||
if err != nil {
|
||||
log.Printf("[%s] error locating command: '%s'", rid, h.ExecuteCommand)
|
||||
log.Printf("[%s] error in %s", rid, err)
|
||||
|
||||
// check if parameters specified in execute-command by mistake
|
||||
if strings.IndexByte(h.ExecuteCommand, ' ') != -1 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue