# invalid UTF-8 rune string: "\xff"

- **ID:** `go/invalid-utf-8-rune-string`
- **Domain:** go
- **Category:** encoding_error
- **Verification:** ai_generated
- **Fix Rate:** 78%

## Root Cause

Attempting to decode a byte sequence that is not valid UTF-8, often from external data sources like network streams or file reads without proper encoding handling.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Go 1.21 | active | — | — |
| Go 1.22 | active | — | — |
| Go 1.23 | active | — | — |

## Workarounds

1. **Use strings.ToValidUTF8() to replace invalid bytes with the Unicode replacement character U+FFFD** (85% success)
   ```
   Use strings.ToValidUTF8() to replace invalid bytes with the Unicode replacement character U+FFFD
   ```
2. **Read data as []byte and decode with utf8.Valid() validation before string conversion** (90% success)
   ```
   Read data as []byte and decode with utf8.Valid() validation before string conversion
   ```

## Dead Ends

- **** — Binary data cannot be safely represented as UTF-8 strings; this leads to data corruption and runtime panics. (95% fail)
- **** — These operations still expect valid UTF-8 and will produce the same error or silently corrupt data. (80% fail)
