{"record":{"id":"7ec3f3c290ec341e","repo":"affaan-m/ECC","slug":"user-not-found-user-id","errorCode":null,"errorMessage":"User not found: {user_id}","messagePattern":"User not found: (.+?)","errorType":"exception","errorClass":"NotFoundError","httpStatus":null,"severity":"error","filePath":"skills/python-patterns/SKILL.md","lineNumber":194,"sourceCode":"\n```python\nclass AppError(Exception):\n    \"\"\"Base exception for all application errors.\"\"\"\n    pass\n\nclass ValidationError(AppError):\n    \"\"\"Raised when input validation fails.\"\"\"\n    pass\n\nclass NotFoundError(AppError):\n    \"\"\"Raised when a requested resource is not found.\"\"\"\n    pass\n\n# Usage\ndef get_user(user_id: str) -> User:\n    user = db.find_user(user_id)\n    if not user:\n        raise NotFoundError(f\"User not found: {user_id}\")\n    return user\n```\n\n## Context Managers\n\n### Resource Management\n\n```python\n# Good: Using context managers\ndef process_file(path: str) -> str:\n    with open(path, 'r') as f:\n        return f.read()\n\n# Bad: Manual resource management\ndef process_file(path: str) -> str:\n    f = open(path, 'r')\n    try:\n        return f.read()","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/affaan-m/ECC/blob/d8409a4b0813771235555e32e3d8046a73988bfa/skills/python-patterns/SKILL.md#L176-L212","documentation":"Illustrative custom-exception example from the python-patterns skill: get_user's db lookup returned nothing for user_id, so a domain NotFoundError is raised instead of a generic exception. The unknown user_id is the invalid input, and the typed error lets callers handle missing resources distinctly.","triggerScenarios":"Thrown at skills/python-patterns/SKILL.md:194 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Catch NotFoundError at the API layer and map it to 404","Distinguish 'not found' from 'deleted'/'permission denied' with separate exception subclasses","Log lookups that miss to detect probing or stale ids"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d8409a4b0813771235555e32e3d8046a73988bfa","analyzedAt":"2026-08-26T12:15:34.022Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}