affaan-m/ECC · error · ValueError
Failed to parse data
Error message
Failed to parse data: {data} What it means
Illustrative exception-chaining example from the python-patterns skill: process_data's json.loads raised JSONDecodeError and it is re-raised as ValueError containing the raw data, with the original preserved via `from e`. The malformed data string is the input at fault.
Solutions
- Include the decode error's position instead of echoing the whole payload
- Truncate long data in the message to avoid log bloat
- Distinguish malformed input from other ValueErrors with a dedicated exception type
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at skills/python-patterns/SKILL.md:172 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of affaan-m/ECC@d8409a4b08 (2026-08-26).
Data as JSON: /api/errors/3e635a90d5f90f1e.
Report an issue: GitHub.
Appendix: source
Thrown at skills/python-patterns/SKILL.md:172
# Bad: Bare except
def load_config(path: str) -> Config:
try:
with open(path) as f:
return Config.from_json(f.read())
except:
return None # Silent failure!
```
### Exception Chaining
```python
def process_data(data: str) -> Result:
try:
parsed = json.loads(data)
except json.JSONDecodeError as e:
# Chain exceptions to preserve the traceback
raise ValueError(f"Failed to parse data: {data}") from e
```
### Custom Exception Hierarchy
```python
class AppError(Exception):
"""Base exception for all application errors."""
pass
class ValidationError(AppError):
"""Raised when input validation fails."""
pass
class NotFoundError(AppError):
"""Raised when a requested resource is not found."""
pass
# UsageView on GitHub (pinned to d8409a4b08)