leonardochaia/dotnet-affected

Running tool in Azure Pipelines will throw exception

Closed this issue · 6 comments

When running the tool in Azure Pipelines to inspect my repository it throws the following exception:

Command I run:

dotnet affected -p $(System.DefaultWorkingDirectory) --from origin/develop generate --output $(System.DefaultWorkingDirectory)\changed.proj
Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at System.CommandLine.Rendering.Views.ScreenView.Render(Region region)
   at Affected.Cli.Views.ViewRenderingContext.Render(View rootView) in C:\Projects\dotnet-affected\src\dotnet-affected\Views\ViewRenderingContext.cs:line 29
   at Affected.Cli.Commands.GenerateCommand.GenTraversalHandler(IConsole console, String output, CommandExecutionData data, ViewRenderingContext renderingContext) in C:\Projects\dotnet-affected\src\dotnet-affected\Commands\GenerateCommand.cs:line 71
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass27_0.<<UseVersionOption>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__24_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseDebugDirective>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

It looks like the System.CommandLine.Rendering package cannot handle the way that Azure DevOps handles the stdout.

I did some further investigation and when I output straight to the IConsole it does work.

Hi @wterpstra ! I'm sorry I haven't been able to spend some time on this one.

screen.Render(Region.EntireTerminal);

I'm not really sure what's going on TBH but maybe changing the Region we provide here might have something to do with it?
I don't really know.

If we can determine it's an issue with CommandLine.Rendering then we should file an issue there.
We can definitively remove it for now if its giving us problems, however I think view-related the code looks much cleaner using it.

Hi @leonardochaia, no worries. I have both tried Region.EntireTerminal and Region.Scrolling. When I find the time I can try to extract a simplified reproduction of the issue and raise an issue with the CommandLine.Rendering folks. I'll reference this issue to keep track. I agree that the code looks much cleaner this way.

Hey @wterpstra! Just wanted you to know that I'm be building an Azure Pipelines where I'm using the current deployed version (1.0.0-preview-1) of dotnet-affected which works fine, since it is not using the ComandLine.Rendering stuff.

I wanted to ask you if you can give me more info of the stuff you have tried, so that we don't duplicate effort.
I'm planning merging #5, figure out #1 and deploy a new preview release.

All right, managed to reproduce it in this GitHub build.

The fix came from here

Hey @wterpstra, I've released v1.0.0-preview-3 which includes the fix.

I've tested in Azure DevOps and it seems to be working fine.

So perhaps with the --solution-path and this fix you could give v1.0.0-preview-3 and report back? :)

Thanks for the help bud!