Skip to content
Back to skills

Defensive Programming

ASecurity

Keep behavior predictable and safe when external systems or user input fail.

  • 14 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added September 19, 2026
toolsapi

Works with

  • api

Security analysis

A100/100

Scanned September 19, 2026

npx -y skills add itsnin/spotlight --skill defensive-programming --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Defensive Programming?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Defensive Programming
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/itsnin-defensive-programming/badge)](https://www.skillsdirectory.com/skills/itsnin-defensive-programming)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Defensive Programming
Keep behavior predictable and safe when external systems or user input fail.
## Validate Inputs
Validate argument count, type, numeric ranges, and allowlisted values before using input in an API call. Reject invalid input with a clear message.
```js
if (typeof accelerator !== 'string' || accelerator.length === 0)
    return false;
```
## Check Dependencies
Check required objects and methods before first use. A genuinely required capability must fail clearly; an optional component may report the absence and continue only when that is an intentional contract.
```js
if (!Main.overview.searchEntry) {
    console.warn('Spotlight: overview search entry not found');
    return;
}
```
## Temporary Resources
Use `GLib.idle_add` with `GLib.SOURCE_REMOVE` for one-shot callbacks. Always store signal IDs that use plain `connect` and disconnect them explicitly. Never rely on garbage collection for cleanup.
## Idempotency
A second enable or disable should converge on the same state. Check before stealing widgets, overriding prototypes, or connecting signals. Avoid broad cleanup globs and make each cleanup target explicit.
## Actor Safety
- Guard against missing actors when traversing the overview hierarchy — `Main.overview._overview?._controls?._thumbnailsBox` with explicit existence checks, not optional chaining on guaranteed paths.
- Verify `monitorIndex` is within valid range before creating a `BackgroundManager` for that monitor.
- Guard `get_preferred_height` return values with `Number.isFinite()` before using them in layout calculations.
## Hard and Optional Failures
Required setup failures must stop before later code runs against an incomplete environment. Optional component failures need a concise warning and a safe continuation path. Do not hide a failure with an unconditional `true`.
## Logging
Log enough context to identify the failed component. Use appropriate `console` levels (`debug`, `warn`, `error`) rather than bare `log`. Never log sensitive data.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.