Skip to content
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

dotnet format without arguments - show usage instead of stack trace #1386

Open
nil4 opened this issue Oct 15, 2021 · 1 comment
Open

dotnet format without arguments - show usage instead of stack trace #1386

nil4 opened this issue Oct 15, 2021 · 1 comment

Comments

@nil4
Copy link

nil4 commented Oct 15, 2021

Today I learned that dotnet format is included with .NET 6.0 SDK, so I ran dotnet format, hoping to find out which arguments it expects:

> dotnet --version
6.0.100-rc.2.21505.57

> dotnet format

Observed results

Red stack trace text filled the console window, scrolling the point it was trying to make with the first line of output off the screen:

> dotnet format
Unhandled exception: System.IO.FileNotFoundException: Could not find a MSBuild project file or solution file in 'C:\some\path'. Specify which to use with the <workspace> argument.
   at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceFinder.FindWorkspace(String searchDirectory, String workspacePath)
   at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceFinder.FindWorkspace(String searchDirectory, String workspacePath)
   at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.ParseWorkspaceOptions(ParseResult parseResult, FormatOptions formatOptions)
   at Microsoft.CodeAnalysis.Tools.Commands.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass27_0.<<UseVersionOption>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__24_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseDebugDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

Expected results

The tool should display some concise guidance for the user. Stack traces can be useful when there's an actual catastrophic error, but not so great for missing arguments.

It would be nice to see, for instance, just this (minus the stack trace):

> dotnet format
Could not find a MSBuild project file or solution file in 'C:\some\path'. 
Specify which to use with the <workspace> argument.

Or perhaps to fall back to something like dotnet format --help:

> dotnet format
Usage:
  dotnet-format [options] [<The project or solution file to operate on. If a file is not specified, the command will
  search the current directory for one.>] [command]

Arguments:
  <The project or solution file to operate on. If a file is   The project or solution file to operate on. If a file is
  not specified, the command will search the current          not specified, the command will search the current
  directory for one.>                                         directory for one. [default: C:\some\path\]

Options: [... etc ...]
@JoeRobich
Copy link
Member

@nil4 Thanks for reporting. This is a regression from 5.x and earlier versions of 6.x that was introduced when we moved to using subcommands. Will open a PR for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants