tectonic
tectonic copied to clipboard
Option to make warnings fatal
Related to issue #577, I would really like tectonic to give me the option to make warnings fatal.
This should be a good starter contribution for someone — I think it should just be a small logic addition in src/bin/tectonic.rs.
I've had a look at adding this option via a command line argument, and everything is looking ok, except for the fact that I don't seem to be able to capture the issues that TeX emits! e.g. I made a TeX document for the purpose of it being wrong, where I \ref{}'d a \label{} that doesn't exist. If -X build -p is used I get warnings from TeX in stdout, but none being propagated into the Rust layer.
In LLDB I had a peek at the bit of the FFI wrapping that I think is supposed to convert C's error codes into the TexResult enum and saw the following:
let r = unsafe {
super::tex_simple_main(
//--snip--
)
};
match r { // <------------------- R stays 0 even when warnings are being put to stdout
0 => Ok(TexResult::Spotless),
1 => Ok(TexResult::Warnings),
2 => Ok(TexResult::Errors),
3 => Err(EngineAbortedError::new_abort_indicator().into()),
x => Err(anyhow!("internal error: unexpected 'history' value {}", x)),
Given that because of this, afaik I can't get a value about what errors have occurred, I have three options:
- Be completely wrong about this implementation and there's some other error state that could be used,
- See if I can find something that should be propagating those errors in the C layer,
- Somehow grep stdout for the word Warning and panic if it gets emitted (which seems silly)
@akkuankka Apologies for the extremely slow follow-up here. I think the issue is that some warnings are issued through the core TeX engine, currently using the ttbc_diag_begin_warning function, but other warnings are created and issued entirely TeX-side, and don't trigger the Tectonic callbacks or change the return value.
One point is that it would be totally reasonable to start with just handling those engine-level warnings.
What I've envisioned to handle all kinds of warnings is that we patch the core LaTeX files to call some custom hooks to expose purely TeX-side warnings (e.g. \@latex@warning) to Tectonic, so that they can be handled uniformly. A new Tectonic-specific builting would need to be added, and we'd need to add some infrastructure to patch some of the files when generating the bundle, but my hope is that this would really only require a few small interventions, since LaTeX provides low-level routines for emitting warnings.
Alternatively, I think it might not actually be that unreasonable to try grepping the engine output for warning: and similar text ... but you can imagine that if a document contains the word "warning", there might be corner-case failures that would be hard to avoid.