Catch error from non-existing hook files when executing

Closes #62
This commit is contained in:
Marius 2016-09-15 23:15:54 +02:00
parent dc673402d2
commit 8e4959dccd
1 changed files with 14 additions and 2 deletions

View File

@ -90,10 +90,22 @@ func invokeHookSync(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byt
cmd.Dir = Flags.HooksDir
cmd.Stderr = os.Stderr
// If `captureOutput` is true, this function will return the output (both,
// stderr and stdout), else it will use this process' stdout
var output []byte
if !captureOutput {
cmd.Stdout = os.Stdout
return nil, cmd.Run()
err = cmd.Run()
} else {
return cmd.Output()
output, err = cmd.Output()
}
// Ignore the error, only, if the hook's file could not be found. This usually
// means that the user is only using a subset of the available hooks.
if os.IsNotExist(err) {
stdout.Printf("Unable to invoke %s hook: %s\n", name, err)
err = nil
}
return output, err
}