sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Dart error - Invocation: 'dart run' Exception: FileSystemException

Open camstuart opened this issue 6 months ago • 2 comments

OS: mac 15.5 (24F74) Dart SDK version: 3.8.1 (stable) (Wed May 28 00:47:25 2025 -0700) on "macos_arm64"

Background: I am building a cli app, and attempting to use an external file watcher (watchexec 2.3.2 (2025-05-18)) to run my cli app on file change.

Error: I have tried multiple methods with debounce / sleep but cannot get this to work, the following commands:

watchexec -n --stop-timeout 5s -- dart run watchexec -- 'sleep 3; dart run' watchexec --debounce 500ms --exts dart -- dart run

All result in the same error:

An unexpected error was encountered by the Dart CLI.
Please file an issue at https://github.com/dart-lang/sdk/issues/new with the following details:

Invocation: 'dart run'
Exception: 'FileSystemException: Failed to get type of stdio handle (fd 1), path = '' (OS Error: Bad file descriptor, errno = 9)'
Stack Trace:
#0      _StdIOUtils._getStdioOutputStream (dart:io-patch/stdio_patch.dart:35:7)
#1      _stdout (dart:io/stdio.dart:505:36)
#2      _stdout (dart:io/stdio.dart)
#3      stdout (dart:io/stdio.dart:532:41)
#4      dartdevUsageLineLength (package:dartdev/src/utils.dart:19:5)
#5      globalDartdevOptionsParser (package:dartdev/src/utils.dart:76:22)
#6      new DartdevRunner (package:dartdev/dartdev.dart:89:21)
#7      runDartdev (package:dartdev/dartdev.dart:46:20)
#8      main (file:///Volumes/Work/s/w/ir/x/w/sdk/pkg/dartdev/bin/dartdev.dart:13:11)
#9      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:310:33)
#10     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:193:12)

[Command exited with 255]

Is this truly an issue with dartdev? or is there an alternative approach to solving this?

I am having the same problem when attempting to run tests on file change as well

camstuart avatar Jun 10 '25 13:06 camstuart

From the exception, it looks like we're having trouble opening stdio at startup. I suspect that watchexec is starting the dart process in a manner we haven't encountered before (and I'm not 100% sure this should be supported).

cc @bkonyi and @brianquinlan

devoncarew avatar Jun 10 '25 16:06 devoncarew

Understandable, I'm not fussed about the particular tooling, I'm more looking for a reliable way of executing my cli app and more importantly tests as I develop.

I am yet to try flutter but I believe hot reload is one of its celebrated DX features.

Something akin to that is what I'm seeking for "other" projects

camstuart avatar Jun 10 '25 21:06 camstuart