Tensegritics / ClojureDart

Clojure dialect for Flutter and Dart
1.43k stars 92 forks source link

Watch process crashing on file change #57

Open arrterian opened 2 years ago

arrterian commented 2 years ago

I run the watch command from the tutorial:

clj -M -m cljd.build flutter

Platform: MacOS 11.6 Java: openjdk 17.0.1 2021-10-19 LTS Clojure CLI version: 1.11.1.1107

Then after any changes to .cljd file I got the process crash:

{:clojure.main/message
 "Execution error (IOException) at java.lang.ProcessBuilder$NullOutputStream/write (ProcessBuilder.java:442).\nStream closed\n",
 :clojure.main/triage
 {:clojure.error/class java.io.IOException,
  :clojure.error/line 442,
  :clojure.error/cause "Stream closed",
  :clojure.error/symbol
  java.lang.ProcessBuilder$NullOutputStream/write,
  :clojure.error/source "ProcessBuilder.java",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type java.io.IOException,
    :message "Stream closed",
    :at
    [java.lang.ProcessBuilder$NullOutputStream
     write
     "ProcessBuilder.java"
     442]}],
  :trace
  [[java.lang.ProcessBuilder$NullOutputStream
    write
    "ProcessBuilder.java"
    442]
   [java.io.OutputStream write "OutputStream.java" 157]
   [java.io.BufferedOutputStream
    flushBuffer
    "BufferedOutputStream.java"
    81]
   [java.io.BufferedOutputStream flush "BufferedOutputStream.java" 142]
   [sun.nio.cs.StreamEncoder implFlush "StreamEncoder.java" 318]
   [sun.nio.cs.StreamEncoder flush "StreamEncoder.java" 153]
   [java.io.OutputStreamWriter flush "OutputStreamWriter.java" 251]
   [cljd.build$compile_cli$compile_files__6707$fn__6708
    invoke
    "build.clj"
    218]
   [cljd.build$watch_dirs invokeStatic "build.clj" 56]
   [cljd.build$watch_dirs invoke "build.clj" 24]
   [cljd.build$compile_cli invokeStatic "build.clj" 236]
   [cljd.build$compile_cli doInvoke "build.clj" 175]
   [clojure.lang.RestFn invoke "RestFn.java" 457]
   [cljd.build$_main invokeStatic "build.clj" 373]
   [cljd.build$_main doInvoke "build.clj" 346]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.core$apply invokeStatic "core.clj" 665]
   [clojure.main$main_opt invokeStatic "main.clj" 514]
   [clojure.main$main_opt invoke "main.clj" 510]
   [clojure.main$main invokeStatic "main.clj" 664]
   [clojure.main$main doInvoke "main.clj" 616]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.main main "main.java" 40]],
  :cause "Stream closed"}}
cgrand commented 2 years ago

It usually happens when the flutter CLI itself crash. Can you copy all the output? Thanks!

dupuchba commented 2 years ago

πŸ‘ with @cgrand . To be sure :

print the output

TiLogic commented 2 years ago

I'm seeing this issue as well...

Following @dupuchba's instructions the following occurs:

terminal 1

git clone https://github.com/Tensegritics/ClojureDart.git
cd ClojureDart/samples/counter
clj -M -m cljd.build init sample.counter 
clj -M -m cljd.build watch
...
Compiling to Dart... @10:14
   sample.counter
   Easy peasy! 😎

terminal 2

flutter run
...
πŸ’ͺ Running with sound null safety πŸ’ͺ
...

<shift-r> hot restart OK

Performing hot restart...
Restarted application in 465ms.

<r> hot reload OK

Performing hot reload...
Reloaded 0 libraries in 104ms.

IDE (vscode)

code src/sample/counter.cljd

<cmd-s> save with or without code changes

terminal 2

<r> hot reload fails

