-
Notifications
You must be signed in to change notification settings - Fork 899
String format ctor for exceptions #1202
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
String format ctor for exceptions #1202
Conversation
odedw
commented
Oct 17, 2015
- Added a c'tor to all exceptions that accepts (IFormatProvider provider, string format, params object[] args) and calls the corresponding LibGit2SharpException c'tor
- changed the LibGit2SharpException c'tor (and all the rest) to accept IFormatProvider instead of CultureInfo.
- Changed all usages to use the new c'tors (where applicable)
Thanks! Looks nicely done to me. @whoisj Any comment? |
👍 @odedw thanks 😄 |
From a brief glance, it looks like we construct all exceptions with |
@ethomson I thought about that but wanted to keep options open (same reason I switched to IFormatProvider instead of CultureInfo). |
👍 agreed. I think that would be a valuable change. Something like: |
Hmmm. Weird unrelated error in the build ( First time I see it. That may be caused by this line (or one a few lines above) whenever Strangely, only entry we're missing is @carlosmn @ethomson @jamill Any idea?
|
Restarted the build as this seems unrelated to this PR. |
@odedw Neat job! How would you feel about rewriting the history and only come up with two commits:
|
@nulltoken Thanks! Working on it. |
@odedw Easy way:
From here on, stage the required files for the first commit, commit. Stage the remaining files and perform the second commit. Force push your changes to GitHub, this PR will be updated accordingly. Would anything go sideways, your local |
@nulltoken Got it. could you describe a bit more what you think each commit should include? |
Sorry, let me try to reword my train of thoughts. Changes that do no impact any existing code (eg. Everything else should go in the first commit. Did that help? |
@nulltoken Yes, LibGit2sharpException related changes in the first one, other exception related changes in the second one. Working on it. |
4877b28
to
51d560a
Compare
@nulltoken Done, let me know if that's what you had in mind. |
@odedw I've pulled this locally. It looks like your first commit doesn't seem to build by itself. Applying the following changes to it should fix this. This should take care of fixing the "updates its dependencies (callers and derived types)" I was referring to earlier LibGit2Sharp/AmbiguousSpecificationException.cs | 5 ++---
LibGit2Sharp/Core/Proxy.cs | 6 ++----
LibGit2Sharp/RemoveFromIndexException.cs | 5 ++---
LibGit2Sharp/Repository.cs | 12 ++++--------
LibGit2Sharp/UnbornBranchException.cs | 2 +-
5 files changed, 11 insertions(+), 19 deletions(-)
diff --git a/LibGit2Sharp/AmbiguousSpecificationException.cs b/LibGit2Sharp/AmbiguousSpecificationException.cs
index 577b84f..bad7af1 100644
--- a/LibGit2Sharp/AmbiguousSpecificationException.cs
+++ b/LibGit2Sharp/AmbiguousSpecificationException.cs
@@ -27,11 +27,10 @@ public AmbiguousSpecificationException(string message)
/// <summary>
/// Initializes a new instance of the <see cref="AmbiguousSpecificationException"/> class with a specified error message.
/// </summary>
- /// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
- public AmbiguousSpecificationException(CultureInfo cultureInfo, string format, params object[] args)
- : base(String.Format(cultureInfo, format, args))
+ public AmbiguousSpecificationException(string format, params object[] args)
+ : base(String.Format(format, args))
{
}
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 71c75db..da2bd00 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -2555,8 +2555,7 @@ public static void git_repository_set_head(RepositorySafeHandle repo, string ref
return null;
case (int)GitErrorCode.Ambiguous:
- throw new AmbiguousSpecificationException(CultureInfo.InvariantCulture,
- "Provided abbreviated ObjectId '{0}' is too short.",
+ throw new AmbiguousSpecificationException("Provided abbreviated ObjectId '{0}' is too short.",
objectish);
default:
@@ -2777,8 +2776,7 @@ public static FileStatus git_status_file(RepositorySafeHandle repo, FilePath pat
return FileStatus.Nonexistent;
case (int)GitErrorCode.Ambiguous:
- throw new AmbiguousSpecificationException(CultureInfo.InvariantCulture,
- "More than one file matches the pathspec '{0}'. " +
+ throw new AmbiguousSpecificationException("More than one file matches the pathspec '{0}'. " +
"You can either force a literal path evaluation " +
"(GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH), or use git_status_foreach().",
path);
diff --git a/LibGit2Sharp/RemoveFromIndexException.cs b/LibGit2Sharp/RemoveFromIndexException.cs
index a1cea4b..c31b86c 100644
--- a/LibGit2Sharp/RemoveFromIndexException.cs
+++ b/LibGit2Sharp/RemoveFromIndexException.cs
@@ -27,11 +27,10 @@ public RemoveFromIndexException(string message)
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2SharpException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
- /// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
- public RemoveFromIndexException(CultureInfo cultureInfo, string format, params object[] args)
- : base(cultureInfo, format, args)
+ public RemoveFromIndexException(string format, params object[] args)
+ : base(format, args)
{
}
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index 3759743..1b5cf22 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -2104,8 +2104,7 @@ private IEnumerable<string> RemoveStagedItems(IEnumerable<string> paths, bool re
status.HasFlag(FileStatus.ModifiedInIndex) ||
status.HasFlag(FileStatus.NewInIndex)))
{
- throw new RemoveFromIndexException(CultureInfo.InvariantCulture,
- "Unable to remove file '{0}', as it has changes staged in the index. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only.",
+ throw new RemoveFromIndexException("Unable to remove file '{0}', as it has changes staged in the index. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only.",
treeEntryChanges.Path);
}
removed.Add(RemoveFromIndex(treeEntryChanges.Path));
@@ -2114,22 +2113,19 @@ private IEnumerable<string> RemoveStagedItems(IEnumerable<string> paths, bool re
case ChangeKind.Modified:
if (status.HasFlag(FileStatus.ModifiedInWorkdir) && status.HasFlag(FileStatus.ModifiedInIndex))
{
- throw new RemoveFromIndexException(CultureInfo.InvariantCulture,
- "Unable to remove file '{0}', as it has staged content different from both the working directory and the HEAD.",
+ throw new RemoveFromIndexException("Unable to remove file '{0}', as it has staged content different from both the working directory and the HEAD.",
treeEntryChanges.Path);
}
if (removeFromWorkingDirectory)
{
- throw new RemoveFromIndexException(CultureInfo.InvariantCulture,
- "Unable to remove file '{0}', as it has local modifications. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only.",
+ throw new RemoveFromIndexException("Unable to remove file '{0}', as it has local modifications. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only.",
treeEntryChanges.Path);
}
removed.Add(RemoveFromIndex(treeEntryChanges.Path));
continue;
default:
- throw new RemoveFromIndexException(CultureInfo.InvariantCulture,
- "Unable to remove file '{0}'. Its current status is '{1}'.",
+ throw new RemoveFromIndexException("Unable to remove file '{0}'. Its current status is '{1}'.",
treeEntryChanges.Path,
treeEntryChanges.Status);
}
diff --git a/LibGit2Sharp/UnbornBranchException.cs b/LibGit2Sharp/UnbornBranchException.cs
index 5efa884..1f1feb4 100644
--- a/LibGit2Sharp/UnbornBranchException.cs
+++ b/LibGit2Sharp/UnbornBranchException.cs
@@ -32,7 +32,7 @@ public UnbornBranchException(string message)
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public UnbornBranchException(CultureInfo cultureInfo, string format, params object[] args)
- : base(cultureInfo, format, args)
+ : base(format, args)
{ }
/// <summary> Of course, you'll have to remove those changes from your second commit. |
51d560a
to
0625b7f
Compare
@nulltoken Done, thanks for the help. |
String format ctor for exceptions
Merged 💥 @odedw Very neat first PR! ✨ ✨ ✨ |
Thanks guys! Here's to many more 👍 |