@@ -5,13 +5,16 @@ defmodule Expert.EngineNode do
55 use Expert.Project.Progress.Support
66
77 defmodule State do
8+ require Logger
9+
810 defstruct [
911 :project ,
1012 :port ,
1113 :cookie ,
1214 :stopped_by ,
1315 :stop_timeout ,
1416 :started_by ,
17+ :last_message ,
1518 :status
1619 ]
1720
@@ -103,6 +106,19 @@ defmodule Expert.EngineNode do
103106 end
104107 end
105108
109+ def on_exit_status ( % __MODULE__ { } = state , exit_status ) do
110+ if exit_status > 0 do
111+ GenLSP . error (
112+ Expert . get_lsp ( ) ,
113+ "Node exited with status #{ exit_status } , last message: #{ to_string ( state . last_message ) } "
114+ )
115+ else
116+ Logger . debug ( "Node exited with status 0" )
117+ end
118+
119+ % { state | status: :stopped }
120+ end
121+
106122 def maybe_reply_to_stopper ( % State { stopped_by: stopped_by } = state )
107123 when is_tuple ( stopped_by ) do
108124 GenServer . reply ( state . stopped_by , :ok )
@@ -252,6 +268,10 @@ defmodule Expert.EngineNode do
252268 Logger . debug ( "Building engine: #{ to_string ( data ) } " )
253269 wait_for_engine ( port , data )
254270
271+ { ^ port , { :exit_status , status } } ->
272+ Logger . debug ( "Engine build script exited with status: #{ to_string ( status ) } " )
273+ { :error , { :exit_status , status } , last_line }
274+
255275 { :EXIT , ^ port , reason } ->
256276 Logger . error ( "Engine build script exited with reason: #{ inspect ( reason ) } #{ last_line } " )
257277 { :error , reason , last_line }
@@ -372,10 +392,17 @@ defmodule Expert.EngineNode do
372392 { :stop , :shutdown , state }
373393 end
374394
395+ @ impl true
396+ def handle_info ( { _port , { :exit_status , exit_status } } , % State { } = state ) do
397+ state = State . on_exit_status ( state , exit_status )
398+
399+ { :stop , :shutdown , state }
400+ end
401+
375402 @ impl true
376403 def handle_info ( { _port , { :data , message } } , % State { } = state ) do
377404 Logger . debug ( "Node port message: #{ to_string ( message ) } " )
378- { :noreply , state }
405+ { :noreply , % { state | last_message: message } }
379406 end
380407
381408 @ impl true
0 commit comments