# flag provided but not defined: -foo

- **ID:** `go/flag-provided-but-not-defined`
- **Domain:** go
- **Category:** build_error
- **Verification:** ai_generated
- **Fix Rate:** 97%

## Root Cause

A command-line flag passed to a Go program that does not have a corresponding flag definition using the flag package.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| go1.20 | active | — | — |
| go1.21 | active | — | — |
| go1.22 | active | — | — |

## Workarounds

1. **Define the flag before parsing: var foo string; flag.StringVar(&foo, "foo", "", "usage"); flag.Parse()** (97% success)
   ```
   Define the flag before parsing: var foo string; flag.StringVar(&foo, "foo", "", "usage"); flag.Parse()
   ```
2. **If the flag is from a third-party tool, check its documentation and add the correct flag definition** (95% success)
   ```
   If the flag is from a third-party tool, check its documentation and add the correct flag definition
   ```
3. **Use flag.VisitAll() to list all defined flags and verify the intended flag exists** (90% success)
   ```
   Use flag.VisitAll() to list all defined flags and verify the intended flag exists
   ```

## Dead Ends

- **Change the flag name in the command line to match an existing flag** — May not be the intended flag; could cause incorrect behavior if the wrong flag is used (50% fail)
- **Ignore the error and continue execution by catching it** — flag.Parse() terminates on undefined flags; cannot be ignored (95% fail)
- **Use a third-party flag library that doesn't report this error** — Switching libraries may introduce compatibility issues and doesn't fix the missing definition (60% fail)
