{"record":{"id":"64a97d1ac012d912","repo":"docling-project/docling","slug":"last-status-error-message-or-f-task-task-id-fai","errorCode":null,"errorMessage":"{last_status.error_message or f\"Task {task_id} failed.\"}","messagePattern":"(.+?) failed\\.\"\\}","errorType":"exception","errorClass":"TaskExecutionError","httpStatus":null,"severity":"error","filePath":"docling/service_client/client.py","lineNumber":672,"sourceCode":"            return None\n\n        now = datetime.now(tz=retry_at.tzinfo or timezone.utc)\n        return max(0.0, (retry_at - now).total_seconds())\n\n    def _raise_for_result_404(\n        self,\n        task_id: str,\n        response: httpx.Response,\n        last_status: TaskStatusResponse | None,\n    ) -> None:\n        detail = self._http_error_detail(response)\n        if detail == \"Task not found.\":\n            raise TaskNotFoundError(f\"Task {task_id} was not found.\")\n        if detail is not None and detail.startswith(\"Task result not found\"):\n            if last_status is not None and is_terminal_task_status(last_status):\n                if last_status.task_status == \"failure\":\n                    message = last_status.error_message or f\"Task {task_id} failed.\"\n                    raise TaskExecutionError(message, failure=last_status.failure)\n                raise ResultExpiredError(f\"Result for task {task_id} has expired.\")\n            raise ResultNotReadyError(f\"Result for task {task_id} is not ready.\")\n        raise ServiceError(\n            \"Unexpected result lookup error.\",\n            status_code=response.status_code,\n            detail=detail,\n        )\n\n    def _raise_if_task_failure_result(self, response: httpx.Response) -> None:\n        content_type = response.headers.get(\"content-type\", \"\")\n        if \"json\" not in content_type.lower():\n            return\n\n        try:\n            payload = response.json()\n        except ValueError:\n            return\n","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/service_client/client.py#L654-L690","documentation":"Raised as TaskExecutionError when a result lookup returned 'Task result not found', the last known status is terminal, and that status is 'failure'. The message is the error_message recorded by the service for the failed task, or the fallback 'Task {task_id} failed.' if the service stored none. The structured failure payload is attached via the 'failure' attribute (last_status.failure).","triggerScenarios":"Polling or fetching the result of a task whose last observed TaskStatusResponse has task_status == 'failure' and whose result artifact is gone (404 'Task result not found'); the conversion itself failed server-side (e.g. unsupported/corrupt input, pipeline crash, limits exceeded).","commonSituations":"Fetching results long after submission so failed-task artifacts were cleaned up, batch jobs where failures are only surfaced at result-collection time, or conversions that failed due to document-specific problems (encrypted PDF, OOM on huge files).","solutions":["Inspect the exception's 'failure' attribute (TaskFailure) for the machine-readable cause returned by the service.","Fix the document-side problem it reports: decrypt/password-protect the PDF, reduce page count via page_range, or lower max_file_size, then resubmit.","Log task_id plus failure details so recurring document failures can be triaged in bulk.","For batch pipelines, catch TaskExecutionError per item and continue rather than aborting the whole batch."],"exampleFix":"# before\nresult = job.result()  # raises TaskExecutionError with server message\n\n# after\nfrom docling.service_client.exceptions import TaskExecutionError\n\ntry:\n    result = job.result()\nexcept TaskExecutionError as exc:\n    print(\"task failed:\", exc.failure)  # structured failure payload\n    result = None","handlingStrategy":"try-catch","validationCode":"# before fetching result, check status is terminal-success\nstatus = client._poll_task_status(task_id, wait=0)  # or public status API\nif status.task_status == \"failure\":\n    handle_failure(status.error_message, status.failure)","typeGuard":null,"tryCatchPattern":"from docling.service_client.exceptions import TaskExecutionError\n\ntry:\n    result = job.result()\nexcept TaskExecutionError as exc:\n    failure = exc.failure  # structured TaskFailure or None\n    log.error(\"task failed: %s\", failure or exc)\n    mark_document_failed(source, str(exc))","preventionTips":["Pre-validate documents (open PDFs, check encryption) before submission.","Slice large documents with page_range to avoid server-side resource failures.","Process batches per-item with try/except so one failure does not kill the run.","Always read exc.failure for the machine-readable cause."],"tags":["task","failure","service-client","conversion"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}