-
Notifications
You must be signed in to change notification settings - Fork 359
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
Harden curl output parsing #5984
Conversation
fdfa01e
to
b02478b
Compare
9728872
to
53ff088
Compare
src/repository/opamDownload.ml
Outdated
let num = try int_of_string code with Failure _ -> 999 in | ||
if num >= 400 then | ||
fail (Some ("curl error code " ^ code), | ||
Printf.sprintf "curl: code %s while downloading %s" | ||
code (OpamUrl.to_string url)) | ||
else Done () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let num = try int_of_string code with Failure _ -> 999 in | |
if num >= 400 then | |
fail (Some ("curl error code " ^ code), | |
Printf.sprintf "curl: code %s while downloading %s" | |
code (OpamUrl.to_string url)) | |
else Done () | |
try | |
if int_of_string code >= 400 then | |
fail (Some ("curl error code " ^ code), | |
Printf.sprintf "curl: code %s while downloading %s" | |
code (OpamUrl.to_string url)) | |
else Done () | |
with Failure _ -> | |
fail (Some "No error code", | |
Printf.sprintf "curl: no error code while downloading %s" | |
(OpamUrl.to_string url)) |
Like that we give the 'no code' information instead of an unknown 999 code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah - I debated whether the 999 thing should remain as well, so the fact you also thought it suggests it really ought to go!
I pushed an extra commit, but switching it to have fewer try
blocks (not necessarily elegantly, though). It also removes the separation of "no output" from "no code parsed", which I think is also fine, as we don't really care about the distinction.
701b8f4
to
fd1842b
Compare
fd1842b
to
a9ca990
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
The cURL project has maintained a beautiful changelog!
… cmd_stdout is given
a9ca990
to
1e1fbb5
Compare
Thanks! |
Issue originally reported on Discuss.
The OP was using a native Windows
curl.exe
from Git-for-Windows git-bash (MSYS2 has curl both for its "Cygwin" main install, but also compiled natively - git-bash installs the mingw64 native-compiled version). This yields an exception duringopam init
while attempting to setup the internal Cygwin installation:Note that there is no code. Running the command manually, everything appears to be OK, but if the output is piped to a file, the issue becomes apparent (the various
\r
effects removed):There is a blank line at the end of the file and the 200 is at the end of the penultimate line. There appears to be an issue with interleaving stderr and stdout when the output is being piped. At this point I could wave my hands and spout Posix, line-buffering and all sorts of explanations, but this PR is a somewhat simpler approach - the status code now has a newline printed before and after it and the parser attempts to convert the first non-blank line from the end of the output to an integer.
I was tempted to add
--no-progress-meter
, but it turns out that's too recent an option. I'm wondering why--silent
has never been added (same for the others), but perhaps that's because if something goes wrong, the display might be useful. We could add--silent --show-error
which would add errors only to the log files (--silent
is there since the dawn of time, and--show-error
was added in 5.9 on 22-May-1999).