Handling errors

View Source

PDF operations and HTML rendering return explainable failures as:

{:error, {reason, diagnostic}}

Use reason to decide what your application does next. Use diagnostic.message to explain or log the failure.

require Logger

case NativeElixirPdfUtilities.Text.extract_file("report.pdf") do
  {:ok, text} ->
    text

  {:error, {reason, diagnostic}} ->
    Logger.warning("PDF operation failed: #{reason}: #{diagnostic.message}")
    {:error, reason}
end

Understanding the diagnostic

FieldMeaningAlways present?
:reasonThe same reason atom as the outer tupleYes
:messageA description of the problemYes
:stageWhere processing stoppedYes
:operation, :moduleThe operation and module reporting itNo
:sourceA relevant path or input snippetNo
:line, :columnA position in the source inputNo

Read optional fields with Map.get/2. Messages may change between releases; match reason atoms rather than message text. Operation labels may differ from function names, such as :stamp_text or a file action named :read.

Common failures

ReasonWhat to check
:invalid_optionsOption names, types, and accepted values in the task guide
:invalid_html, :unsupported_html, :invalid_cssThe source location andsupported HTML/CSS
:invalid_pdf_inputWhether the input is a complete, readable PDF
:encrypted_pdfSupply an unencrypted PDF; decryption is not supported
:unsupported_pdf_feature, :unsupported_text_encodingThe relevant operation's supported inputs
:resource_limit_exceededDocument size/complexity and yourconfigured limits