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

[BUG] stdout.terminalColumns causes StdoutException #512

Closed
4 tasks done
jibbers42 opened this issue Mar 24, 2023 · 13 comments
Closed
4 tasks done

[BUG] stdout.terminalColumns causes StdoutException #512

jibbers42 opened this issue Mar 24, 2023 · 13 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@jibbers42
Copy link

jibbers42 commented Mar 24, 2023

Before creating a bug report please make check the following

  • You have read our FAQ
  • If you have used flutter. Please install correctly, run pub cache repair. Close the terminal and try again.
  • If you are on Windows. Make sure you are running the terminal as administrator or with developer permissions.
  • Run fvm doctor if possible and add the output to the issue.

Describe the bug
Running my cli app results in an error from dartio. It runs fine if I don't use fvm.

I get the width of the terminal to make help output friendlier. The offending line is:
int get usageLineLength => min(stdout.terminalColumns, 90);

The error begins:

Unhandled exception:
StdoutException: Could not get terminal size, OS Error: The handle is invalid.
, errno = 6
#0      Stdout._terminalSize (dart:io-patch/stdio_patch.dart:172:7)
#1      Stdout._terminalColumns (dart:io-patch/stdio_patch.dart:165:35)
#2      Stdout.terminalColumns (dart:io/stdio.dart:228:30)
...

To Reproduce
Steps to reproduce the behavior:

  1. Go to terminal..
  2. Run fvm dart run .\bin\my_script.dart -h
  3. See error

Expected behavior
My script should run (show help in this case).

Running without fvm works fine:
dart run .\bin\my_script.dart -h

Logs

> fvm --verbose dart run .\bin\my_script.dart -h
[     0.004s] Version: 3.3.10 - already installed.
[     0.014s] Link is setup correctly
[     0.015s] fvm: running Dart from Flutter "3.3.10"

Unhandled exception:
StdoutException: Could not get terminal size, OS Error: The handle is invalid.
, errno = 6
#0      Stdout._terminalSize (dart:io-patch/stdio_patch.dart:172:7)
#1      Stdout._terminalColumns (dart:io-patch/stdio_patch.dart:165:35)
#2      Stdout.terminalColumns (dart:io/stdio.dart:228:30)
...

Desktop (please complete the following information):

  • OS: Windows 11 Pro 22621.1413
  • FVM Version: 2.4.1
  • If Windows: Which Powershell are you using?: PowerShell 7.3.2

Additional context

> fvm doctor

FVM Version: 2.4.1
___________________________________________________

FVM config found:
___________________________________________________

Project: my_project
Directory: C:\Users\...\my_project
Version: 3.3.10
Project Flavor: None selected
___________________________________________________

Version is currently cached locally.

Cache Path: C:\Users\...\fvm\versions\3.3.10
Channel: false
SDK Version: 3.3.10

IDE Links
VSCode: .fvm/flutter_sdk
Android Studio: C:\Users\...\my_project\.fvm\flutter_sdk


Configured env paths:
___________________________________________________

Flutter:
C:\Users\...\flutter\bin\flutter.bat

Dart:
C:\Users\...\flutter\bin\dart.bat

FVM_HOME:
not set
@jibbers42 jibbers42 added the bug Something isn't working label Mar 24, 2023
@leoafarias
Copy link
Owner

@jibbers42 can you confirm the version configured in your path is 3.3.10 also?

@jibbers42
Copy link
Author

@jibbers42 can you confirm the version configured in your path is 3.3.10 also?

It used to be and I just now switched it back to test and be sure - same issue...

> flutter --version
Flutter 3.3.10 • channel unknown • unknown source
Framework • revision 135454af32 (4 months ago) • 2022-12-15 07:36:55 -0800
Engine • revision 3316dd8728
Tools • Dart 2.18.6 • DevTools 2.15.0

> fvm flutter --version
Flutter 3.3.10 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 135454af32 (4 months ago) • 2022-12-15 07:36:55 -0800
Engine • revision 3316dd8728
Tools • Dart 2.18.6 • DevTools 2.15.0

@leoafarias
Copy link
Owner

@jibbers42 the only thing I can think of is that the Dart version is different when you are running with FVM, can you run fvm dart --version and dart --version within the project that has your script?

@jibbers42
Copy link
Author

> dart --version
Dart SDK version: 2.18.6 (stable) (Tue Dec 13 21:15:14 2022 +0000) on "windows_x64"

> fvm dart --version
Dart SDK version: 2.18.6 (stable) (Tue Dec 13 21:15:14 2022 +0000) on "windows_x64"

I didn't save the links because I wasn't confident it was related (maybe they were issues here or in other projects), but when originally searching for answers I got the impression that the work to switch how the process is launched, spawn vs start, might fix it. I'm not sure if that switch is actually happening or if it would fix it, just mentioning it in case it helps.

@leoafarias
Copy link
Owner

@jibbers42 does your CLI call dart, or flutter through a separate process?

@jibbers42
Copy link
Author

I'd guess it's a pretty standard Windows setup

Windows Terminal
Version: 1.16.10262.0
> pwsh --version
PowerShell 7.3.3

I was referring to however fvm runs dart and a change like #508. I'm trying to find whatever resource led me to think that might make a difference, but my google-fu is failing at the moment.

@leoafarias
Copy link
Owner

@jibbers42 #508 has not been merged. Also, my question was in regard to what is your CLI doing. Because if your CLI starts a new process using a process manager, that could also be causing an issue due to the compatibility problem. But it might be tough to troubleshoot without knowing what the script is doing.

@jibbers42
Copy link
Author

Oops, I read "CLI" as "terminal" and didn't really understand the question...

I had a look and the -h help path for fvm dart run .\bin\my_script.dart -h pretty much just creates a CommandRunner from args and shows the help.

I'll try to create a minimal repro project...

@jibbers42
Copy link
Author

script.dart

import 'dart:io';

void main() {
  print('stdout.terminalColumns: ${stdout.terminalColumns}');
}

I tested this script stand-alone - I didn't create a flutter project to set fvm to a specific version. Let me know if you'd like me to do those things...

> dart --version
Dart SDK version: 2.18.6 (stable) (Tue Dec 13 21:15:14 2022 +0000) on "windows_x64"

> fvm dart --version
Dart SDK version: 2.18.6 (stable) (Tue Dec 13 21:15:14 2022 +0000) on "windows_x64"

> dart run .\script.dart
stdout.terminalColumns: 132

> fvm dart run .\script.dart
Unhandled exception:
StdoutException: Could not get terminal size, OS Error: The handle is invalid.
, errno = 6
#0      Stdout._terminalSize (dart:io-patch/stdio_patch.dart:172:7)
#1      Stdout._terminalColumns (dart:io-patch/stdio_patch.dart:165:35)
#2      Stdout.terminalColumns (dart:io/stdio.dart:228:30)
#3      main (file:///C:/Users/.../script.dart:4:43)
#4      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

@leoafarias
Copy link
Owner

@jibbers42 I know what is happening; flutter is run through a process inside FVM, which is probably why that information is being lost. I suggest calling the flutter sdk directly the following way here in the documentation:

https://fvm.app/docs/guides/running_flutter#call-sdk-directly

@jibbers42
Copy link
Author

If I understand correctly, that would be a shell alias, so perhaps use Set-Alias for powershell?

Is there a solution that can follow the flutter project to different users and machines and not introduce another way to run the script beyond fvm dart ...? I guess I'd like to make a feature request to enable that, but I"m not sure what the request would actually be or if it's even possible.

@jibbers42
Copy link
Author

For now, I'll just use the whole relative path to the direct sdk in the readme examples...

Thanks for the help!

@leoafarias leoafarias added the help wanted Extra attention is needed label Apr 12, 2023
@leoafarias
Copy link
Owner

Closing as 3.0 has been released. Check again and reopen the issue if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants