Allow ExecError to wrap other errors. Wrap ErrTimeout during timeout failures.

PiperOrigin-RevId: 507456687
This commit is contained in:
Matt LaPlante
2023-02-06 05:53:25 -08:00
committed by Copybara-Service
parent a65510befb
commit 327255c518
2 changed files with 5 additions and 1 deletions

View File

@@ -38,6 +38,7 @@ type ExecResult struct {
type ExecError struct {
errmsg string
procresult ExecResult
wraps error
}
// ExecConfig provides flexible execution configuration.
@@ -85,6 +86,8 @@ func (e ExecError) Error() string {
return e.errmsg
}
func (e ExecError) Unwrap() error { return e.wraps }
// Result returns any information that could be captured from the subprocess that was executed.
func (e ExecError) Result() ExecResult {
return e.procresult

View File

@@ -205,9 +205,10 @@ func execute(path string, args []string, conf *ExecConfig) (ExecResult, error) {
// when the execution times out return a timeout error
if conf.Timeout != nil && !timer.Stop() {
return result, &ExecError{
return result, ExecError{
errmsg: ErrTimeout.Error(),
procresult: result,
wraps: ErrTimeout,
}
}