leonardochaia / dotnet-affected

.NET tool for determining which projects are affected by a set of changes. Useful for large projects or monorepos.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NullReference exception when running dotnet affected on a set of changes that adds the Directory.Packages.props file

wterpstra opened this issue · comments

I just added central management of NuGet packages and it dotnet affected fails with a NullReferenceException. From the stacktrace it looks like it tries to read the Directory.Packages.props from the 'previous' commit but it (obviously) can't find it there and throws a NullReference exception.

From GitChangesProvider:

private static string ReadTextFile(string pathToFile, Commit commit)
        {
            var blob = (Blob)commit[pathToFile].Target; // When commit does not contain file it will go boom here

            using var content = new StreamReader(blob.GetContentStream(), Encoding.UTF8);
            return content.ReadToEnd();
        }

I think it would be wise to check for this and return an empty string instead.

Stacktrace:

2022-03-14T08:57:01.5290841Z Unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object.
2022-03-14T08:57:01.5293712Z    at Affected.Cli.GitChangesProvider.ReadTextFile(String pathToFile, Commit commit) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line 44
2022-03-14T08:57:01.5296484Z    at Affected.Cli.GitChangesProvider.GetTextFileContents(String directory, String pathToFile, String from, String to) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line 33
2022-03-14T08:57:01.5299157Z    at Affected.Cli.Commands.CommandExecutionContext.DetermineChangedNugetPackages() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/Context/CommandExecutionContext.cs:line 117
2022-03-14T08:57:01.5300524Z    at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
2022-03-14T08:57:01.5301503Z    at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
2022-03-14T08:57:01.5302372Z    at System.Lazy`1.CreateValue()
2022-03-14T08:57:01.5303471Z    at System.Lazy`1.get_Value()
2022-03-14T08:57:01.5305352Z    at Affected.Cli.Commands.CommandExecutionContext.get_ChangedNuGetPackages() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/Context/CommandExecutionContext.cs:line 45
2022-03-14T08:57:01.5307691Z    at Affected.Cli.Views.AffectedInfoView..ctor(ICommandExecutionContext context) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Views/AffectedInfoView.cs:line 12
2022-03-14T08:57:01.5310675Z    at Affected.Cli.Commands.AffectedRootCommand.AffectedCommandHandler.InvokeAsync(InvocationContext ic) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/AffectedRootCommand.cs:line 63
2022-03-14T08:57:01.5312292Z    at System.CommandLine.NamingConventionBinder.CommandHandler.GetExitCodeAsync(Object returnValue, InvocationContext context)
2022-03-14T08:57:01.5313540Z    at System.CommandLine.NamingConventionBinder.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
2022-03-14T08:57:01.5314727Z    at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
2022-03-14T08:57:01.5315982Z --- End of stack trace from previous location ---
2022-03-14T08:57:01.5316963Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass18_0.<<UseParseErrorReporting>b__0>d.MoveNext()
2022-03-14T08:57:01.5318265Z --- End of stack trace from previous location ---
2022-03-14T08:57:01.5320615Z    at Affected.Cli.ErrorHandlingMiddleware.<>c__DisplayClass0_0.<<UseRenderingErrorHandler>b__0>d.MoveNext() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/CommandLine/ErrorHandlingMiddleware.cs:line 26
2022-03-14T08:57:01.5322317Z --- End of stack trace from previous location ---
2022-03-14T08:57:01.5323270Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<AddMiddleware>b__0>d.MoveNext()
2022-03-14T08:57:01.5324520Z --- End of stack trace from previous location ---
2022-03-14T08:57:01.5325468Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<AddMiddleware>b__0>d.MoveNext()
2022-03-14T08:57:01.5326705Z --- End of stack trace from previous location ---
2022-03-14T08:57:01.5327673Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<AddMiddleware>b__0>d.MoveNext()
2022-03-14T08:57:01.5328904Z --- End of stack trace from previous location ---
2022-03-14T08:57:01.5329870Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseHelp>b__0>d.MoveNext()
2022-03-14T08:57:01.5331099Z --- End of stack trace from previous location ---
2022-03-14T08:57:01.5332076Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
2022-03-14T08:57:01.5333324Z --- End of stack trace from previous location ---
2022-03-14T08:57:01.5334294Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass20_0.<<UseTypoCorrections>b__0>d.MoveNext()
2022-03-14T08:57:01.5335581Z --- End of stack trace from previous location ---
2022-03-14T08:57:01.5336489Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__19_0>d.MoveNext()
2022-03-14T08:57:01.5337708Z --- End of stack trace from previous location ---
2022-03-14T08:57:01.5338672Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseDirective>b__0>d.MoveNext()
2022-03-14T08:57:01.5339957Z --- End of stack trace from previous location ---
2022-03-14T08:57:01.5340881Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__6_0>d.MoveNext()
2022-03-14T08:57:01.5342110Z --- End of stack trace from previous location ---
2022-03-14T08:57:01.5343264Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass9_0.<<UseExceptionHandler>b__0>d.MoveNext()
2022-03-14T08:57:04.9154009Z Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
2022-03-14T08:57:04.9156920Z  ---> System.NullReferenceException: Object reference not set to an instance of an object.
2022-03-14T08:57:04.9159581Z    at Affected.Cli.GitChangesProvider.ReadTextFile(String pathToFile, Commit commit) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line 44
2022-03-14T08:57:04.9163573Z    at Affected.Cli.GitChangesProvider.GetTextFileContents(String directory, String pathToFile, String from, String to) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line 33
2022-03-14T08:57:04.9167268Z    at Affected.Cli.Commands.CommandExecutionContext.DetermineChangedNugetPackages() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/Context/CommandExecutionContext.cs:line 117
2022-03-14T08:57:04.9169070Z    at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
2022-03-14T08:57:04.9170410Z    at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
2022-03-14T08:57:04.9171669Z    at System.Lazy`1.CreateValue()
2022-03-14T08:57:04.9172606Z    at System.Lazy`1.get_Value()
2022-03-14T08:57:04.9174839Z    at Affected.Cli.Commands.CommandExecutionContext.get_ChangedNuGetPackages() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/Context/CommandExecutionContext.cs:line 45
2022-03-14T08:57:04.9182464Z    at Affected.Cli.Views.AffectedInfoView..ctor(ICommandExecutionContext context) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Views/AffectedInfoView.cs:line 12
2022-03-14T08:57:04.9185195Z    at Affected.Cli.Commands.DescribeCommand.CommandHandler.InvokeAsync(InvocationContext ic) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/DescribeCommand.cs:line 30
2022-03-14T08:57:04.9186740Z    --- End of inner exception stack trace ---
2022-03-14T08:57:04.9187761Z    at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
2022-03-14T08:57:04.9189100Z    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2022-03-14T08:57:04.9190225Z    at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
2022-03-14T08:57:04.9191254Z    at System.CommandLine.NamingConventionBinder.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
2022-03-14T08:57:04.9192501Z    at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
2022-03-14T08:57:04.9193740Z --- End of stack trace from previous location ---
2022-03-14T08:57:04.9194444Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass18_0.<<UseParseErrorReporting>b__0>d.MoveNext()
2022-03-14T08:57:04.9195120Z --- End of stack trace from previous location ---
2022-03-14T08:57:04.9196154Z    at Affected.Cli.ErrorHandlingMiddleware.<>c__DisplayClass0_0.<<UseRenderingErrorHandler>b__0>d.MoveNext() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/CommandLine/ErrorHandlingMiddleware.cs:line 26
2022-03-14T08:57:04.9197036Z --- End of stack trace from previous location ---
2022-03-14T08:57:04.9197531Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<AddMiddleware>b__0>d.MoveNext()
2022-03-14T08:57:04.9198196Z --- End of stack trace from previous location ---
2022-03-14T08:57:04.9198692Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<AddMiddleware>b__0>d.MoveNext()
2022-03-14T08:57:04.9199350Z --- End of stack trace from previous location ---
2022-03-14T08:57:04.9199846Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<AddMiddleware>b__0>d.MoveNext()
2022-03-14T08:57:04.9200500Z --- End of stack trace from previous location ---
2022-03-14T08:57:04.9200981Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseHelp>b__0>d.MoveNext()
2022-03-14T08:57:04.9201607Z --- End of stack trace from previous location ---
2022-03-14T08:57:04.9202126Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
2022-03-14T08:57:04.9202770Z --- End of stack trace from previous location ---
2022-03-14T08:57:04.9203291Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass20_0.<<UseTypoCorrections>b__0>d.MoveNext()
2022-03-14T08:57:04.9204101Z --- End of stack trace from previous location ---
2022-03-14T08:57:04.9204592Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__19_0>d.MoveNext()
2022-03-14T08:57:04.9205208Z --- End of stack trace from previous location ---
2022-03-14T08:57:04.9205706Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseDirective>b__0>d.MoveNext()
2022-03-14T08:57:04.9206373Z --- End of stack trace from previous location ---
2022-03-14T08:57:04.9206853Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__6_0>d.MoveNext()
2022-03-14T08:57:04.9207498Z --- End of stack trace from previous location ---
2022-03-14T08:57:04.9208001Z    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass9_0.<<UseExceptionHandler>b__0>d.MoveNext()