Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Handle a nonzero exit code according to whether the result is expected: deliberately branch on valid outcomes, but preserve failures from required work all the way to the agent controller or CI runner. Capture status immediately, configure pipelines so an earlier failure cannot be hidden, and run diagnostics or cleanup without letting them turn a failed task into a reported success.

First decide whether the nonzero result is an error

Exit codes are interpreted by the caller. In GNU Bash, status 0 means success and a nonzero status means failure; individual programs may assign their own meanings to nonzero values. A search that finds no optional match might be a normal branch, while a failed build, test, or required edit generally means the task did not succeed. Bash also uses 126 for a command that was found but could not be executed, 127 for command-not-found, and 128 + N for termination by fatal signal N. These are Bash conventions, not a universal codebook for all programs. See the GNU Bash manual on exit status.

For each command, establish which outcomes are valid and what the workflow should do next. Handle an expected nonzero outcome explicitly; do not suppress an unexpected one merely to keep the run moving.

Branch explicitly on a command’s result

Keep the status decision adjacent to the command that produced it. In Bash, $? contains the status of the most recently executed command, so an intervening logging or diagnostic command can overwrite the value. Prefer a conditional that tests the command directly:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
if grep -q "optional pattern" input.txt; then
  echo "Match found; continue with the matching path."
else
  echo "No match; continue with the documented no-match path."
fi

This makes the expected branch visible and avoids confusing an intentional “no match” with a failed required operation. For a command whose failure is not an expected branch, allow the failure to propagate or handle it explicitly while preserving a nonzero final result.

Make pipeline failures visible

By default, Bash assigns a pipeline the status of its last command. That means a producer can fail while a later formatter succeeds, leaving the overall pipeline looking successful. Bash’s pipefail option changes the pipeline status to the rightmost command that failed, or zero if every component succeeded. The manual documents this behavior in Bash pipelines.

set -o pipefail
producer | formatter

Use pipefail when failure in any pipeline component should fail the operation. It reports a pipeline-level status, not a complete list of which components failed. If the workflow needs component-by-component attribution, capture those statuses separately.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Use set -e as a guardrail, not a guarantee

Bash’s -e (also called errexit) does not exit after every nonzero command in every context. The manual lists exceptions, including commands used as tests in if, while, or until; most commands in && and || lists; non-final pipeline elements when pipefail is not enabled; and commands whose status is inverted with !. Consequently, set -e is useful fail-fast protection in some scripts, but it is not a substitute for explicit decisions about important command results.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check statuses directly wherever the workflow needs a particular response—for example, when a failed test should stop required work, but a missing optional search result should select a normal alternative.

Preserve failure through wrappers, cleanup, and diagnostics

A wrapper or agent step should return a nonzero result when required work fails. Logging the problem, saving artifacts, or running cleanup can be useful, but a successful final housekeeping command must not erase the original failure. Structure the wrapper so it records the failed status, performs the needed recovery, and then reports failure to its caller.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

In execution traces, record enough context to identify and diagnose the failure: the command, working directory, relevant environment, standard output and error, and exit status. This is practical implementation guidance; the shell and CI documentation defines status behavior but does not prescribe one universal agent logging format.

Do not retry every nonzero status automatically. First determine whether the command documents the condition as transient; a retry may repeat side effects and will not fix a deterministic error.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Apply the runtime’s contract in GitHub Actions

These shell details should not be assumed to describe every agent runner or CI service. In GitHub Actions, each run keyword starts a new process and shell in the runner environment. GitHub documents that, on non-Windows runners, an unspecified shell invokes bash -e with fallback behavior, while explicitly selecting bash invokes bash --noprofile --norc -eo pipefail. The selected shell’s status determines whether the step succeeds or fails. Check the current GitHub Actions workflow syntax documentation for the shell and platform in use.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

GitHub maps exit code 0 to success and every nonzero code to failure. Its documented consequences include canceling concurrent actions and skipping future dependent actions. A wrapper that accidentally returns success after failed required work can therefore affect more than its own log line. See GitHub’s guidance on setting exit codes for actions.

Run diagnostics after an earlier step fails

GitHub Actions applies an implicit success() status check to ordinary conditions. To run a diagnostic step after an earlier failure, use a failure-aware condition such as failure():

- name: Collect diagnostics
  if: ${{ failure() }}
  run: ./collect-diagnostics.sh

This is for recovery or diagnosis; it should not make failed required work appear successful. GitHub explains status-check functions in its workflow expressions documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Mark a JavaScript action as failed

For a JavaScript action, use core.setFailed(message) to log an error and set the action’s failure status. GitHub documents this as a shortcut for logging an error and exiting with status 1. See GitHub’s workflow command reference.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose the handling policy at the right scope

Before changing a workflow, identify where the status originates and what receives it. A useful decision sequence is:

  1. Classify the result: Is this nonzero status an intentional outcome, such as an absent optional match, or a failure of required work?
  2. Locate its scope: Did it come from one process, a script’s final command, a pipeline component, a task step, or the full agent run?
  3. Verify propagation: Will the wrapper, controller, or CI runner receive the original failure, or can a later successful command mask it?
  4. Select recovery: Should the workflow stop, retry under a documented transient-error policy, or continue only to collect diagnostics or clean up?
  5. Check the runtime contract: Confirm the shell, operating system, runner, and action type that define status behavior and defaults.

The authoritative behavior described here is specific to GNU Bash and GitHub Actions. For another shell, runner, agent framework, or CI service, consult its official documentation rather than assuming Bash or GitHub’s rules apply.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.