Re: [PATCH 1/2] sha1_name: don't trigger detailed diagnosis for file arguments
From: Matthieu Moy <hidden>
Date: 2016-06-15 22:54:07
Junio C Hamano [off-list ref] writes:
I am not so sure about that. The "only-to-die" caller is not even
expecting that the call to this codepath would successfully return.
Or at least, it shouldn't.
So it might not be a bad idea to actually catch this as a
programming error and do
if (only_to_die) {
if (!ret)
die("BUG");
diagnose_invalid_sha1_path(...);
}
I disagree.
The only-to-die caller can expect that get_sha1_with_context_1 never
returns when called with only-to-die, but it's a stronger assumption to
expect that this particular place will trigger the failure.
In this case, the assumption is correct because there's a "return ret;"
a bit later in the code, but I don't think we should have to look at
this to check the correctness of the code (for example, if something
like "if (ret) try_some_fallback_method();" is later added before
"return ret;", then the assumption would become false).
My version reads as
try something;
if (it failed && I'm only here to report an error)
report_error();
which I find easier to understand.
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/