|
Download code/bad003.jsonl from winapiadmin/tinycodinglm: direct link, hf CLI and curl.
- Browser
- Download file 2.09 kB
-
https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/034ba678829a1c436b19d43dd3adab33b5170a80/code/bad003.jsonl
- Command line
-
hf download hf://datasets/winapiadmin/tinycodinglm@034ba678829a1c436b19d43dd3adab33b5170a80/code/bad003.jsonl
-
curl -L -o bad003.jsonl https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/034ba678829a1c436b19d43dd3adab33b5170a80/code/bad003.jsonl
2.09 kB
| {"type": "session", "harness": "deepseek-harness", "id": "bad003", "name": "Bad error handling practices"} | |
| {"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}} | |
| {"type": "message", "message": {"role": "user", "content": "What are bad error handling practices?"}} | |
| {"type": "message", "message": {"role": "assistant", "content": "**Bad Practices:**\n\n1. **Bare Except / Catch All:**\n```python\n# Bad\ntry:\n do_something()\nexcept:\n pass # silently ignores ALL errors\n\n# Good\ntry:\n do_something()\nexcept ValueError as e:\n logger.error(f\"Invalid value: {e}\")\n raise\n```\n\n2. **Swallowing Exceptions:**\n```python\n# Bad\ntry:\n parse_data(raw)\nexcept:\n return None # caller has no idea what went wrong\n\n# Good\ntry:\n parse_data(raw)\nexcept ParseError as e:\n raise ValueError(f\"Failed to parse: {e}\") from e\n```\n\n3. **Generic Error Messages:**\n```python\n# Bad\nraise Exception(\"Error occurred\")\n\n# Good\nraise FileNotFoundError(f\"Config not found at {path}\")\n```\n\n4. **Returning None Instead of Error:**\n```python\n# Bad\ndef divide(a, b):\n if b == 0:\n return None\n return a / b\n\n# Good\ndef divide(a, b):\n if b == 0:\n raise ZeroDivisionError(\"Cannot divide by zero\")\n return a / b\n```\n\n5. **Using Exceptions for Flow Control:**\n```python\n# Bad\ntry:\n value = my_dict[key]\nexcept KeyError:\n value = default\n\n# Good\nvalue = my_dict.get(key, default)\n```\n\n6. **Catching Too Broadly:**\n```python\n# Bad\ntry:\n api_call()\nexcept Exception: # catches KeyboardInterrupt too\n pass\n\n# Good\ntry:\n api_call()\nexcept (ConnectionError, TimeoutError) as e:\n retry()\n```"}} | |