Error Handling Patterns

Error handling patterns I’ve actually used. Every entry has a date and context.

2026-04-02: GPG Agent TTY Refresh

Problem: GPG pinentry fails in SSH sessions — wrong TTY, prompt never appears

Context: P16g remote deployment, gopass operations over SSH tunnel

The Fix:

# Add to .zshrc for SSH session GPG fix
gpg-connect-agent updatestartuptty /bye >/dev/null 2>&1

# Why: GPG agent caches the TTY from first use.
# SSH sessions get a new TTY that the agent doesn't know about.
# This tells the agent to update its cached TTY to current.

Rule: Add gpg-connect-agent updatestartuptty /bye to shell RC for remote GPG operations.

Worklog: WRKLOG-2026-04-02


2026-04-02: GPG Lock Cleanup

Problem: GPG operations fail with "lock file exists" after interrupted operation

Context: P16g gopass bootstrap, GPG agent crash during key import

The Fix:

# Find stale locks
find ~/.gnupg -name "*.lock" -ls

# Remove stale locks (only if gpg-agent is not running)
find ~/.gnupg -name "*.lock" -delete

# Restart agent
gpgconf --kill gpg-agent
gpg-connect-agent /bye

Rule: GPG lock files are not automatically cleaned on crash. Check for stale locks when GPG operations fail mysteriously.

Worklog: WRKLOG-2026-04-02