What problem does it solve?
This Skill provides patterns and best practices for implementing robust error handling, cleanup routines, and debugging in shell scripts, ensuring reliability and maintainability.
Core Features & Use Cases
- Exit Code Management: Understand and utilize standard exit codes for clear success/failure indication.
- Error Checking: Implement patterns to reliably check command success and handle failures gracefully.
- Cleanup with Traps: Ensure resources are cleaned up automatically upon script exit, regardless of how it terminates (success, error, or interrupt).
- Error Reporting: Standardize error messages to stderr and implement functions for logging and fatal errors.
- Defensive Programming: Validate prerequisites, inputs, and create secure temporary files/directories.
- Debugging: Enable debug modes and trace execution for easier troubleshooting.
- Error Recovery: Implement retry and fallback mechanisms for resilient script execution.
- Use Case: When writing a complex deployment script, use this Skill's patterns to ensure temporary files are removed, services are stopped cleanly, and meaningful error messages are displayed if any step fails.
Quick Start
Use the shell-error-handling skill to implement a trap for cleaning up temporary files upon script exit.