Developer tools dump stack traces, exit codes, and jargon. Figuring out *what to do next* often means searching the same Stack Overflow answers again.
| 1 | <p align="center"> |
| 2 | <img src="assets/why-failed-banner.png" alt="why-failed — cryptic errors to actionable fixes" width="100%"> |
| 3 | </p> |
| 4 | |
| 5 | # why-failed |
| 6 | |
| 7 | > Turn cryptic developer errors into actionable fixes. |
| 8 | |
| 9 | Developer tools dump stack traces, exit codes, and jargon. Figuring out *what to do next* often means searching the same Stack Overflow answers again. |
| 10 | |
| 11 | `why-failed` is a local-first CLI that reads an error message (from arguments, stdin, or a file), matches it against a curated rule database, and prints a short **why / check / fix** explanation. |
| 12 | |
| 13 | It does **not** call OpenAI, Anthropic, Gemini, Ollama, or any other model. Version 1 is fully offline, deterministic, and works without API keys or network access. |
| 14 | |
| 15 | ## Features |
| 16 | |
| 17 | - Local-first — no cloud, no API keys |
| 18 | - Deterministic rule matching (same input → same output) |
| 19 | - 79 built-in rules across common tooling |
| 20 | - Git, npm, Node, Python, Docker, TypeScript, MongoDB, Redis, Linux |
| 21 | - stdin piping, file input, and direct arguments |
| 22 | - JSON output for scripts |
| 23 | - Secret redaction before display |
| 24 | - Windows, macOS, and Linux |
| 25 | |
| 26 | ## Installation |
| 27 | |
| 28 | ```bash |
| 29 | pip install why-failed |
| 30 | ``` |
| 31 | |
| 32 | Development install: |
| 33 | |
| 34 | ```bash |
| 35 | git clone <repo> |
| 36 | cd why-failed |
| 37 | python -m venv .venv |
| 38 | source .venv/bin/activate # Windows: .venv\Scripts\activate |
| 39 | pip install -e ".[dev]" |
| 40 | ``` |
| 41 | |
| 42 | ## Usage |
| 43 | |
| 44 | ```bash |
| 45 | # Direct text |
| 46 | why-failed "fatal: not a git repository" |
| 47 | |
| 48 | # Multiple arguments (joined) |
| 49 | why-failed npm ERR! ERESOLVE unable to resolve dependency tree |
| 50 | |
| 51 | # Pipe a failing command |
| 52 | npm install 2>&1 | why-failed |
| 53 | |
| 54 | # Read a log file |
| 55 | why-failed --file error.log |
| 56 | |
| 57 | # Explicit stdin |
| 58 | why-failed --stdin < build.log |
| 59 | |
| 60 | # Machine-readable JSON |
| 61 | why-failed --json "ECONNREFUSED 127.0.0.1:6379" |
| 62 | |
| 63 | # Only print the primary fix |
| 64 | why-failed --quiet "ECONNREFUSED 127.0.0.1:6379" |
| 65 | |
| 66 | # Show score / alternatives |
| 67 | why-failed --verbose "ECONNREFUSED 127.0.0.1:6379" |
| 68 | |
| 69 | # List rules |
| 70 | why-failed --list-rules |
| 71 | ``` |
| 72 | |
| 73 | ### Exit codes |
| 74 | |
| 75 | | Code | Meaning | |
| 76 | | ---: | ------- | |
| 77 | | 0 | Successful analysis (rule matched) | |
| 78 | | 1 | Input / runtime error | |
| 79 | | 2 | No matching rule | |
| 80 | |
| 81 | A failed original command does **not** force a non-zero exit — this tool analyzes failures. |
| 82 | |
| 83 | ## Example |
| 84 | |
| 85 | Before: |
| 86 | |
| 87 | ```text |
| 88 | Error: connect ECONNREFUSED 127.0.0.1:6379 |
| 89 | ``` |
| 90 | |
| 91 | After: |
| 92 | |
| 93 | ```text |
| 94 | ✗ Redis connection failed |
| 95 | |
| 96 | WHY |
| 97 | The application tried to connect to Redis, but the connection was refused. |
| 98 | |
| 99 | CHECK |
| 100 | → Is Redis running? |
| 101 | → Is port 6379 listening? |
| 102 | → Is REDIS_URL correct? |
| 103 | |
| 104 | FIX |
| 105 | 1. docker compose up -d redis |
| 106 | 2. Check REDIS_URL |
| 107 | 3. Check whether port 6379 is exposed |
| 108 | |
| 109 | Confidence: High |
| 110 | ``` |
| 111 | |
| 112 | ## Supported tools |
| 113 | |
| 114 | | Tool | Rules | |
| 115 | | ---------- | ----: | |
| 116 | | Git | 12 | |
| 117 | | npm | 9 | |
| 118 | | Node | 7 | |
| 119 | | Python | 11 | |
| 120 | | Docker | 10 | |
| 121 | | TypeScript | 9 | |
| 122 | | MongoDB | 6 | |
| 123 | | Redis | 6 | |
| 124 | | Linux | 9 | |
| 125 | | **Total** | **79** | |
| 126 | |
| 127 | ## Architecture |
| 128 | |
| 129 | ```text |
| 130 | Input |
| 131 | ↓ |
| 132 | Normalizer (ANSI strip, CRLF, secrets, size limit) |
| 133 | ↓ |
| 134 | Matcher (deterministic scoring) |
| 135 | ↓ |
| 136 | Rule Registry |
| 137 | ↓ |
| 138 | Structured Result |
| 139 | ↓ |
| 140 | Terminal / JSON |
| 141 | ``` |
| 142 | |
| 143 | An `ErrorProvider` protocol exists so an optional AI provider can be added later without rewriting the core pipeline. V1 ships only the local rules provider. |
| 144 | |
| 145 | ## Security |
| 146 | |
| 147 | ```text |
| 148 | No network requests. |
| 149 | No command execution. |
| 150 | Secrets are redacted before display. |
| 151 | ``` |
| 152 | |
| 153 | - Never executes the failed command or suggested fixes |
| 154 | - Reads files only when you pass `--file PATH` |
| 155 | - Redacts common tokens, passwords, and DB URIs |
| 156 | |
| 157 | ## Contributing |
| 158 | |
| 159 | See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, tests, and how to add a rule. |
| 160 | |
| 161 | Quick rule sketch: |
| 162 | |
| 163 | ```python |
| 164 | Rule( |
| 165 | id="docker.port_allocated", |
| 166 | tool="docker", |
| 167 | title="Port is already allocated", |
| 168 | why="Docker could not bind a published port because another process already uses it.", |
| 169 | checks=("Is another container using that host port?",), |
| 170 | fixes=("docker ps",), |
| 171 | patterns=(Pattern(r"port is already allocated", kind="regex", required=True),), |
| 172 | confidence="high", |
| 173 | ) |
| 174 | ``` |
| 175 | |
| 176 | ## Roadmap |
| 177 | |
| 178 | Possible future features (not in v1): |
| 179 | |
| 180 | - optional local LLM provider |
| 181 | - MCP server |
| 182 | - shell integration |
| 183 | - IDE integration |
| 184 | - community rule packs |
| 185 | - GitHub Action |
| 186 | |
| 187 | ## License |
| 188 | |
| 189 | MIT — see [LICENSE](LICENSE). |