Skip to content

Silence MuPDF warnings/errors unconditionally (fixes #132) - #148

Closed
tloriato wants to merge 2 commits into
gen2brain:masterfrom
tloriato:feat/silence-warnings
Closed

Silence MuPDF warnings/errors unconditionally (fixes #132)#148
tloriato wants to merge 2 commits into
gen2brain:masterfrom
tloriato:feat/silence-warnings

Conversation

@tloriato

@tloriato tloriato commented Apr 23, 2026

Copy link
Copy Markdown

Unconditionally silences MuPDF warning and error callbacks on every new context, suppressing stderr noise like warning: ignoring CMap range .... Errors are still surfaced via Go error returns.

Closes #132.

Changes

  • cgo (fitz_cgo.go): static no-op callback + go_fitz_silence(ctx) called in New and NewFromMemory.
  • nocgo (fitz_nocgo.go): single purego.NewCallback allocated in init(), reused for every context via applySilence.
  • All 35 tests pass, go build ./..., go vet ./... clean.

@gen2brain

Copy link
Copy Markdown
Owner

Sorry, do not have much time to spend on this. At first glance, why would a user be involved at all? Warnings should be silenced; who wants them in the output? Errors should be returned as errors. How useful would be for someone to log and collect warnings. As for purego and NewCallback, just a note that there is a limited number of callbacks one can create so it should be reused if possible.

Remove the opt-in Quiet flag — stderr callbacks are now always
suppressed. Errors continue to surface via Go error returns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tloriato tloriato changed the title Add Quiet flag to silence MuPDF warnings/errors (fixes #132) Silence MuPDF warnings/errors unconditionally (fixes #132) Apr 23, 2026
@tloriato

Copy link
Copy Markdown
Author

Hey @gen2brain! Thank you for looking, I tried to change and make as brief as possible so it doesn't take your time. What I reworked:

  • Dropped the Quiet flag — warnings and errors are now silenced unconditionally on every new context. No user involvement.
  • Errors continue to surface through Go error returns (the existing fz_try/fz_catch wrappers already handle that).
  • The purego callback is allocated once in init() and reused.
  • Removed the SetWarningFunc idea entirely.

Net result is -35 / +9 lines vs the previous revision. All 35 tests pass.

@gen2brain

Copy link
Copy Markdown
Owner

Warnings are silenced in d009362 . Closing this one.

@gen2brain gen2brain closed this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suppressing the warnings from MuPDF

2 participants