-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
emitting multi-line messages from build scripts #13233
Comments
I also have concerns with It at least looks like this could be possible with a little I should probably note that my first inclination when seeing I previously posted this in the other thread, for which I've moved it here. |
This is one of the topics that needs to be worked out is how multi-line messages are rendered. For example, if cargo emits "error", etc, should there be an expectation that users be able to align later lines with the first, requiring Cargo to guarantee the column count used. That along with all the semantics for how to handle edge cases. Id have to look up our meeting notes to see if there was anything else. |
imo that isn't raw string literal syntax because its on the left hand of the assignment and being too close but not quite the same will likely lead to errors. We also likely don't want to support it after the assignment because that would change the interpretation of existing values. |
Yeah, I definitely prefer something like the basic idea is these would look like: Edit: The following snippet is a bad idea.
So it is enough to just take a string and With this we know if it's I'm happy to drop the comparison to raw string literals. |
Personally, I always like to have a form of escaping for that "just in case" situation where a delimiter needs to be included. The approach of raw string literals and markdown code fences of "do something more" to escape works well. |
An alternative that would allow us to avoid escaping Because, to be honest I don't really see the need for escaping though. The only thing that could possibly need escaping is Edit:
|
This comment was marked as resolved.
This comment was marked as resolved.
That concern is not to clear to me. The build will fail, whether we use |
Yes, I totally misread that statement I quoted, as "Treat the script as having errored if it returns an error code." which was the behavior I believe was originally implemented for compatibility. |
I'm not a fan of I've worked on design and multiple implementations of the HTML5 println!("cargo:error={}", err.to_string().replace("\n", "\ncargo:<some continuation syntax>=")); This design makes escaping mandatory and easy to get right. An HTTP/1 headers have a similar continuation syntax (a line starting with a tab appends to previous line). An orphaned |
My problem with this is that an orphaned I feel less strongly about the need for an end marker, but it makes enforcing balance easier,
|
This seems to be a very rare edge case, and I don't understand why this should be an issue worth designing against.
So overall the problem you're trying to address seems completely benign, very unlikely to happen, and is just a small UI formatting issue at worst. And remember the current status quo is a hard-to-read dump of all stdout and stderr without any structure. Even incorrectly run-on error line continuations are an improvement over the current unformatted state of the output. Please don't let perfect be the enemy of the good. |
My feeling is that when faced with a pile of errors, the last thing one wants to be doing is debugging the error handling code in an external project... so it is a good idea to sus these issues out beforehand so if we can find a tolerable way to avoid these quirks before they land we should. Having a staring contest over this feature hasn't appeared to actually be getting us actually closer to landing anything, and I would like to see this feature happen. |
In practice build scripts don't emit piles of errors. They typically panic, once. |
Not necessarily when your build.rs is calling into a library which are parsing many files. So in practice typically that is the case, but not always and there are plenty of examples where it is not. |
I don't think there's a risk of FWIW, I originally proposed, and still prefer, that the status code of the build script should be the only way to fail the build. Cargo should flag printing of errors and returning a success code from the build as a programmer mistake (and downgrade these faux-errors to warnings or hide them and warn that the script is buggy). Anyway, if a good scenario looked like this:
then the absolutely worst case of everyone always using
So I don't understand why this one particular minor issue deserves the focus. This is such a small detail, that even a contrived worst-case scenario is quite good! There are infinitely many ways to print a directive wrong, and this is a fundamental flaw of Cargo's print-based API. A sloppy programmer could print If this is really showstopping concern, then syntax variations can't do much about it. The whole interface of build scripts would be better replaced with a proper Rust one, e.g.: extern crate cargo_build;
fn main() {
cargo_build::abort(r"many
lines
and
checked
syntax!
");
} |
The lists of errors in my case are coming from 3 different libraries. So there should be 3 error codes. What I would like to focus on is whether authors of crates should have any say in whether others can append to a crates error message. I agree, the output you list is good, because my errors though already contain an I think the actual worse case scenario is probably more something like:
As fun as that sounds, I'd rather not see us go that way. |
If user prints `start`, but no `end` (e.g. due to last line not ending with a newline, or due to a panic when `unwrap()`ing some `println!` arguments, or a syntax error in the end directive), then the parser will be stuck in the error-text-capturing state, eating arbitrary other output. That may be a ton of unhelpful output from spawned `Command`s. If another error is printed after the unclosed one, then it will capture the first error and everything in between, potentially other `cargo:` directives too. A continuation syntax can't break so catastrophically, because every line opts in to being included.
A basic
Currently cargo directives can be parsed with a simple stateless 1-liner like Regarding presentation of |
If there is an unterminated end marker, then cargo can warn at the end when it sees that there is an unterminated because the current continuation is I don't think it should handle nesting, so it should if the current continuation is
I don't see it being super fiddly, just a few cases and a catchall, and one check at the end to see if there was an error left unconsumed... If cargo warns about these cases they can be caught by developers. While in the I think we have probably been talking past one another this whole time, because I think the If for whatever reason this becomes untenable, cargo can just completely ignore |
An empty line can act as a terminator for the continuation syntax. That follows naturally from the fact that continuation lines have to follow a line they can continue, so any other line will work, and an empty line is the simplest case. |
I would tend towards preferring a directive, but it isn't a big deal to me whatever is settled upon. |
I'm not confident I understand exactly what you mean anymore, could you give an example? |
Your worry is that printing wild
and it would be prevented by requiring a terminator:
I suggest that any non-continuation line, including an empty line, can be the terminator, like so:
This is enough to detect that the second error is an invalid syntax (it's not immediately after an error directive), without introducing any special syntax for the terminator itself. It also looks fine when reading the raw log (when debugging the build script or getting verbose dump). Any line will work, this too:
or this
and because any irrelevant line works as a terminator, then it's literally impossible to get it wrong and end up with an unterminated state, e.g.
In this case the typo in the terminator generated a message like:
|
I guess my only concern with bare newlines as terminator is just that it is likely to be output by something random, and completely unrelated to the error potentially allowing an unterminated error to be accepted. However it does make the raw log look nice. I.e. in the final check
It seems very likely that this check could become irrelevant because of any random newline. So I would tend towards explicit personally, but I don't want to be difficult so if that is the thing so be it? |
I've re-read the discussion, and think the points still stand, so this issue needs an executive decision to pick one way or another. (I'm not impartial in this discussion, so I don't think I can make a fair summary) |
First, it would be good to provide a summary of each option for easy comparison, rather than trying to piece together the "final states" from the thread. Second, syntax is only one problem to be solved. I've not gone back to the meeting notes but I've added to the Issue several design points that are of concern. |
Some solution is really needed, including I've tried improving output of openssl-sys build script, but the current formatting of Having
openssl-sys has these things to output:
If it was something more like rustc errors, I presume it'd be formatted like:
|
Problem
#10159 discusses and #11312 has an implementation of
cargo::error=
andcargo::error+=
for build scripts,This breaks out the discussion of
cargo::error+=
from these as this aspect needs more design discussion.Questions
+=
without a=
or directives between=
and+=
, begin without end or double begins, etc)warning
(and presumableerror
) has a built-in prefix. If we don't include that here, then it would be inconsistent and users might forget. If we do include it, users might have problems aligning the first line with the second if they want.Proposed Solution
No response
Notes
No response
The text was updated successfully, but these errors were encountered: