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
GetEffectiveGitSetting treats non 0 results as failures #11145
Comments
All commands where 0 is not a failure explicitly handles this. There are probably more of these commands than those that fails. (And it is mstv that has the credit of introducing this handling, I have though been involved in handling git errors. A number of unknown issues were fixed this way.) |
Which of these exit codes is not an error for If you need a |
Exactly my point but if you will take the time to do something like add a test that shows current implementation raises an exception if config key is not set. Try adding a test that looks for either a valid git config key found from |
Again, if you need a TryGet, implement one. If the error from the BTW: "config file cannot be written" is completely off-topic for a Get function. |
I don't think you see my point. I will walk you through it.
Exit code: 1
diff --git a/GitUI/CommandsDialogs/FormCommit.cs b/GitUI/CommandsDialogs/FormCommit.cs
index 8ee22871b..980fa7f5e 100644
--- a/GitUI/CommandsDialogs/FormCommit.cs
+++ b/GitUI/CommandsDialogs/FormCommit.cs
@@ -1319,6 +1319,9 @@ bool ConfirmAndStageAllUnstaged()
void DoCommit()
{
+ var catDog = Module.GetEffectiveGitSetting("cat.dog");
+ Console.WriteLine($"cat.dog:'{catDog}'");
+
if (Module.InTheMiddleOfConflictedMerge())
{
MessageBox.Show(this, _mergeConflicts.Text, _mergeConflictsCaption.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); This is DEAD wrong. The config result is a blank string and exit code 1 says value unset. This is NOT an exception. I got the expected result. It is valid and did not fail and is not exceptional state. My fix does the following
I am against creating a try... function and leaving another function that just exceptions. My way provides status and allows for exceptional handling if needed with null status value and will prevent users reporting x error when it was really just that their config value was unset.
Setting config values. Note the exit codes 3, 4, 5. I know I am not dealing with setting values but I did provide the values just the same so that they could be used. |
Yes I can add the config name and potentially when retrieved. There is room for metadata around this. |
What is unclear with
? What you want, is a |
That is the same error-hiding attitude as
That's why it is an |
Again: |
Do you run git try-getconfig? No. I am doing same 5hing here. Run git config and get the output and also store the result from exit code. Then use this result value as needed where you called. Exit code 1 is NOT an exceptional state. If git config blew up and returned say exit code 99. Yes that would be a exception. We can definitely show that. What I don't like is this get setting and it blows up vs a result that will always provide you details and each caller can deal as needed. |
Have you ever used a |
Sure I have worked with a generic dictionary. But I was working with potential more fields like contig key asked for just in case we do a whole git config fetch down the road. That is where I would do a Dictionary<string, MySettingType). I was more using this to define the result with OOP principles like being able to add ConfigKey, Value, Status, WhenRetrieved...Whatever down the road. I knew both of you would push back because you a don't quite seem to get exit codes and the fact that they don't always mean error and that I am pushing for consistency and one result of a git config value that provides all the info from one method. I hate the idea of a user trying to figure out do I do TryGetEffectiveGtSetting vs the other thing. Yes if exit code isn't defined in enum.. sure I can see an exception being thrown.. Frankly it is too easy to goof the Git Version of GetEffectiveGitSettkng vs the GetEffectiveSetting. But that is another topic. Yes expose git errors where needed but read the exit codes. 1 is clearly my example of cat.dog and attempting to retrieve it. Good example is if you don't have gpg.program set. In my gpg work and without me changing functionality, you get an error dialog with exit code 1. The program should internally handle that and based on what is desired ( just accept blank value, write special case code to handle this state...). Exceptions are for Exceptional state. An unset git config value is understood by everyone to return a blank value. Not everyone understands 1 is unset. Our program can help by going. I see that the value is blank and the status is unset... I can not create an exception and instead provide the blanks and Unset status. If I as a non admin user tried to run code that tried to set a system level git config value, our program could look at the status and see maybe a 3 or 4 result. http://www.codinghell.ch/blog/2013/03/31/how-and-when-not-to-use-exceptions/#:~:text=Don't%20use%20exceptions%20to,fields%20for%20flow%20control%20instead. If I can see the status and skip the whole exception crud, I would rather do that. Yes can add throw where needed but if 1, not an exception...Just return blank and unset to user. No need for exception building and throwing. |
If the caller is OK with exit code 1 is OK, then it may be OK to have a specific access function like The other error codes still seem as errors to me - or they need special handling too. |
Environment
Issue description
As seen in https://git-scm.com/docs/git-config#_description it is not an error to get an exit code of non 0. Right now we get an exception because of the changes to GetOutput and treating all non 0 exit codes as exceptions instead of handing the result.
Not understanding exit codes as non errors is a failure on executable handling. Found during gpg work on a clean machine ant it looking for gpg.Program and commit.gpgSign and such. Which when not set, exit code is 1. Which tells you that value is not set.
Steps to reproduce
Change the name and email fetching in formCommit to get
usser.Value
Did this work in previous version of GitExtensions?
Maybe before the changes @mstv and @gerhardol did with changing the way executable output is handled with GetOutput from the executable.
Diagnostics
No response
The text was updated successfully, but these errors were encountered: