Module: Bwrap::Execution::Labels

Defined in:
lib/bwrap/execution/labels.rb

Overview

Exit codes for exit status handling.

These are not strictly speaking related to execution system, but rather to handle execution status of actual scripts. For example, to set exit code for Output#error call.

Since this is fully own module, it shouldn’t harm for this to be here.

Constant Summary collapse

NO_ERROR =

If we had a successful run, i.e. no error happened.

0
INVALID_ERROR =

Do not use.

1
UNSPECIFIED_ERROR =

When Output#error has been called with no :label.

2
GENERIC_ERROR =

If no better error code has been created.

3

Class Method Summary collapse

Class Method Details

.add_label(label, exit_code) ⇒ Object

Add a custom label.

Parameters:

  • label (Symbol)

    Name of exit code label

  • exit_code (Integer)

    Number in range 0-255



69
70
71
72
# File 'lib/bwrap/execution/labels.rb', line 69

def self.add_label label, exit_code
  @additional_labels ||= {}
  @additional_labels[label] = exit_code
end

.resolve_exit_code(label) ⇒ Integer

Converts given label to real exit code.

Accepted labels:

  • :success

  • :unspecified

  • :generic

  • :target_host_not_found

  • :no_package_manager

  • :debootstrap_failed

  • :file_not_modified

Additional labels can be added with add_label.

Parameters:

  • label (Symbol)

    Label to be converted to a exit code

Returns:

  • (Integer)

    Exit code between 0 to 255



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bwrap/execution/labels.rb', line 49

def self.resolve_exit_code label
  return @additional_labels[label] if @additional_labels and @additional_labels[label]

  case label
  when :success
    NO_ERROR
  when :unspecified
    UNSPECIFIED_ERROR
  when :generic
    GENERIC_ERROR
  else
    warn "Got invalid error label: #{label}"
    INVALID_ERROR
  end
end