execx

package module
Version: v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2019 License: ISC Imports: 7 Imported by: 0

README

execx

import "acln.ro/execx"

GoDoc

Extensions to os/exec, to collect richer exit errors.

Documentation

Overview

Package execx provides convenience extensions to os/exec, to collect richer exit errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cmdline

func Cmdline(cmd *exec.Cmd) string

Cmdline returns an approximation of the command line invocation equivalent to cmd. The returned string is the concatenation of filepath.Base(cmd.Path) and cmd.Args, separated by spaces.

Note that Cmdline does not produce shell-safe output, and does not account for environment variables. Cmdline should be used for strictly informative purposes, such as logging or debugging.

func Wrap

func Wrap(err error, cmd *exec.Cmd) error

Wrap wraps an *exec.ExitError in a *ExitError, decorating it with additional details about the command. For convenience, Wrap also makes the following decisions:

If err is nil, Wrap returns nil.

If err is not of type *exec.ExitError, it is returned unchanged.

If err is of type *exec.ExitError, but did not originate from cmd, it is returned unchanged.

Types

type ExitError

type ExitError struct {
	// The original ExitError returned by os/exec.
	*exec.ExitError

	// Path is the path of the command which was executed.
	Path string

	// Args holds command line arguments.
	Args []string

	// Dir holds the working directory for the child process.
	Dir string

	// ParentEnv is the environment of the parent process.
	ParentEnv env.Map

	// ChildEnv is the environment of the child process.
	ChildEnv env.Map
}

ExitError wraps an *os/exec.ExitError with additional details.

func (*ExitError) Cmdline

func (e *ExitError) Cmdline() string

Cmdline returns the concatenation of filepath.Base(e.Path) and e.Args, separated by spaces. See func Cmdline.

func (*ExitError) Error

func (e *ExitError) Error() string

Error returns e.ExitError.Error().

func (*ExitError) Format

func (e *ExitError) Format(s fmt.State, verb rune)

Format implements fmt.Formatter for *ExitError as follows:

If the verb is anything other than 'v', Format emits no output.

For "%v", Format emits e.Cmdline(), the exit status of the process, and standard error output, if it was captured.

For "%+v", Format emits everything "%v" emits, and some additional details about the child process: its working directory, its user and system CPU time, its environment, etc.

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

Unwrap returns the e.ExitError.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL