dolibarr/htdocs/includes
nikube d5f773158e
FIX TCPDI: honor K_TCPDF_THROW_EXCEPTION_ERROR and enable exceptions by default (#37827)
* FIX tcpdi_parser::Error() respects K_TCPDF_THROW_EXCEPTION_ERROR

tcpdi_parser::Error() called die() unconditionally, producing white
pages on PDF import failures (corrupted background, missing template)
and killing batch generation on the first bad PDF.

TCPDF already supports exception mode via K_TCPDF_THROW_EXCEPTION_ERROR,
and Dolibarr already exposes TCPDF_THROW_ERRORS_INSTEAD_OF_DIE to
control it (core/lib/pdf.lib.php). TCPDI, derived from TCPDF, never
honored it.

Changes:
- tcpdi_parser::Error(): throw \Exception when
  K_TCPDF_THROW_EXCEPTION_ERROR is defined and true, otherwise die()
  as before.
- commonGenerateDocument(): wrap write_file() calls in try/catch to
  catch exceptions from TCPDI (and any other throwable), set
  \$resultwritefile = -1 and preserve the exception message in
  \$this->error.
- commonGenerateDocument(): guard error-path assignment so an already
  set \$this->error (from the catch block) is not overwritten by an
  empty \$obj->error.

100% backward compatible: without the constant set, behavior is
unchanged.

Assisted by Claude, maybe it needs a human verification ;)

Signed-off-by: nikube <n.zaoui@outlook.com>

* FIX Enable TCPDF/TCPDI exception mode by default

Now that tcpdi_parser::Error() honors K_TCPDF_THROW_EXCEPTION_ERROR and
commonGenerateDocument() catches write_file() exceptions, flip the
default of TCPDF_THROW_ERRORS_INSTEAD_OF_DIE from 0 to 1.

Rationale: die() in a PDF library has no legitimate production use
case. It produces white pages on web requests (user gets no message,
no way to recover) and kills batch PDF generation on the first bad
PDF. Exceptions can be caught, logged, and surfaced as normal Dolibarr
error banners.

Users who need the legacy die() behavior can opt out by setting
TCPDF_THROW_ERRORS_INSTEAD_OF_DIE = 0.

Assisted by Claude, maybe it needs a human verification ;)

Signed-off-by: nikube <n.zaoui@outlook.com>

---------

Signed-off-by: nikube <n.zaoui@outlook.com>
2026-04-11 18:01:59 +02:00
..
ace Clean files 2026-01-07 19:01:54 +01:00
ckeditor WIP mail layout 2025-04-17 00:27:52 +02:00
fonts Clean files 2026-01-07 19:01:54 +01:00
geoip2
geoPHP
jquery Clean files 2026-01-07 19:01:54 +01:00
jsgantt Clean files 2026-01-07 19:01:54 +01:00
leaflet
markrogoyski/math-php Clean files 2026-01-07 19:01:54 +01:00
maximebf/debugbar Clean files 2026-01-07 19:01:54 +01:00
mike42/escpos-php Clean files 2026-01-07 19:01:54 +01:00
mobiledetect/mobiledetectlib FIX #36902 2026-01-19 13:36:48 +01:00
nnnick/chartjs/dist
nusoap/lib Clean files 2026-01-07 19:01:54 +01:00
OAuth Fix data saved with generic oauth 2026-02-25 22:46:27 +01:00
odtphp Replace var_export by formatLogObject (continued) (#37188) 2026-02-10 16:54:51 +01:00
parsedown
php-iban Clean files 2026-01-07 19:01:54 +01:00
phpoffice/phpspreadsheet Clean files 2026-01-07 19:01:54 +01:00
printipp Clean files 2026-01-07 19:01:54 +01:00
Psr Clean files 2026-01-07 19:01:54 +01:00
restler/framework/Luracast/Restler Clean files 2026-01-07 19:01:54 +01:00
sabre Clean files 2026-01-07 19:01:54 +01:00
stripe/stripe-php Clean files 2026-01-07 19:01:54 +01:00
swiftmailer Clean files 2026-01-07 19:01:54 +01:00
symfony/var-dumper Clean files 2026-01-07 19:01:54 +01:00
tcpdi FIX TCPDI: honor K_TCPDF_THROW_EXCEPTION_ERROR and enable exceptions by default (#37827) 2026-04-11 18:01:59 +02:00
tecnickcom/tcpdf Clean files 2026-01-07 19:01:54 +01:00
webklex/php-imap Clean files 2026-01-07 19:01:54 +01:00
.gitignore
.htaccess