{"record":{"id":"3a2d6964b2d51d67","repo":"Dolibarr/dolibarr","slug":"error-in-trigger-invoice-errorstostring","errorCode":null,"errorMessage":"Error in trigger: ${invoice->errorsToString()}","messagePattern":"Error in trigger: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"htdocs/document.php","lineNumber":437,"sourceCode":"\t\t\t\t$moreparams = '';\n\t\t\t\t$hidedetails = isset($hidedetails) ? $hidedetails : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0); // @phpstan-ignore-line as variable $hidedetails is forced\n\t\t\t\t$hidedesc = isset($hidedesc) ? $hidedesc : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0); // @phpstan-ignore-line as variable $hidedesc is forced\n\t\t\t\t$hideref = isset($hideref) ? $hideref : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0); // @phpstan-ignore-line as variable $hideref is forced\n\t\t\t\t$moreparams = isset($moreparams) ? $moreparams : null; // @phpstan-ignore-line as variable $moreparams is forced\n\n\t\t\t\t$result = $invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);\n\t\t\t\tif ($result < 0) {\n\t\t\t\t\tdol_syslog(\"Failed to regenerate PDF\", LOG_WARNING);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Call trigger\n\t\t\t$result = $invoice->call_trigger($action, $user);\n\t\t\tif ($result < 0) {\n\t\t\t\ttop_httphead();\n\n\t\t\t\thttp_response_code(500);\n\t\t\t\tprint 'Error in trigger: '.$invoice->errorsToString();\n\t\t\t\texit;\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n\n// Permissions are ok and file found, so we return it\ntop_httphead($type);\n\nheader('Content-Description: File Transfer');\nif ($encoding) {\n\theader('Content-Encoding: '.$encoding);\n}\n// Add MIME Content-Disposition from RFC 2183 (inline=automatically displayed, attachment=need user action to open)\n\nif ($attachment > 0) {","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/Dolibarr/dolibarr/blob/598aa4bdada683d17ca04b1842548821ff0eb6c6/htdocs/document.php#L419-L455","documentation":"document.php can run in 'attachment' style flows where calling a trigger on an invoice-like object fails; when $invoice->call_trigger() returns < 0 the code sends HTTP 500 and prints 'Error in trigger: <errorsToString()>'. Trigger handlers (modules implementing BILL_... triggers) signaled a failure via $object->errors.","triggerScenarios":"A trigger action (e.g. BILLSENTBYMAIL, BILL_PAYED) fired during a document.php request whose handler returns negative / fills $object->errors; typically when sending a document by email or registering a payment-like action through the download endpoint.","commonSituations":"A third-party module's trigger has a bug or missing dependency; database write inside trigger fails; trigger code not updated after a core version upgrade; trigger expects a fully loaded object that document.php's minimal stdClass context lacks.","solutions":["Read $invoice->errorsToString() output to find the failing trigger/module","Check the module's trigger code in htdocs/<module>/class/triggers_*.class.php and its logs","Fix or disable the faulty trigger module","Ensure trigger code uses $object->errors = array(...) and returns < 0 only on genuine failure","Confirm the object is fully loaded (fetch) before call_trigger in custom code"],"exampleFix":"// before (trigger)\n$result = $object->update($user); // errors not captured\n// after\n$res = $object->update($user);\nif ($res < 0) { $this->errors = $object->errors; return -1; }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"$result = $object->call_trigger($action, $user);\nif ($result < 0) {\n    http_response_code(500);\n    error_log('Trigger failed: '.implode(', ', $object->errors));\n}","preventionTips":["Capture and propagate $object->errors inside trigger implementations","Fully fetch/load objects before firing triggers in custom code","Test trigger modules after Dolibarr version upgrades","Keep third-party trigger modules updated and monitor their dependencies"],"tags":["triggers","http-500","third-party-module","dolibarr"],"backgroundTag":"api-error-response","analyzedSha":"598aa4bdada683d17ca04b1842548821ff0eb6c6","analyzedAt":"2026-09-14T11:12:15.309Z","contentChangedAt":"2026-09-14T11:12:15.309Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}