From 8e4959dccd8959bbc0799ef0b00870c89763c67f Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 15 Sep 2016 23:15:54 +0200 Subject: [PATCH] Catch error from non-existing hook files when executing Closes #62 --- cmd/tusd/cli/hooks.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/tusd/cli/hooks.go b/cmd/tusd/cli/hooks.go index 0baf3e3..10c7abb 100644 --- a/cmd/tusd/cli/hooks.go +++ b/cmd/tusd/cli/hooks.go @@ -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 }