Skip to content

Capture warnings into diagnostic objects #625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 22, 2020

Conversation

ralismark
Copy link
Contributor

This is meant to resolve #577. The general design of this is have each warning/error be reported via a Diagnostic object (diagnostic_t on the C side) -- doing this will allow extra information to be added later (e.g. location of error). I've also added a sort of hack in xetex-output.c to be able to capture print messages into a diagnostic. The main thing left now is to wrap all the places where warnings/errors are emitted with

diagnostic_t warning = ttstub_warn_begin(); // or ttstub_error_begin()
capture_to_diagnostic(warning);

and

capture_to_diagnostic(0);
ttstub_diag_finish(warning);

@pkgw
Copy link
Collaborator

pkgw commented Aug 6, 2020

I really like the look of this! I think you're right that it will be helpful to use a small structure to allow for the capture of line-number information. (The line-numbering option is turned on in Tectonic by default, but I have to admit that I feel like I can never understand what it reports anyway.)

@pkgw
Copy link
Collaborator

pkgw commented Aug 6, 2020

The current Travis failure is due to formatting — our CI requires that cargo fmt and cargo clippy both be satisfied. Something to keep an eye out for before updating the branch.

(I'm not sure why Azure hasn't run — maybe it doesn't run for draft PRs? Or sometimes there's just a hiccup in the system.)

@codecov
Copy link

codecov bot commented Aug 9, 2020

Codecov Report

Merging #625 into master will increase coverage by 0.05%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #625      +/-   ##
==========================================
+ Coverage   46.07%   46.13%   +0.05%     
==========================================
  Files         138      138              
  Lines       59884    59956      +72     
==========================================
+ Hits        27592    27660      +68     
- Misses      32292    32296       +4     
Impacted Files Coverage Δ
tectonic/xetex-xetexd.h 66.66% <ø> (ø)
tectonic/xetex-output.c 82.19% <88.88%> (+0.69%) ⬆️
tectonic/xetex-xetex0.c 78.47% <93.33%> (+0.01%) ⬆️
src/engines/mod.rs 66.74% <100.00%> (+1.67%) ⬆️
tectonic/core-bridge.c 82.60% <100.00%> (+2.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11c5ac3...8f9111e. Read the comment docs.

Copy link
Collaborator

@pkgw pkgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This continues to look very nice! Here are a few things I've noticed.

@pkgw
Copy link
Collaborator

pkgw commented Aug 12, 2020

For some reason, codecov seems to be stuck, but CI is looking green otherwise. Is this ready for review?

@ralismark
Copy link
Contributor Author

I've only added the diagnostics to a portion of the places where warnings or errors get emitted - and there's quite a lot of these. Should I do that in this PR or separate those into a new one? Either way I'll clean up the commits before mark this as ready for review.

@pkgw
Copy link
Collaborator

pkgw commented Aug 14, 2020

@ralismark I think it makes sense to have this PR work on the foundation without trying to cover every single message in the codebase. If nothing else, that leaves some nice low-hanging-fruit tasks for new contributors.

ralismark added 7 commits August 16, 2020 19:44
The idea is that a Diagnostic is essentially a "builder" for a
warning/error - we apply changes to it (e.g. adding strings) and
eventually output it with diag_finish.

Doing it this way allows us to add more information to warnings later,
such as the filename & line number. Having individual diagnostic_t
objects instead of a global warning allows multiple warnings to be
constructed simultaneously (e.g. across multiple functions).
This allows functions to "tee" printed output into warnings. This makes
it easier to support this new warning style.
@ralismark ralismark marked this pull request as ready for review August 16, 2020 10:40
@ralismark ralismark changed the title [WIP] Capture warnings into diagnostic objects Capture warnings into diagnostic objects Aug 16, 2020
@ralismark
Copy link
Contributor Author

This PR should be ready for review & merging now.

@pkgw pkgw self-assigned this Aug 21, 2020
pkgw added 5 commits August 22, 2020 10:42
Centralize the code that prints the file/line information and take more
advantage of the `current_diagnostic` state -- automatically calling
`ttstub_diag_finish()` when stopping a capture, and having the helper
functions call `capture_to_diagnostic()` automatically.
Oops -- need to do this to tidy up Cargo.lock changes.
@pkgw
Copy link
Collaborator

pkgw commented Aug 22, 2020

Thanks, this is fantastic!

I've pushed a few changes to tidy up the API a little bit. Now, the warning messages captured into Tectonic will include file and line information unconditionally. I've also wired up the error reporting code in insert_dollar_sign to give an easy way to test that codepath -- just put something like Free text math_oops in a sample document.

Presuming those all work, I'll merge this. (Looks like the "semistatic" macOS build is failing due to vcpkg, yet again.)

Namely, install pkg-config with brew. We didn't need to do this
before, so maybe this error reflects a transient vcpkg issue,
but it's easy enough to work around. (Hopefully.)
@pkgw pkgw merged commit fe62a31 into tectonic-typesetting:master Aug 22, 2020
@ralismark ralismark deleted the warn-type branch April 14, 2021 12:06
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.

Capture and report warning text instead of simply saying that warnings were issued
2 participants