sass / dart-sass

The reference implementation of Sass, written in Dart.
https://sass-lang.com/dart-sass
MIT License
3.97k stars 360 forks source link

Handle errors from filesystem watchers more gracefully #1220

Closed 0x44454c closed 3 years ago

0x44454c commented 3 years ago
Unhandled exception:
FileSystemException: Directory watcher closed unexpectedly, path = 'C:\Users\monim\Desktop\projects\dev_profile_edit'
#0      _FileSystemWatcher._listenOnSocket.<anonymous closure> (dart:io-patch/file_patch.dart:330)
#1      _ExpandStream._handleData (dart:async/stream_pipe.dart:240)
#2      _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:157)
#3      _RootZone.runUnaryGuarded (dart:async/zone.dart:1384)
#4      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357)
#5      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285)
#6      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:808)
#7      _StreamController._add (dart:async/stream_controller.dart:682)
#8      _StreamController.add (dart:async/stream_controller.dart:624)
#9      _RawSocket.read.<anonymous closure> (dart:io-patch/socket_patch.dart:1634)
#10     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1069)
#11     _microtaskLoop (dart:async/schedule_microtask.dart:41)
#12     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#13     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118)
#14     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169)

Above is the exception occurring whenever sass is used for more than 10 seconds in watch mode. It is getting stopped after 10 seconds while watching.

jathak commented 3 years ago

Native file system watchers tend to be temperamental in a way that is difficult for us to debug, especially on Windows. We can probably surface a better error message here, but it's unlikely to be something we can fix ourselves. You may want to file an issue against Dart's watcher package. I'm not able to replicate this error on my own Windows machine, so you should include some information about your machine.

You should be able to work around this by adding the --poll flag, which bypasses the OS's native watcher and just polls the watched files periodically.

nex3 commented 3 years ago

This error should be handled correctly already—it should be surfaced as a Future exception by the await for in _Watcher.watch:

https://github.com/sass/dart-sass/blob/0f68d7a5115082df93049f6df78f3f33a9fb424b/lib/src/executable/watch.dart#L126-L150

Which is awaited in watch():

https://github.com/sass/dart-sass/blob/0f68d7a5115082df93049f6df78f3f33a9fb424b/lib/src/executable/watch.dart#L55

Which is awaited in main():

https://github.com/sass/dart-sass/blob/0f68d7a5115082df93049f6df78f3f33a9fb424b/bin/sass.dart#L57

Which has backup error-handling code that should have handled this exception:

https://github.com/sass/dart-sass/blob/0f68d7a5115082df93049f6df78f3f33a9fb424b/bin/sass.dart#L109-L119

The fact that it didn't suggests that something is broken in dart:io's native watcher code. I don't think there's much more we can do to mitigate this.