1- import {
2- UPDATE_CARDS , CREATE_NETWORK , CREATE_SIMULATE_NETWORK , PYTHON_CALL , SIMULATE_NETWORK , SHOW_NETWORK ,
1+ import {
2+ UPDATE_CARDS , CREATE_NETWORK , CREATE_SIMULATE_NETWORK , PYTHON_CALL , SIMULATE_NETWORK , SHOW_NETWORK ,
33 editModel , EDIT_MODEL , LOAD_TUTORIAL , RESET_MODEL , setDefaultWidgets
44} from '../actions/general' ;
55import FLEXLAYOUT_DEFAULT_STATE from '../../components/layout/defaultLayout' ;
@@ -16,32 +16,35 @@ let previousLayout = { edit: undefined, network: undefined };
1616
1717
1818export default store => next => action => {
19-
2019
2120 const switchLayoutAction = ( edit = true , reset = true ) => {
2221 previousLayout [ store . getState ( ) . general . editMode ? 'edit' : 'network' ] = store . getState ( ) . layout ;
2322 if ( reset ) {
2423 previousLayout = { edit : undefined , network : undefined } ;
2524 }
26- return next ( edit
27- ? previousLayout . edit ? setLayout ( previousLayout . edit ) : setWidgets ( { ...Constants . EDIT_WIDGETS } )
25+ return next ( edit
26+ ? previousLayout . edit ? setLayout ( previousLayout . edit ) : setWidgets ( { ...Constants . EDIT_WIDGETS } )
2827 : previousLayout . network ? setLayout ( previousLayout . network ) : setWidgets ( { ...Constants . DEFAULT_NETWORK_WIDGETS } ) ) ;
2928 }
29+
3030 const toNetworkCallback = reset => ( ) => {
31-
3231 switchLayoutAction ( false , reset ) ;
3332 next ( action ) ;
3433 } ;
3534
36- const pythonErrorCallback = errorPayload => next ( openBackendErrorDialog ( errorPayload . message ) ) ;
35+ const pythonErrorCallback = error => {
36+ console . debug ( Utils . getPlainStackTrace ( error . errorDetails ) )
37+ return next ( openBackendErrorDialog ( error ) ) ;
38+ } ;
39+
3740 switch ( action . type ) {
3841
3942 case UPDATE_CARDS :
4043 console . log ( "Triggered card update" )
4144 next ( action ) ;
4245 break ;
4346 case SHOW_NETWORK :
44-
47+
4548 switchLayoutAction ( false , false ) ;
4649 next ( action ) ;
4750 break ;
@@ -59,7 +62,7 @@ export default store => next => action => {
5962 ) ;
6063 break
6164 }
62- case CREATE_NETWORK :{
65+ case CREATE_NETWORK :{
6366 instantiateNetwork ( { } ) . then ( toNetworkCallback ( false ) , pythonErrorCallback ) ;
6467 break ;
6568 }
@@ -82,7 +85,7 @@ export default store => next => action => {
8285 case NETPYNE_COMMANDS . deleteModel :
8386 next ( editModel ) ;
8487 switchLayoutAction ( true , true ) ;
85-
88+
8689 break ;
8790 default :
8891 break ;
@@ -95,80 +98,76 @@ export default store => next => action => {
9598 case LOAD_TUTORIAL : {
9699 const tutName = action . payload . replace ( '.py' , '' )
97100 GEPPETTO . trigger ( GEPPETTO . Events . Show_spinner , `Loading tutorial ${ tutName } ` ) ;
98-
101+
99102 const params = {
100103 modFolder : 'mod' ,
101104 loadMod : false ,
102105 compileMod : false ,
103106
104- netParamsPath :"." ,
107+ netParamsPath : "." ,
105108 netParamsModuleName : tutName ,
106109 netParamsVariable : "netParams" ,
107110
108- simConfigPath :"." ,
111+ simConfigPath : "." ,
109112 simConfigModuleName : tutName ,
110113 simConfigVariable : "simConfig" ,
111-
112114 }
113115
114- pythonCall ( { cmd : 'netpyne_geppetto.importModel' , args :params } )
116+ pythonCall ( { cmd : 'netpyne_geppetto.importModel' , args : params } )
115117 . then ( response => console . log ( response ) )
116118 break
117119 }
118120 default : {
119121 next ( action ) ;
120122 }
121123 }
122-
123-
124124}
125125
126-
127126const instantiateNetwork = payload => createSimulateBackendCall (
128127 NETPYNE_COMMANDS . instantiateModel ,
129128 payload ,
130129 "The NetPyNE model is getting instantiated..." ,
131130 GEPPETTO . Resources . INSTANTIATING_MODEL )
132131
133-
134- const simulateNetwork = payload =>
132+ const simulateNetwork = payload =>
135133 createSimulateBackendCall (
136134 NETPYNE_COMMANDS . simulateModel ,
137135 payload ,
138136 "The NetPyNE model is getting simulated..." ,
139137 GEPPETTO . Resources . RUNNING_SIMULATION
140138 )
141139
142-
143140const createSimulateBackendCall = async ( cmd , payload , consoleMessage , spinnerType ) => {
144141 GEPPETTO . CommandController . log ( consoleMessage ) ;
145142 GEPPETTO . trigger ( GEPPETTO . Events . Show_spinner , spinnerType ) ;
146143
147-
148144 const response = await Utils . evalPythonMessage ( cmd , [ payload ] ) ;
149145 console . log ( 'Python response' , response ) ;
150146 GEPPETTO . trigger ( GEPPETTO . Events . Hide_spinner ) ;
151147 const responsePayload = processError ( response ) ;
152148 console . log ( 'Python payload' , responsePayload ) ;
149+
153150 if ( responsePayload ) {
154- console . error ( responsePayload . errorDetails . replace ( / \u001b \[ . * ? m / g , '' ) )
155- throw new Error ( responsePayload . errorMessage ) ;
151+ throw responsePayload
152+
156153 } else {
157154 GEPPETTO . trigger ( GEPPETTO . Events . Show_spinner , GEPPETTO . Resources . PARSING_MODEL ) ;
158-
155+
159156 dehydrateCanvas ( )
160157
161158 GEPPETTO . Manager . loadModel ( response ) ;
162159 GEPPETTO . CommandController . log ( 'Instantiation / Simulation completed.' ) ;
163-
164160 }
165161 return response ;
166162}
167163
168164export const processError = response => {
169- var parsedResponse = Utils . getErrorResponse ( response ) ;
165+ const parsedResponse = Utils . getErrorResponse ( response ) ;
170166 if ( parsedResponse ) {
171- return { errorMessage : parsedResponse [ 'message' ] , errorDetails : parsedResponse [ 'details' ] }
167+ return {
168+ errorMessage : parsedResponse [ 'message' ] ,
169+ errorDetails : parsedResponse [ 'details' ]
170+ }
172171 }
173172 return false
174173}
@@ -177,14 +176,14 @@ const pythonCall = async ({ cmd, args }) => {
177176 const response = await Utils . evalPythonMessage ( cmd , [ args ] )
178177 const errorPayload = processError ( response ) ;
179178 GEPPETTO . trigger ( GEPPETTO . Events . Hide_spinner ) ;
179+
180180 if ( errorPayload ) {
181- console . error ( errorPayload . errorDetails . replace ( / \u001b \[ . * ? m / g , '' ) )
182- throw new Error ( errorPayload . errorMessage ) ;
183- }
181+ throw errorPayload
182+ }
183+
184184 return response ;
185185}
186186
187-
188187const dehydrateCanvas = ( ) => {
189188 if ( 'CanvasContainer' in window ) {
190189 CanvasContainer . engine . reset ( )
0 commit comments