mozilla/pdf.js · error · Error
Error from the AI service.
Error message
Error from the AI service.
What it means
Thrown by StampEditor.mlGuessAltText when the 'altText' guess response carries a truthy `error` field. Unlike the no-response case, the ML service did reply, but the payload signals a backend-side failure (model error, bad input, rate limit, etc.). The library surfaces this as a distinct, non-recoverable error for that guess attempt.
Source
Thrown at src/display/editor/stamp.js:186
throw new Error("ML isn't enabled for alt text.");
}
const { data, width, height } =
imageData ||
this.copyCanvas(null, null, /* createImageData = */ true).imageData;
const response = await mlManager.guess({
name: "altText",
request: {
data,
width,
height,
channels: data.length / (width * height),
},
});
if (!response) {
throw new Error("No response from the AI service.");
}
if (response.error) {
throw new Error("Error from the AI service.");
}
if (response.cancel) {
return null;
}
if (!response.output) {
throw new Error("No valid response from the AI service.");
}
const altText = response.output;
await this.setGuessedAltText(altText);
if (updateAltTextData && !this.hasAltTextData()) {
this.altTextData = { alt: altText, decorative: false };
}
return altText;
}
#getBitmap() {
if (this.#bitmapId) {
this._uiManager.enableWaiting(true);View on GitHub (pinned to 5903d58d58)
Solutions
- Inspect response.error from your mlManager to identify the backend-reported cause.
- Verify the imageData passed in has consistent width, height, and channels (data.length === width*height*channels).
- Retry the guess after a short delay if the backend error is transient.
- Catch the error and fall back to the manual alt-text dialog so the editor stays usable.
Example fix
// before
const alt = await editor.mlGuessAltText();
// after
try {
const alt = await editor.mlGuessAltText();
} catch (e) {
if (e.message === 'Error from the AI service.') {
// log backend cause and fall back
}
} Defensive patterns
Strategy: try-catch
Validate before calling
if (imageData.width <= 0 || imageData.height <= 0 || imageData.data.length === 0) {
// do not call mlGuessAltText with bad image data
} Type guard
function isValidImageDataForGuess({ data, width, height }) {
return width > 0 && height > 0 && data.length === width * height * (data.length / (width * height));
} Try / catch
try {
const alt = await editor.mlGuessAltText();
} catch (e) {
if (e.message.startsWith('Error from the AI service.')) {
// log and fall back to manual entry
}
} Prevention
- Validate image data dimensions/length are consistent before guessing.
- Inspect mlManager.guess response.error to find the backend cause.
- Retry transient backend errors with backoff before giving up.
- Keep the manual alt-text dialog as the persistent fallback.
When it happens
Trigger: mlManager.guess({ name:'altText', request:{data,width,height,channels} }) resolves to an object whose `error` property is truthy (e.g. { error: 'model timeout' }).
Common situations: The image data payload is malformed or too large; the deployed alt-text model rejects the input; the backend is rate-limiting or temporarily failing; channels (data.length/(width*height)) computes to an unexpected value due to a zero-size canvas.
Related errors
- No response from the AI service.
- No valid response from the AI service.
- No ML.
- ML isn't enabled for alt text.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/b654a80ab473b866.
Report an issue: GitHub.