mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-12 08:34:43 +00:00
Merge pull request #460 from moorereason/iss456-log-exec-err
Log stdlib error on failed exec.LookPath
This commit is contained in:
commit
b8498c564d
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 {
|
||||
|
|
|
@ -720,7 +720,7 @@ env: HOOK_head_commit.timestamp=2013-03-12T08:14:29-07:00
|
|||
|
||||
// Check logs
|
||||
{"static params should pass", "static-params-ok", nil, "POST", nil, "application/json", `{}`, http.StatusOK, "arg: passed\n", `(?s)command output: arg: passed`},
|
||||
{"command with space logs warning", "warn-on-space", nil, "POST", nil, "application/json", `{}`, http.StatusInternalServerError, "Error occurred while executing the hook's command. Please check your logs for more details.", `(?s)error locating command.*use 'pass[-]arguments[-]to[-]command' to specify args`},
|
||||
{"command with space logs warning", "warn-on-space", nil, "POST", nil, "application/json", `{}`, http.StatusInternalServerError, "Error occurred while executing the hook's command. Please check your logs for more details.", `(?s)error in exec:.*use 'pass[-]arguments[-]to[-]command' to specify args`},
|
||||
{"unsupported content type error", "github", nil, "POST", map[string]string{"Content-Type": "nonexistent/format"}, "application/json", `{}`, http.StatusBadRequest, `Hook rules were not satisfied.`, `(?s)error parsing body payload due to unsupported content type header:`},
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue