Skip to content
Back to skills

Return None For Failure

ASecurity

For graceful failure: return None or False instead of exceptions, let caller decide how to handle failure.

  • 4 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 7, 2026
ai-agentspythongo

Security analysis

A100/100

Scanned November 7, 2026

npx -y skills add jimmc414/claude-code-plugin-marketplace --skill return-none-for-failure --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Return None For Failure?

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

Security grade badge for Return None For Failure
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/jimmc414-return-none-for-failure/badge)](https://www.skillsdirectory.com/skills/jimmc414-return-none-for-failure)

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
---
name: return-none-for-failure
description: "For graceful failure: return None or False instead of exceptions, let caller decide how to handle failure."
---

# return-none-for-failure

## When to Use
- Algorithm might not find solution
- Search can fail naturally
- Caller should check result
- Backtracking search patterns

## When NOT to Use
- Failure is a programming error (raise exception)
- Caller must handle failure (exception is clearer)
- None is a valid result

## The Pattern

Return None (or False) to indicate failure, let caller check.

```python
def find(items, predicate):
    """Find first item matching predicate, or None."""
    for item in items:
        if predicate(item):
            return item
    return None  # Not found

# Caller checks
result = find(items, is_valid)
if result is not None:
    process(result)
else:
    handle_not_found()
```

## Example (from pytudes)

```python
# Sudoku solver (sudoku.py)
def search(values):
    """Using depth-first search and propagation."""
    if values is False:
        return False  # Failed earlier

    if all(len(values[s]) == 1 for s in squares):
        return values  # Solved!

    # Choose unfilled square with fewest possibilities
    n, s = min((len(values[s]), s)
               for s in squares if len(values[s]) > 1)

    for d in values[s]:
        result = search(assign(values.copy(), s, d))
        if result:  # Found solution
            return result

    return False  # No solution found

# Constraint propagation
def eliminate(values, s, d):
    """Return values, or False if contradiction detected."""
    if d not in values[s]:
        return values  # Already done

    values[s] = values[s].replace(d, '')

    if len(values[s]) == 0:
        return False  # Contradiction

    # ... more propagation
    return values

# Usage pattern
solution = solve(puzzle)
if solution:
    display(solution)
else:
    print("No solution exists")

# Cryptarithmetic (Cryptarithmetic.ipynb)
def first(iterable):
    """First element of iterable, or None."""
    return next(iter(iterable), None)

solution = first(solve('SEND + MORE = MONEY'))
if solution:
    print(solution)
```

## Key Principles
1. **False/None for "not found"**: Not an exception
2. **Caller checks with `if`**: Natural control flow
3. **Propagate failure**: `if result is False: return False`
4. **Truthy check works**: `if result:` catches None/False
5. **Document the contract**: Docstring says what failure means

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.

View all in ai-agents →

Comments

Loading comments…

Newsletter

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