Skip to content

Commit b5bd2e0

Browse files
committed
Add length check for log indent level
Add length check for log indent level to avoid exceptions like this: Error Message: System.ArgumentOutOfRangeException : Length cannot be less than zero. Parameter name: length Stack Trace: at System.String.Substring (System.Int32 startIndex, System.Int32 length) [0x0004a] in <f3f2aa82c3a04d48845485ce37124803>:0 at GitVersion.Logger+<>c__DisplayClass19_0.<IndentLog>b__0 () [0x00010] in <05fc21618d444a47be7b45d99fa1d3c6>:0 at GitVersion.Logger+ActionDisposable.Dispose () [0x00000] in <05fc21618d444a47be7b45d99fa1d3c6>:0 at GitVersion.VersionCalculation.BaseVersionCalculator.GetBaseVersion (GitVersion.GitVersionContext context) [0x00211] in <05fc21618d444a47be7b45d99fa1d3c6>:0 at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion (GitVersion.GitVersionContext context) [0x0003f] in <05fc21618d444a47be7b45d99fa1d3c6>:0 at GitVersion.GitVersionFinder.FindVersion (GitVersion.GitVersionContext context) [0x000a1] in <05fc21618d444a47be7b45d99fa1d3c6>:0 at GitVersionCore.Tests.GitToolsTestingExtensions.ExecuteGitVersion (GitVersion.GitVersionContext context) [0x00007] in <e141d799e05748d0bf9753d21cdcadd7>:0 at GitVersionCore.Tests.GitToolsTestingExtensions.GetVersion (GitTools.Testing.RepositoryFixtureBase fixture, GitVersion.Config configuration, LibGit2Sharp.IRepository repository, System.String commitId, System.Boolean isForTrackedBranchOnly, System.String targetBranch) [0x00030] in <e141d799e05748d0bf9753d21cdcadd7>:0 at GitVersionCore.Tests.GitToolsTestingExtensions.AssertFullSemver (GitTools.Testing.RepositoryFixtureBase fixture, GitVersion.Config configuration, System.String fullSemver, LibGit2Sharp.IRepository repository, System.String commitId, System.Boolean isForTrackedBranchOnly, System.String targetBranch) [0x00050] in <e141d799e05748d0bf9753d21cdcadd7>:0 at GitVersionCore.Tests.GitToolsTestingExtensions.AssertFullSemver (GitTools.Testing.RepositoryFixtureBase fixture, System.String fullSemver, LibGit2Sharp.IRepository repository, System.String commitId, System.Boolean isForTrackedBranchOnly, System.String targetBranch) [0x00007] in <e141d799e05748d0bf9753d21cdcadd7>:0 at DocumentationSamples.GitFlowFeatureBranch () [0x000a2] in <e141d799e05748d0bf9753d21cdcadd7>:0 at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <f3f2aa82c3a04d48845485ce37124803>:0 https://dev.azure.com/GitTools/GitVersion/_build/results?buildId=191&view=logs&jobId=a5e52b91-c83f-5429-4a68-c246fc63a4f7&taskId=d6b35a2b-3a7d-590e-76eb-a415813199f6&lineStart=225&lineEnd=226&colStart=1&colEnd=1
1 parent 4ed89ac commit b5bd2e0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/GitVersionCore/Logger.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public static IDisposable IndentLog(string operationDescription)
2626
indent = indent + " ";
2727
return new ActionDisposable(() =>
2828
{
29-
indent = indent.Substring(0, indent.Length - 2);
29+
var length = indent.Length - 2;
30+
indent = length > 0 ? indent.Substring(0, length) : indent;
3031
WriteInfo(string.Format(CultureInfo.InvariantCulture, "End: {0} (Took: {1:N}ms)", operationDescription, DateTime.Now.Subtract(start).TotalMilliseconds));
3132
});
3233
}

0 commit comments

Comments
 (0)