Skip to content

[Tizen] Handle exception in System.Console.SetCursorPosition in some environments#3635

Closed
gbalykov wants to merge 1 commit intodotnet:mainfrom
gbalykov:terminal-fix
Closed

[Tizen] Handle exception in System.Console.SetCursorPosition in some environments#3635
gbalykov wants to merge 1 commit intodotnet:mainfrom
gbalykov:terminal-fix

Conversation

@gbalykov
Copy link
Copy Markdown
Member

@gbalykov gbalykov commented Feb 3, 2023

For some environments that do not support some terminal interactions next exception happens:

System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension. (Parameter 'top') 
Actual value was -1.
at System.Console.SetCursorPosition(Int32 left, Int32 top) 
at Microsoft.Internal.Common.Utils.LineRewriter.SystemConsoleLineRewriter()
at Microsoft.Internal.Common.Utils.LineRewriter.RewriteConsoleLine()
at Microsoft.Diagnostics.Tools.Trace.CollectCommandHandler.<>c__DisplayClass6_2.b__4()
at Microsoft.Diagnostics.Tools.Trace.CollectCommandHandler.Collect(CancellationToken ct, IConsole console, Int32 processId, FileInfo output, UInt32 buffersize, String providers, String profile, TraceFileFormat format, TimeSpan duration, String clrevents, String clreventlevel, String name, String diagnosticPort, Boolean showchildio, Boolean resumeRuntime

Is there a better fix for this?

cc @HJLeee @alpencolt

…environments

System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension. (Parameter 'top')
Actual value was -1.
at System.Console.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.Internal.Common.Utils.LineRewriter.SystemConsoleLineRewriter()
at Microsoft.Internal.Common.Utils.LineRewriter.RewriteConsoleLine()
at Microsoft.Diagnostics.Tools.Trace.CollectCommandHandler.<>c__DisplayClass6_2.b__4()
at Microsoft.Diagnostics.Tools.Trace.CollectCommandHandler.Collect(CancellationToken ct, IConsole console, Int32 processId, FileInfo output, UInt32 buffersize, String providers, String profile, TraceFileFormat format, TimeSpan duration, String clrevents, String clreventlevel, String name, String diagnosticPort, Boolean showchildio, Boolean resumeRuntime
@gbalykov gbalykov requested a review from a team as a code owner February 3, 2023 09:57
@noahfalk
Copy link
Copy Markdown
Member

noahfalk commented Feb 3, 2023

Thanks @gbalykov! What does the new console output look like after your change in the failure case? I'm trying to figure out if we should be writing that error message you added, failing silently, or perhaps output something else.

@gbalykov
Copy link
Copy Markdown
Member Author

gbalykov commented Feb 6, 2023

@noahfalk

Output before looks like this:

�[6n�[?25l�[6n�[2K�[-1;0H�[6n[ERROR] System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension. (Parameter 'top')
Actual value was -1.
   at System.Console.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.Internal.Common.Utils.LineRewriter.SystemConsoleLineRewriter()
   at Microsoft.Internal.Common.Utils.LineRewriter.RewriteConsoleLine()
   at Microsoft.Diagnostics.Tools.Trace.CollectCommandHandler.<>c__DisplayClass6_2.<Collect>b__4()
   at Microsoft.Diagnostics.Tools.Trace.CollectCommandHandler.Collect(CancellationToken ct, IConsole console, Int32 processId, FileInfo output, UInt32 buffersize, String providers, String profile, TraceFileFormat format, TimeSpan duration, String clrevents, String clreventlevel, String name, String diagnosticPort, Boolean showchildio, Boolean resumeRuntime)
�[?12l�[?25hsh-3.2$

Output after will look smth like this:

�[6n�[?25l
Console.SetCursorPosition() is not supported in this env.
Trace completed.
�[?12l�[?25hsh-3.2$

@noahfalk
Copy link
Copy Markdown
Member

noahfalk commented Feb 7, 2023

Normally we'd see something like this:

> dotnet-trace collect -n <appname>
No profile or providers specified, defaulting to trace profile 'cpu-sampling'

Provider Name                           Keywords            Level               Enabled By
Microsoft-DotNETCore-SampleProfiler     0x0000F00000000000  Informational(4)    --profile
Microsoft-Windows-DotNETRuntime         0x00000014C14FCCBD  Informational(4)    --profile

Process        : C:\Program Files\WindowsApps\Microsoft.YourPhone_1.22112.142.0_x64__8wekyb3d8bbwe\PhoneExperienceHost.exe
Output File    : C:\Users\noahfalk\PhoneExperienceHost.exe_20230206_164056.nettrace

[00:00:00:04]   Recording trace 2.8575   (MB)
Press <Enter> or <Ctrl+C> to exit...
Stopping the trace. This may take several minutes depending on the application being traced.

Trace completed.

Are you saying all that output is gone now? I was expecting the 'Recording trace ...' to be the first line of output that was impacted by the problem. Higher level my worry is that 'Console.SetCursorPosition() is not supported in this env.' isn't going to be very meaningful to users. They might understand literally what the message is telling them, but they won't know why it matters or to what degree the functioning of dotnet-trace has been impacted. Ideally I hope we could write some alternate output like this when we can't do in-place updates:

> dotnet-trace collect -n <appname>
No profile or providers specified, defaulting to trace profile 'cpu-sampling'

Provider Name                           Keywords            Level               Enabled By
Microsoft-DotNETCore-SampleProfiler     0x0000F00000000000  Informational(4)    --profile
Microsoft-Windows-DotNETRuntime         0x00000014C14FCCBD  Informational(4)    --profile

Process        : C:\Program Files\WindowsApps\Microsoft.YourPhone_1.22112.142.0_x64__8wekyb3d8bbwe\PhoneExperienceHost.exe
Output File    : C:\Users\noahfalk\PhoneExperienceHost.exe_20230206_164056.nettrace

Recording trace in progress. Press <Enter> or <Ctrl+C> to exit...
Stopping the trace. This may take several minutes depending on the application being traced.

Trace completed.

@HJLeee
Copy link
Copy Markdown
Contributor

HJLeee commented Feb 21, 2023

@gbalykov Please close this one.

@gbalykov gbalykov closed this Feb 21, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants