Signal handling (SIGINT/SIGTERM)
Why it matters
When a user presses Ctrl+C mid-operation and the CLI has no SIGINT handler, any temporary files written during that run become orphaned, any terminal modifications (hidden cursor, raw mode, alternate screen) persist into the next shell prompt, and partial output files are left in a state that corrupts subsequent runs. ISO 25010:2011 reliability.fault-tolerance requires that interruption be a recoverable event, not a resource leak. The exit code matters too: a process killed by SIGINT that exits 0 misleads shell scripts into treating the interrupt as a successful completion — the conventional exit codes are 130 (SIGINT) and 143 (SIGTERM), encoding 128 + signal_number.
Severity rationale
Medium because absent signal handling leaves orphaned resources and corrupted terminal state on every Ctrl+C, but the impact is bounded to the local user session.
Remediation
Register cleanup handlers for both SIGINT and SIGTERM before any long-running work begins:
const tempFiles: string[] = []
process.on('SIGINT', () => {
console.error('\nInterrupted, cleaning up...')
for (const f of tempFiles) {
try { unlinkSync(f) } catch {}
}
process.exit(130) // 128 + 2 (SIGINT)
})
process.on('SIGTERM', () => {
console.error('Terminated, cleaning up...')
for (const f of tempFiles) {
try { unlinkSync(f) } catch {}
}
process.exit(143) // 128 + 15 (SIGTERM)
})
import signal, sys
def handle_sigint(signum, frame):
click.echo('\nInterrupted, cleaning up...', err=True)
cleanup()
sys.exit(130)
signal.signal(signal.SIGINT, handle_sigint)
If your CLI hides the cursor or enters raw mode, restore terminal state in the same handler before exiting.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the CLI Quality Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · reliability.fault-tolerance — Reliability — Fault Tolerance
Taxons
History
- 2026-04-18·v1.0.0·Initial import from cli-quality·automated