Skip to content

Conversation

@scowing
Copy link
Contributor

@scowing scowing commented Nov 20, 2025

Why

Want to include stack trace to the debug output

Ticket

HOD-4002

@scowing scowing requested a review from a team as a code owner November 20, 2025 16:59
Copy link
Member

@boarnoah boarnoah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth deliberately throwing a random exception in a local build -- to verify that it looks good

@scowing
Copy link
Contributor Author

scowing commented Nov 20, 2025

It might be worth deliberately throwing a random exception in a local build -- to verify that it looks good

@boarnoah Yeah I did, looks like:

Invalid account selection
[DEBUG] Exception: BmxException - Invalid account selection
   at D2L.Bmx.ConsolePrompter.D2L.Bmx.IConsolePrompter.PromptAccount(String[] accounts) in C:\d2l\Workspace\bmx\src\D2L.Bmx\ConsolePrompter.cs:line 82
   at D2L.Bmx.AwsCredsCreator.CreateAwsCredsAsync(OktaAuthenticatedContext okta, String account, String role, Nullable`1 duration, Boolean nonInteractive,
Boolean cache) in C:\d2l\Workspace\bmx\src\D2L.Bmx\AwsCredsCreator.cs:line 92
   at D2L.Bmx.PrintHandler.HandleAsync(String org, String user, String account, String role, Nullable`1 duration, Boolean nonInteractive, String format,
Boolean cacheAwsCredentials) in C:\d2l\Workspace\bmx\src\D2L.Bmx\PrintHandler.cs:line 25
   at System.CommandLine.Invocation.AnonymousCommandHandler.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__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Program.<>c__DisplayClass0_0.<<<Main>$>b__8>d.MoveNext() in C:\d2l\Workspace\bmx\src\D2L.Bmx\Program.cs:line 257
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__18_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__5_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<<UseExceptionHandler>b__0>d.MoveNext()

The trace is a little bloated with all the builder extensions though but not sure if there is a way to omit them?

@boarnoah
Copy link
Member

Looks fine to me, not worth the effort to trim stack trace (and its only ever visible when someone enables debug mode to get detailed traces anyway)

@scowing scowing merged commit 7dec0f1 into main Nov 20, 2025
11 checks passed
@scowing scowing deleted the add-debug-stacktrace branch November 20, 2025 19:09
if( BmxEnvironment.IsDebug ) {
messageWriter.WriteError( $"[DEBUG] Exception: {exception.GetType().Name} - {exception.Message}" );
messageWriter.WriteError(
$"[DEBUG] Exception: {exception.GetType().Name} - {exception.Message}\n{exception.StackTrace ?? string.Empty}" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be simply exception.ToString()

consoleWriter.WriteError( exception.ToString() );

and it worked well enough.
I don't see why it shouldn't be kept the same, maybe only adding the prefix "[DEBUG] Exception:"

@scowing

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 this pull request may close these issues.

4 participants