{"record":{"id":"0376b11a36693d73","repo":"mozilla/pdf.js","slug":"no-response-from-the-ai-service","errorCode":null,"errorMessage":"No response from the AI service.","messagePattern":"No response from the AI service\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/editor/stamp.js","lineNumber":183,"sourceCode":"      throw new Error(\"No ML.\");\n    }\n    if (!(await mlManager.isEnabledFor(\"altText\"))) {\n      throw new Error(\"ML isn't enabled for alt text.\");\n    }\n    const { data, width, height } =\n      imageData ||\n      this.copyCanvas(null, null, /* createImageData = */ true).imageData;\n    const response = await mlManager.guess({\n      name: \"altText\",\n      request: {\n        data,\n        width,\n        height,\n        channels: data.length / (width * height),\n      },\n    });\n    if (!response) {\n      throw new Error(\"No response from the AI service.\");\n    }\n    if (response.error) {\n      throw new Error(\"Error from the AI service.\");\n    }\n    if (response.cancel) {\n      return null;\n    }\n    if (!response.output) {\n      throw new Error(\"No valid response from the AI service.\");\n    }\n    const altText = response.output;\n    await this.setGuessedAltText(altText);\n    if (updateAltTextData && !this.hasAltTextData()) {\n      this.altTextData = { alt: altText, decorative: false };\n    }\n    return altText;\n  }\n","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/editor/stamp.js#L165-L201","documentation":"Thrown by StampEditor.mlGuessAltText after awaiting mlManager.guess() for the 'altText' model. It fires only when the guess() promise resolves to a falsy value (null/undefined) rather than a response object. The library treats a completely absent payload as a hard failure of the ML-backed alt-text feature, distinct from a service error or an empty result.","triggerScenarios":"mlGuessAltText() is called (hasAltTextData() is false, mlManager exists, mlManager.isEnabledFor('altText') is true), mlManager.guess({ name:'altText', request:{data,width,height,channels} }) resolves to null or undefined.","commonSituations":"The host application wires a stub mlManager whose guess() returns nothing; the AI backend is unreachable and the wrapper resolves empty instead of rejecting; a version mismatch between the viewer and the ML backend returns no body; the ML feature is half-enabled (enabled flag true but no real backend).","solutions":["Confirm a real mlManager is registered and that isEnabledFor('altText') reflects an actually reachable backend.","Wrap mlGuessAltText() / guess-based flows in try/catch and degrade to the manual alt-text dialog.","Inspect the mlManager.guess implementation to ensure it rejects on network failure rather than resolving undefined.","Check the host environment's telemetry/network logs for the altText request that produced the empty result."],"exampleFix":"// before\nconst alt = await editor.mlGuessAltText();\n// after\ntry {\n  const alt = await editor.mlGuessAltText();\n} catch (e) {\n  console.warn('Alt-text guess unavailable:', e.message);\n  // fall back to the manual alt-text entry dialog\n}","handlingStrategy":"try-catch","validationCode":"const { mlManager } = editor._uiManager;\nif (!mlManager || !(await mlManager.isEnabledFor('altText'))) {\n  // skip ML guess entirely; open the manual alt-text dialog instead\n}","typeGuard":"function hasAltTextGuessSupport(editor) {\n  const { mlManager } = editor._uiManager ?? {};\n  return !!mlManager && typeof mlManager.guess === 'function' && typeof mlManager.isEnabledFor === 'function';\n}","tryCatchPattern":"try {\n  const alt = await editor.mlGuessAltText();\n} catch (e) {\n  // 'No response from the AI service.' -> backend absent/unreachable\n  openAltTextDialog(editor);\n}","preventionTips":["Register a real mlManager only when the AI backend is reachable; otherwise leave it unset.","Gate mlGuessAltText behind isEnabledFor('altText') checks.","Ensure your mlManager.guess rejects on failure rather than resolving undefined.","Treat ML alt-text as an enhancement that can fail; always keep the manual dialog as fallback."],"tags":["ai","alt-text","ml-manager","async"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}