══║ EXCEPTION CAUGHT BY WIDGETS LIBRARY β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
The following _CompileTimeError was thrown building Reify$51(dirty, state: Reify$52#fe0eb):
Unimplemented handling of missing static target

The relevant error-causing widget was:
  Reify$51
  Reify$51:file:///Users/user/dev/ClojureDart/samples/counter/lib/cljd-out/sample/counter.dart:61:56

When the exception was thrown, this was the stack:
#0      StatefulElement.build (package:flutter/src/widgets/framework.dart:4870:27)
#1      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4754:15)
#2      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4928:11)
#3      Element.rebuild (package:flutter/src/widgets/framework.dart:4477:5)
#4      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2659:19)
#5      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
#6      RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:363:5)
#7      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144:15)
#8      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1081:9)
#9      SchedulerBinding.scheduleWarmUpFrame.<anonymous closure>
(package:flutter/src/scheduler/binding.dart:862:7)
(elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)

════════════════════════════════════════════════════════════════════════════════════════════════════
Performing hot reload...
Reloaded 2 of 587 libraries in 307ms.
dupuchba commented 2 years ago

Can you paste your cljd code ? Also it's a "good" idea to use hot-restart and not hot-reload with cljd right now.

arrterian commented 2 years ago

@dupuchba

Terminal 1

clj -M -m cljd.build flutter

Lauching flutter run
More than one device connected; please specify a device with the '-d <deviceId>' flag, or use '-d all' to act on all devices.

Roman’s iPhone (mobile)             β€’ <device_id>          β€’ ios        β€’ iOS 15.4.1 19E258
iPhone SE (2nd generation) (mobile) β€’ <device_id> β€’ ios        β€’ com.apple.CoreSimulator.SimRuntime.iOS-15-2
(simulator)
macOS (desktop)                     β€’ macos                                β€’ darwin-x64 β€’ macOS 11.6 20G165 darwin-x64

BTW: It's good to have the possibility to pass parameters for flutter run

Since I have multiple targets I run in Terminal 2 following command:

flutter run -d <divice-id>

Then any changes to file lead to the error mentioned in this issue.

dupuchba commented 2 years ago

Sorry for the delay @arrterian , can you update your compiler sha and tell me if it is still bugging ? I cannot reproduce your error that's why it take so long to correct this bug :(

arrterian commented 2 years ago

Still appears on the master branch :(

error-reproducing

Gif last frame:

error-reproducing

arrterian commented 2 years ago

Actually, this is not a critical problem anymore. I just get that I did it wrong. And I could just pass options to cljd.build flutter rather than run flutter run manually in another terminal.

dupuchba commented 2 years ago

It bugs me that you have this, I am wondering if it is because you're using VS Code terminal.

PEZ commented 2 years ago

I have this too. With the project that @lambdina sets up here: https://www.youtube.com/watch?v=dfmRNTmfYVg

I am also using the VS Code internal terminal, so will try without that now.

PEZ commented 2 years ago

Same when I use terminal outside VS Code:

~/Projects/tests/clojuredart/form(:|βœ”) % clj -M -m cljd.build flutter -d macos
Warming up `.clojuredart/libs-info.edn` (helps us emit better code)

Compiling cljd.core to Dart

Compiling to Dart... @11:55
  tutorial.form
  Bravissimo! πŸ‘

Lauching flutter run -d macos
Launching lib/main.dart on macOS in debug mode...
Building macOS application...
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:x86_64, id:F942E853-FF71-5E10-8871-D1A2E6B69E9A }
{ platform:macOS, arch:arm64, id:F942E853-FF71-5E10-8871-D1A2E6B69E9A }
Syncing files to device macOS...                                    97ms

Flutter run key commands.
r Hot reload. πŸ”₯πŸ”₯πŸ”₯
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

πŸ’ͺ Running with sound null safety πŸ’ͺ

An Observatory debugger and profiler on macOS is available at: http://127.0.0.1:55208/SzyO_rtR3FA=/
The Flutter DevTools debugger and profiler on macOS is available at:
http://127.0.0.1:9100?uri=http://127.0.0.1:55208/SzyO_rtR3FA=/

Compiling to Dart... @11:55
  tutorial.form
  You rock! 🀘

Performing hot reload...

══║ EXCEPTION CAUGHT BY WIDGETS LIBRARY β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
The following _CompileTimeError was thrown building Reify$51(dirty, dependencies:
[_LocalizationsScope-[GlobalKey#30b2f]], state: Reify$52#dc40f):
Unimplemented handling of missing static target

The relevant error-causing widget was:
  Reify$51
  Reify$51:file:///Users/pez/Projects/tests/clojuredart/form/lib/cljd-out/tutorial/form.dart:90:18

When the exception was thrown, this was the stack:
#0      StatefulElement.build (package:flutter/src/widgets/framework.dart:4919:27)
#1      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4806:15)
#2      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4977:11)
#3      Element.rebuild (package:flutter/src/widgets/framework.dart:4529:5)
#4      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2659:19)
#5      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:891:21)
#6      RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:370:5)
#7      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1146:15)
#8      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1083:9)
#9      SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:864:7)
(elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)

════════════════════════════════════════════════════════════════════════════════════════════════════
Reloaded 2 of 589 libraries in 477ms.

form.cljd:

(ns tutorial.form
  "Form tutorial"
  (:require ["package:flutter/material.dart" :as m]
            [cljd.flutter.alpha :as f]))

(def my-custom-form
  (f/widget
   :with [my-controller (m/TextEditingController)]
   :context ctx
   (m/Scaffold
    :appBar (m/AppBar :title (m/Text "Retrieve Text Input"))
    :body (m/Padding :padding (m.EdgeInsets/all 16.0)
                     :child (m/TextField :controller my-controller))
    :floatingActionButton (m/FloatingActionButton
                           :onPressed
                           (fn []
                             (m/showDialog
                              :context ctx
                              :builder (fn [_]
                                         (m/AlertDialog :content
                                                        (m/Text (.text my-controller)))))
                             nil)
                           :tooltip "Show me the stuff"
                           :child (m/Icon (m.Icons/text_fields))))))

(defn main []
  (m/runApp
   (m/MaterialApp :title "Retrieve text field content"
                  :home my-custom-form)))

deps.edn

{:paths ["src"] ; where your cljd files are
 :deps {org.clojure/clojure {:mvn/version "1.10.1"}
        tensegritics/clojuredart
        {:git/url "git@github.com:tensegritics/ClojureDart.git"
         :sha "885a3797ccc756d8eb91a08223d3a52817646612"}}}

MacOS Monterey 12.3.1 on an Macbook Pro M1 Max. Using Apple Silicon Flutter, but it seems like XCode is choosing the x64 destination anyway.

Let me know what more info I can provide, or other things I can test.

vinurs commented 2 years ago

i have the same on macos m1 max

clj -M -m cljd.build flutter -d 'iPhone 11 Pro'
Warming up `.clojuredart/libs-info.edn` (helps us emit better code)

Compiling cljd.core to Dart

Compiling to Dart... @02:44
  app.main
  Easy peasy! 😎

Lauching flutter run -d iPhone 11 Pro
Launching lib/main.dart on iPhone 11 Pro in debug mode...
Running Xcode build...
Xcode build done.                                           10.1s
Syncing files to device iPhone 11 Pro...                            33ms

Flutter run key commands.
r Hot reload. πŸ”₯πŸ”₯πŸ”₯
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

πŸ’ͺ Running with sound null safety πŸ’ͺ

An Observatory debugger and profiler on iPhone 11 Pro is available at:
http://127.0.0.1:51704/wmCCpkkFZhA=/
The Flutter DevTools debugger and profiler on iPhone 11 Pro is available at:
http://127.0.0.1:9100?uri=http://127.0.0.1:51704/wmCCpkkFZhA=/

Compiling to Dart... @02:45
  app.main
  You rock! 🀘

Performing hot reload...

══║ EXCEPTION CAUGHT BY SCHEDULER LIBRARY
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
The following _CompileTimeError was thrown during a scheduler callback:
Unimplemented handling of missing static target

When the exception was thrown, this was the stack:
#0      Element.debugFillProperties (package:flutter/src/widgets/framework.dart:4400:14)
#1      StatefulElement.debugFillProperties
(package:flutter/src/widgets/framework.dart:5132:11)
#2      DiagnosticableNode.builder.<anonymous closure>
(package:flutter/src/foundation/diagnostics.dart:2992:17)
#3      DiagnosticableNode.builder (package:flutter/src/foundation/diagnostics.dart:2995:8)
#4      DiagnosticableNode.getProperties
(package:flutter/src/foundation/diagnostics.dart:3009:105)
#5      DiagnosticsProperty.toJsonMap
(package:flutter/src/foundation/diagnostics.dart:2726:57)
#6      DiagnosticsNode.toJsonList.<anonymous closure>
(package:flutter/src/foundation/diagnostics.dart:1665:19)
#7      MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
#8      ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
#9      new _GrowableList._ofEfficientLengthIterable
(dart:core-patch/growable_array.dart:189:27)
#10     new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#11     new List.of (dart:core-patch/array_patch.dart:51:28)
#12     ListIterable.toList (dart:_internal/iterable.dart:213:44)
#13     DiagnosticsNode.toJsonList (package:flutter/src/foundation/diagnostics.dart:1666:8)
#14     DiagnosticsNode.toJsonMap.<anonymous closure>
(package:flutter/src/foundation/diagnostics.dart:1628:25)
#15     DiagnosticsNode.toJsonMap (package:flutter/src/foundation/diagnostics.dart:1641:6)
#16     WidgetInspectorService._nodeToJson
(package:flutter/src/widgets/widget_inspector.dart:1517:18)
#17     WidgetInspectorService._reportStructuredError
(package:flutter/src/widgets/widget_inspector.dart:925:44)
#18     FlutterError.reportError (package:flutter/src/foundation/assertions.dart:1177:14)
#19     _debugReportException (package:flutter/src/widgets/framework.dart:6408:16)
#20     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2661:11)
#21     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:891:21)
#22     RendererBinding._handlePersistentFrameCallback
(package:flutter/src/rendering/binding.dart:370:5)
#23     SchedulerBinding._invokeFrameCallback
(package:flutter/src/scheduler/binding.dart:1146:15)
#24     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1083:9)
#25     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure>
(package:flutter/src/scheduler/binding.dart:864:7)
(elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)
═════════════════════════════════════════════════════════════════════════════════════════════
═══════
Reloaded 2 of 589 libraries in 134ms.

my main.cljd

(ns app.main
  ;; pure dart package are imported using string
  (:require ["package:flutter/material.dart" :as m]
            [cljd.flutter.alpha :as f]))

(defn main []
  (m/runApp
   (m/MaterialApp
    :title "Cljd Demo"
    :theme (m/ThemeData :primarySwatch m.Colors/blue)
    :home (f/widget
           :state [counter 0]
           :inherit [m/Theme]
           (m/Scaffold
            :appBar (m/AppBar :title (m/Text "ClojureDart Home Page vinurs"))
            :body
            (f/nest
             m/Center
             (m/Column
              :mainAxisAlignment m.MainAxisAlignment/center
              :children
              [(m/Text "You have pushed the button this many times:")
               (m/Text (str @counter)
                       :style (-> theme .textTheme .displayLarge))]))
            :floatingActionButton
            (m/FloatingActionButton
             :onPressed #(swap! counter inc)
             :tooltip "Increment"
             :child (m/Icon m.Icons/add)))))))