{"record":{"id":"2dcc91a99bf71bd7","repo":"AykutSarac/jsoncrack.com","slug":"unable-to-process-the-request","errorCode":null,"errorMessage":"Unable to process the request.","messagePattern":"Unable to process the request\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/www/src/hooks/useJsonQuery.ts","lineNumber":23,"sourceCode":"const useJsonQuery = () => {\n  const getJson = useJson(state => state.getJson);\n  const setContents = useFile(state => state.setContents);\n\n  const transformer = async ({ value }) => {\n    const { run } = await import(\"json_typegen_wasm\");\n    return run(\"Root\", value, JSON.stringify({ output_mode: \"typescript/typealias\" }));\n  };\n\n  const updateJson = async (query: string, cb?: () => void) => {\n    try {\n      const jq = await import(\"jq-web\");\n      const res = await jq.promised.json(JSON.parse(getJson()), query);\n\n      setContents({ contents: JSON.stringify(res, null, 2) });\n      cb?.();\n    } catch (error) {\n      console.error(error);\n      toast.error(\"Unable to process the request.\");\n    }\n  };\n\n  const getJsonType = async () => {\n    const types = await transformer({ value: getJson() });\n    return types;\n  };\n\n  return { updateJson, getJsonType };\n};\n\nexport default useJsonQuery;\n","sourceCodeStart":5,"sourceCodeEnd":36,"githubUrl":"https://github.com/AykutSarac/jsoncrack.com/blob/3c9af69e23c635356293b6b28cf4cd0af10d1059/apps/www/src/hooks/useJsonQuery.ts#L5-L36","documentation":"Toast from useJsonQuery.updateJson when the jq-web pipeline fails. The function dynamically imports jq-web, calls JSON.parse(getJson()) then jq.promised.json(parsed, query). Any failure — module/WASM load error, invalid JSON input, or an invalid jq query — is caught and reported as 'Unable to process the request.' console.error(error) logs the real cause.","triggerScenarios":"Typing an invalid jq expression (e.g. `.foo |`, `.[`, unknown functions); running jq against editor content that is not valid JSON (JSON.parse throws); jq-web WASM failing to load/instantiate (missing .wasm asset, CSP blocking wasm, memory).","commonSituations":"User learning jq syntax; CDN/bundler misconfiguration dropping jq-web's .wasm file; Content-Security-Policy without wasm-src; running jq on a large payload exceeding the WASM heap.","solutions":["Validate the editor JSON parses before running jq (pre-check with JSON.parse).","Verify jq-web's WASM asset is served correctly (check Network tab for a 200 on the .wasm).","Allow 'wasm-src' / 'script-src' in CSP if the WASM fails to compile.","Surface the real error message (jq-web often returns a parse error with position) instead of the generic text."],"exampleFix":"// before\n} catch (error) {\n  console.error(error);\n  toast.error(\"Unable to process the request.\");\n}\n\n// after — distinguish parse, jq-syntax, and load failures\n} catch (error) {\n  console.error(error);\n  const msg = error instanceof SyntaxError && /JSON/.test(error.message)\n    ? \"Editor content is not valid JSON.\"\n    : (error?.message?.includes(\"compile\") || error?.message?.includes(\"wasm\"))\n      ? \"jq engine failed to load.\"\n      : \"Invalid jq query or unable to process.\";\n  toast.error(msg);\n}","handlingStrategy":"validation","validationCode":"// Validate JSON parses before invoking jq\nexport function isParsableJson(text: string): boolean {\n  try { JSON.parse(text); return true; } catch { return false; }\n}","typeGuard":"// Detect jq-web module-load/WASM failures\nexport function isJqLoadError(error: unknown): boolean {\n  const msg = error instanceof Error ? error.message : String(error);\n  return /wasm|compile|instantiate|import/i.test(msg);\n}","tryCatchPattern":"// Distinguish parse, load, and query errors\nif (!isParsableJson(getJson())) { toast.error(\"Editor content is not valid JSON.\"); return; }\ntry { const res = await jq.promised.json(JSON.parse(getJson()), query); /* ... */ }\ncatch (error) {\n  console.error(error);\n  toast.error(isJqLoadError(error) ? \"jq engine failed to load.\" : \"Invalid jq query.\");\n}","preventionTips":["Ensure jq-web's .wasm asset is served and CSP allows wasm-src.","Validate editor JSON before running jq.","Surface the real jq error (often includes position) instead of a generic message."],"tags":["jq","wasm","json","query","csp"],"backgroundTag":null,"analyzedSha":"3c9af69e23c635356293b6b28cf4cd0af10d1059","analyzedAt":"2026-08-12T19:00:27.891Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}