Skip to content

Refactoring: Return non-zero exit codes for error conditions #183

@stefanprodan

Description

@stefanprodan

Expected Behaviour

When a command fails I would expect exit code 1 so automation tools can detect an error occurred and stop/react accordingly.

Current Behaviour

Some examples of error handling:

	response, err := proxy.InvokeFunction(gateway, functionName, &functionInput, contentType)
	if err != nil {
		fmt.Println(err)
		return
	}
	if len(services.Functions) > 0 {
		pushStack(&services, parallel)
	} else {
		fmt.Println("You must supply a valid YAML file.")
		return
	}
	if len(services.Functions) > 0 {
		pushStack(&services, parallel)
	} else {
		fmt.Println("You must supply a valid YAML file.")
		return
	}

Possible Solution

  • use cobra.Command.RunE instead of Run
  • change the signature of all runCmd functions to return error
  • propagate errors with pkg/errors and wrap the original error with meaningful messages

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions