Skip to content

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

Merged
merged 2 commits into from
Oct 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions LibGit2Sharp/AmbiguousSpecificationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
}

Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/BareRepositoryException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ public BareRepositoryException(string message)
: base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.BareRepositoryException"/> class with a specified error message.
/// </summary>
/// <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 BareRepositoryException(string format, params object[] args)
: base(format, args)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.BareRepositoryException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions LibGit2Sharp/BranchCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ public virtual Branch Rename(Branch branch, string newName, bool allowOverwrite)

if (branch.IsRemote)
{
throw new LibGit2SharpException(CultureInfo.InvariantCulture,
"Cannot rename branch '{0}'. It's a remote tracking branch.",
throw new LibGit2SharpException("Cannot rename branch '{0}'. It's a remote tracking branch.",
branch.FriendlyName);
}

Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/CheckoutConflictException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public CheckoutConflictException(string message)
: base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a specified error message.
/// </summary>
/// <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 CheckoutConflictException(string format, params object[] args)
: base(format, args)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions LibGit2Sharp/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,7 @@ private ConfigurationSafeHandle RetrieveConfigurationHandle(ConfigurationLevel l

if (handle == null && throwIfStoreHasNotBeenFound)
{
throw new LibGit2SharpException(CultureInfo.InvariantCulture,
"No {0} configuration file has been found.",
throw new LibGit2SharpException("No {0} configuration file has been found.",
Enum.GetName(typeof(ConfigurationLevel), level));
}

Expand Down
10 changes: 4 additions & 6 deletions LibGit2Sharp/Core/Ensure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,14 @@ public static void GitObjectIsNotNull(GitObject gitObject, string identifier)
return;
}

var message = string.Format(CultureInfo.InvariantCulture,
"No valid git object identified by '{0}' exists in the repository.",
identifier);

var messageFormat = "No valid git object identified by '{0}' exists in the repository.";

if (string.Equals("HEAD", identifier, StringComparison.Ordinal))
{
throw new UnbornBranchException(message);
throw new UnbornBranchException(messageFormat, identifier);
}

throw new NotFoundException(message);
throw new NotFoundException(messageFormat, identifier);
}
}
}
30 changes: 12 additions & 18 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,7 @@ public static void git_filter_register(string name, IntPtr filterPtr, int priori
int res = NativeMethods.git_filter_register(name, filterPtr, priority);
if (res == (int)GitErrorCode.Exists)
{
var message = String.Format("A filter with the name '{0}' is already registered", name);
throw new EntryExistsException(message);
throw new EntryExistsException("A filter with the name '{0}' is already registered", name);
}
Ensure.ZeroResult(res);
}
Expand Down Expand Up @@ -1432,9 +1431,8 @@ public static IntPtr git_odb_backend_malloc(IntPtr backend, UIntPtr len)

if (IntPtr.Zero == toReturn)
{
throw new LibGit2SharpException(CultureInfo.InvariantCulture,
"Unable to allocate {0} bytes; out of memory",
len,
throw new LibGit2SharpException("Unable to allocate {0} bytes; out of memory",
len,
GitErrorCode.Error,
GitErrorCategory.NoMemory);
}
Expand Down Expand Up @@ -2257,7 +2255,7 @@ public static void git_remote_rename(RepositorySafeHandle repo, string name, str

if (res == (int)GitErrorCode.NotFound)
{
throw new NotFoundException(string.Format("Remote '{0}' does not exist and cannot be renamed.", name));
throw new NotFoundException("Remote '{0}' does not exist and cannot be renamed.", name);
}

Ensure.ZeroResult(res);
Expand Down Expand Up @@ -2405,9 +2403,8 @@ public static RepositorySafeHandle git_repository_open(string path)

if (res == (int)GitErrorCode.NotFound)
{
throw new RepositoryNotFoundException(String.Format(CultureInfo.InvariantCulture,
"Path '{0}' doesn't point at a valid Git repository or workdir.",
path));
throw new RepositoryNotFoundException("Path '{0}' doesn't point at a valid Git repository or workdir.",
path);
}

Ensure.ZeroResult(res);
Expand Down Expand Up @@ -2436,9 +2433,8 @@ public static void git_repository_open_ext(string path, RepositoryOpenFlags flag

if (res == (int)GitErrorCode.NotFound)
{
throw new RepositoryNotFoundException(String.Format(CultureInfo.InvariantCulture,
"Path '{0}' doesn't point at a valid Git repository or workdir.",
path));
throw new RepositoryNotFoundException("Path '{0}' doesn't point at a valid Git repository or workdir.",
path);
}

Ensure.ZeroResult(res);
Expand Down Expand Up @@ -2556,8 +2552,7 @@ public static Tuple<GitObjectSafeHandle, ReferenceSafeHandle> git_revparse_ext(R
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:
Expand Down Expand Up @@ -2778,8 +2773,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);
Expand Down Expand Up @@ -3079,8 +3073,8 @@ public static void git_transport_register(String prefix, IntPtr transport_cb, In

if (res == (int)GitErrorCode.Exists)
{
throw new EntryExistsException(String.Format("A custom transport for '{0}' is already registered",
prefix));
throw new EntryExistsException("A custom transport for '{0}' is already registered",
prefix);
}

Ensure.ZeroResult(res);
Expand Down
3 changes: 1 addition & 2 deletions LibGit2Sharp/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ private static T BuildDiffResult<T>(DiffSafeHandle diff) where T : class, IDiffR

if (!ChangesBuilders.TryGetValue(typeof(T), out builder))
{
throw new LibGit2SharpException(CultureInfo.InvariantCulture,
"User-defined types passed to Compare are not supported. Supported values are: {0}",
throw new LibGit2SharpException("User-defined types passed to Compare are not supported. Supported values are: {0}",
string.Join(", ", ChangesBuilders.Keys.Select(x => x.Name)));
}

Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/EmptyCommitException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public EmptyCommitException(string message)
: base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="EmptyCommitException"/> class with a specified error message.
/// </summary>
/// <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 EmptyCommitException(string format, params object[] args)
: base(format, args)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="EmptyCommitException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/EntryExistsException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public EntryExistsException(string message)
: base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.EntryExistsException"/> class with a specified error message.
/// </summary>
/// <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 EntryExistsException(string format, params object[] args)
: base(format, args)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.EntryExistsException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions LibGit2Sharp/GitObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ internal static GitObject BuildFrom(Repository repo, ObjectId id, GitObjectType
return new Blob(repo, id);

default:
throw new LibGit2SharpException(CultureInfo.InvariantCulture,
"Unexpected type '{0}' for object '{1}'.",
throw new LibGit2SharpException("Unexpected type '{0}' for object '{1}'.",
type,
id);
}
Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/InvalidSpecificationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public InvalidSpecificationException(string message)
: base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="InvalidSpecificationException"/> class with a specified error message.
/// </summary>
/// <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 InvalidSpecificationException(string format, params object[] args)
: base(format, args)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="InvalidSpecificationException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
Expand Down
5 changes: 2 additions & 3 deletions LibGit2Sharp/LibGit2SharpException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ public LibGit2SharpException(string message, Exception innerException)
/// <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 LibGit2SharpException(CultureInfo cultureInfo, string format, params object[] args)
: base(String.Format(cultureInfo, format, args))
public LibGit2SharpException(string format, params object[] args)
: base(String.Format(CultureInfo.InvariantCulture, format, args))
{
}

Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/LockedFileException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public LockedFileException(string message)
: base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.LockedFileException"/> class with a specified error message.
/// </summary>
/// <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 LockedFileException(string format, params object[] args)
: base(format, args)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.LockedFileException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/MergeFetchHeadNotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ public MergeFetchHeadNotFoundException(string message)
: base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="MergeFetchHeadNotFoundException"/> class with a specified error message.
/// </summary>
/// <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 MergeFetchHeadNotFoundException(string format, params object[] args)
: base(format, args)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="MergeFetchHeadNotFoundException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/NameConflictException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public NameConflictException(string message)
: base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="NameConflictException"/> class with a specified error message.
/// </summary>
/// <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 NameConflictException(string format, params object[] args)
: base(format, args)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="NameConflictException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
Expand Down
4 changes: 1 addition & 3 deletions LibGit2Sharp/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,7 @@ public virtual void Push(
{
if (string.IsNullOrEmpty(branch.UpstreamBranchCanonicalName))
{
throw new LibGit2SharpException(
CultureInfo.InvariantCulture,
"The branch '{0}' (\"{1}\") that you are trying to push does not track an upstream branch.",
throw new LibGit2SharpException("The branch '{0}' (\"{1}\") that you are trying to push does not track an upstream branch.",
branch.FriendlyName, branch.CanonicalName);
}
}
Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/NonFastForwardException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ public NonFastForwardException(string message)
: base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.NonFastForwardException"/> class with a specified error message.
/// </summary>
/// <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 NonFastForwardException(string format, params object[] args)
: base(format, args)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.NonFastForwardException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/NotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public NotFoundException(string message)
: base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.NotFoundException"/> class with a specified error message.
/// </summary>
/// <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 NotFoundException(string format, params object[] args)
: base(format, args)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.NotFoundException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
Expand Down
Loading