dn-vm / dnvm

dnvm is a command-line interface for installing and updating different dotnet SDKs
https://dnvm.net
MIT License
59 stars 8 forks source link

Slightly more robust parameter parsing #144

Closed danielmarbach closed 3 months ago

danielmarbach commented 3 months ago

When doing

dvnm install

the following exception is raised

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Dnvm.InstallCommand.<Run>d__1.MoveNext() + 0x198
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x24
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x100
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x68
   at Dnvm.Program.<Dnvm>d__3.MoveNext() + 0x2f0
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x24
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x100
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x68
   at Dnvm.Program.<Main>d__2.MoveNext() + 0x2cc
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x24
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x100
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x68
   at Dnvm.Program.<Main>(String[] args) + 0x3c
   at dnvm!<BaseAddress>+0x557538

The code tries to access options.SdkVersion.Major while SdkVersion is null.

With this change you get

error: Parameter <version> requires a value

There might be a few edge cases I haven't been able to cover given the limited amount of time I had available to fix this. Sorry for that.

agocke commented 3 months ago

Thanks! FYI, the reason there aren't more improvements to argument parsing is that I was hoping to swap this code out for an AOT-compatible argument parser, but my progress on Spectre.Console.Cli is very slow. So it makes sense to spend a little time cleaning this up.