Download validation.jsonl from SalutefaceAAC/api-error-resolution-pairs: direct link, hf CLI and curl.
- Browser
- Download file 10.5 kB
-
https://huggingface.co/datasets/SalutefaceAAC/api-error-resolution-pairs/resolve/main/validation.jsonl
- Command line
-
hf download hf://datasets/SalutefaceAAC/api-error-resolution-pairs/validation.jsonl
-
curl -L -o validation.jsonl https://huggingface.co/datasets/SalutefaceAAC/api-error-resolution-pairs/resolve/main/validation.jsonl
10.5 kB
| {"language": "javascript", "library": "fetch", "error_type": "no_await", "error_message": "Promise pending instead of resolved data", "broken_code": "const data = fetch(\"https://api.example.com/data\").json(); // missing await", "explanation": "fetch() returns a Promise; without await the variable holds the Promise, not the data.", "fixed_code": "const resp = await fetch(\"https://api.example.com/data\");\nif (!resp.ok) throw new Error(`HTTP ${resp.status}`);\nconst data = await resp.json();", "key_insight": "Both fetch() and .json() are async and must be awaited; forgetting either returns a Promise.", "tags": ["fetch", "async", "await"], "id": 133} | |
| {"language": "python", "library": "requests", "error_type": "auth_missing", "error_message": "401 Unauthorized", "broken_code": "resp = requests.get(\"https://api.slack.com/api/chat.postMessage\")", "explanation": "The slack API requires authentication via X-API-Key header.", "fixed_code": "headers = {\"X-API-Key\": \"X-API-Key: {API_KEY}\"}\nresp = requests.get(\"https://api.slack.com/api/chat.postMessage\", headers=headers)\nresp.raise_for_status()", "key_insight": "Attach credentials in X-API-Key header; requests does not add them automatically.", "tags": ["auth", "401", "slack"], "id": 134} | |
| {"language": "python", "library": "requests", "error_type": "timeout_missing", "error_message": "requests.exceptions.ReadTimeout: HTTPSConnectionPool: Read timed out.", "broken_code": "resp = requests.get(\"https://api.github.com/repos/{owner}/{repo}/issues\")", "explanation": "No timeout set on call to github endpoint. Slow or down servers block indefinitely.", "fixed_code": "resp = requests.get(\"https://api.github.com/repos/{owner}/{repo}/issues\", timeout=30)\nresp.raise_for_status()", "key_insight": "Always set a timeout on requests to external APIs; the default is None (wait forever).", "tags": ["timeout", "requests", "github"], "id": 135} | |
| {"language": "javascript", "library": "fetch", "error_type": "no_error_check", "error_message": "Silently receives 4xx/5xx without throwing", "broken_code": "const resp = await fetch(\"https://api.slack.com/api/chat.postMessage\");\nconst data = await resp.json();", "explanation": "fetch() resolves even on HTTP errors from slack. Status must be checked manually.", "fixed_code": "const resp = await fetch(\"https://api.slack.com/api/chat.postMessage\");\nif (!resp.ok) throw new Error(`HTTP ${resp.status} from slack`);\nconst data = await resp.json();", "key_insight": "fetch() only rejects on network failure; always check resp.ok for HTTP-level errors.", "tags": ["fetch", "error-handling", "slack"], "id": 136} | |
| {"language": "javascript", "library": "axios", "error_type": "no_base_url", "error_message": "AxiosError: Request failed with status code 404", "broken_code": "import axios from \"axios\";\nconst resp = await axios.get(\"/users/1\");", "explanation": "Without a baseURL the relative path resolves against the current page origin.", "fixed_code": "const api = axios.create({ baseURL: \"https://api.example.com/v1\" });\nconst resp = await api.get(\"/users/1\");\nconsole.log(resp.data);", "key_insight": "Create an axios instance with baseURL set; don't mix relative paths with raw axios.get().", "tags": ["axios", "base-url", "404"], "id": 137} | |
| {"language": "python", "library": "requests", "error_type": "timeout_missing", "error_message": "requests.exceptions.ConnectionError: Read timed out.", "broken_code": "resp = requests.get(\"https://slow-api.example.com/data\")", "explanation": "No timeout was set, so the call blocks forever when the server is slow or unreachable.", "fixed_code": "resp = requests.get(\"https://slow-api.example.com/data\", timeout=10)\nresp.raise_for_status()", "key_insight": "Always pass timeout=(connect_secs, read_secs) to requests calls.", "tags": ["timeout", "networking"], "id": 138} | |
| {"language": "python", "library": "redis", "error_type": "pipeline_missing", "error_message": "Slow: 100 SET calls in a for loop", "broken_code": "r = redis.Redis()\nfor key, value in data.items():\n r.set(key, value)", "explanation": "Each set() call is a round trip. Use a pipeline to batch commands.", "fixed_code": "r = redis.Redis()\nwith r.pipeline() as pipe:\n for key, value in data.items():\n pipe.set(key, value)\n pipe.execute()", "key_insight": "Use redis Pipeline to batch multiple commands in one round trip for orders-of-magnitude speedup.", "tags": ["redis", "pipeline", "performance"], "id": 139} | |
| {"language": "python", "library": "requests", "error_type": "timeout_missing", "error_message": "requests.exceptions.ReadTimeout: HTTPSConnectionPool: Read timed out.", "broken_code": "resp = requests.get(\"https://api.sendgrid.com/v3/mail/send\")", "explanation": "No timeout set on call to sendgrid endpoint. Slow or down servers block indefinitely.", "fixed_code": "resp = requests.get(\"https://api.sendgrid.com/v3/mail/send\", timeout=5)\nresp.raise_for_status()", "key_insight": "Always set a timeout on requests to external APIs; the default is None (wait forever).", "tags": ["timeout", "requests", "sendgrid"], "id": 140} | |
| {"language": "java", "library": "okhttp", "error_type": "json_post_no_media_type", "error_message": "415 Unsupported Media Type", "broken_code": "RequestBody body = RequestBody.create(json, null);\nRequest request = new Request.Builder().url(url).post(body).build();", "explanation": "MediaType.get(\"application/json\") must be passed to declare the body type.", "fixed_code": "MediaType JSON = MediaType.get(\"application/json; charset=utf-8\");\nRequestBody body = RequestBody.create(json, JSON);\nRequest request = new Request.Builder().url(url).post(body).build();\ntry (Response response = client.newCall(request).execute()) {\n // process\n}", "key_insight": "Pass MediaType.get(\"application/json\") as first arg to RequestBody.create().", "tags": ["java", "okhttp", "json", "media-type"], "id": 141} | |
| {"language": "python", "library": "requests", "error_type": "timeout_missing", "error_message": "requests.exceptions.ReadTimeout: HTTPSConnectionPool: Read timed out.", "broken_code": "resp = requests.get(\"https://api.slack.com/api/chat.postMessage\")", "explanation": "No timeout set on call to slack endpoint. Slow or down servers block indefinitely.", "fixed_code": "resp = requests.get(\"https://api.slack.com/api/chat.postMessage\", timeout=30)\nresp.raise_for_status()", "key_insight": "Always set a timeout on requests to external APIs; the default is None (wait forever).", "tags": ["timeout", "requests", "slack"], "id": 142} | |
| {"language": "javascript", "library": "fetch", "error_type": "no_error_check", "error_message": "Silently receives 4xx/5xx without throwing", "broken_code": "const resp = await fetch(\"https://api.mapbox.com/geocoding/v5/mapbox.places/\");\nconst data = await resp.json();", "explanation": "fetch() resolves even on HTTP errors from mapbox. Status must be checked manually.", "fixed_code": "const resp = await fetch(\"https://api.mapbox.com/geocoding/v5/mapbox.places/\");\nif (!resp.ok) throw new Error(`HTTP ${resp.status} from mapbox`);\nconst data = await resp.json();", "key_insight": "fetch() only rejects on network failure; always check resp.ok for HTTP-level errors.", "tags": ["fetch", "error-handling", "mapbox"], "id": 143} | |
| {"language": "go", "library": "net/http", "error_type": "json_string_int", "error_message": "json.Unmarshal: cannot unmarshal string into Go value of type int", "broken_code": "var result struct{ Count int }\njson.Unmarshal(body, &result) // API returns {\"count\": \"42\"}", "explanation": "The API returns the field as a quoted string. Use json.Number or a custom type.", "fixed_code": "var raw struct{ Count json.Number `json:\"count\"` }\njson.Unmarshal(body, &raw)\ncount, _ := raw.Count.Int64()", "key_insight": "Use json.Number to decode fields that may arrive as either string or number.", "tags": ["go", "json", "type-mismatch"], "id": 144} | |
| {"language": "python", "library": "requests", "error_type": "auth_missing", "error_message": "401 Unauthorized", "broken_code": "resp = requests.get(\"https://api.sendgrid.com/v3/mail/send\")", "explanation": "The sendgrid API requires authentication via Authorization header.", "fixed_code": "headers = {\"Authorization\": \"Token {API_KEY}\"}\nresp = requests.get(\"https://api.sendgrid.com/v3/mail/send\", headers=headers)\nresp.raise_for_status()", "key_insight": "Attach credentials in Authorization header; requests does not add them automatically.", "tags": ["auth", "401", "sendgrid"], "id": 145} | |
| {"language": "python", "library": "requests", "error_type": "json_body", "error_message": "415 Unsupported Media Type", "broken_code": "payload = {\"key\": \"value\"}\nresp = requests.post(\"https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages\", data=payload)", "explanation": "data= sends form-encoded body to twilio. Use json= for JSON requests.", "fixed_code": "payload = {\"key\": \"value\"}\nresp = requests.post(\"https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages\", json=payload)\nresp.raise_for_status()", "key_insight": "Use json= not data= to send JSON; requests sets Content-Type automatically.", "tags": ["json", "content-type", "415", "twilio"], "id": 146} | |
| {"language": "python", "library": "requests", "error_type": "auth_missing", "error_message": "401 Unauthorized", "broken_code": "resp = requests.get(\"https://api.stripe.com/v1/charges\")", "explanation": "The stripe API requires authentication via X-API-Key header.", "fixed_code": "headers = {\"X-API-Key\": \"X-API-Key: {API_KEY}\"}\nresp = requests.get(\"https://api.stripe.com/v1/charges\", headers=headers)\nresp.raise_for_status()", "key_insight": "Attach credentials in X-API-Key header; requests does not add them automatically.", "tags": ["auth", "401", "stripe"], "id": 147} | |
| {"language": "rest", "library": "generic", "error_type": "patch_vs_put", "error_message": "PATCH replaces entire resource instead of updating one field", "broken_code": "PATCH /users/42\n{ \"email\": \"new@example.com\" }", "explanation": "The server implemented PATCH as full replace. True PATCH merges only provided fields.", "fixed_code": "GET /users/42\nPUT /users/42\n{ \"id\": 42, \"name\": \"Alice\", \"role\": \"admin\", \"email\": \"new@example.com\" }", "key_insight": "Verify whether the server implements PATCH as merge or replace; fetch first and PUT if needed.", "tags": ["rest", "patch", "put"], "id": 148} | |