Skip to content

Commit c36cef8

Browse files
authored
Merge pull request #438 from MetaCell/feature/381-error-dialog-management
Feature/381 error dialog management
2 parents 849938f + 9771859 commit c36cef8

4 files changed

Lines changed: 262 additions & 203 deletions

File tree

netpyne_ui/netpyne_geppetto.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from shutil import copyfile
1515
from dacite import from_dict
1616
import base64
17+
import jsonpickle
1718

1819
import neuron
1920
import numpy as np
@@ -266,6 +267,7 @@ def simulateNetPyNEModelInGeppetto(self, args):
266267
"""
267268
allTrials = args.get('allTrials', True)
268269
use_prev_inst = args.get('usePrevInst', False)
270+
sim_id = args.get('simId', 0)
269271

270272
try:
271273
experiment = experiments.get_current()
@@ -289,17 +291,17 @@ def simulateNetPyNEModelInGeppetto(self, args):
289291
return self.simulate_single_model(experiment, use_prev_inst)
290292
except Exception:
291293
experiment.state = model.ExperimentState.ERROR
292-
message = "Unknown error during simulation of Experiment"
294+
message = ("Unknown error during simulation of Experiment. SimulationId %i" % sim_id)
293295
logging.exception(message)
294-
return utils.getJSONError("Unknown error during simulation of Experiment", sys.exc_info())
296+
return utils.getJSONError("Unknown error during simulation of Experiment", sys.exc_info(), { "sim_id": sim_id})
295297

296298
else:
297299
return self.simulate_single_model(use_prev_inst=use_prev_inst)
298300

299-
except Exception:
300-
message = "Error while simulating the NetPyNE model"
301+
except Exception as e :
302+
message = ("Error while simulating the NetPyNE model: %s. SimulationId %f" % (e, sim_id))
301303
logging.exception(message)
302-
return utils.getJSONError(message, sys.exc_info())
304+
return utils.getJSONError(message, sys.exc_info(), { "sim_id": sim_id})
303305

304306
def _prepare_simulation_files(self, experiment: model.Experiment = None, use_prev_inst: bool = False) -> str:
305307
"""Prepares template files and netpyne model files for a single simulation """
@@ -647,6 +649,8 @@ def instantiateNetPyNEModel(self):
647649
saveData = sim.allSimData if hasattr(sim, 'allSimData') and 'spkt' in sim.allSimData.keys() and len(
648650
sim.allSimData['spkt']) > 0 else False
649651

652+
#netcoded = jsonpickle.encode(self.netParams, unpicklable=False)
653+
#simcoded = jsonpickle.encode(self.simConfig, unpicklable=False)
650654
sim.create(self.netParams, self.simConfig)
651655
sim.net.defineCellShapes() # creates 3d pt for cells with stylized geometries
652656
sim.gatherData(gatherLFP=False)

webapp/Utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ const Utils = {
195195
} else if (Object.prototype.hasOwnProperty.call(parsedData, 'websocket')) {
196196
error.message = parsedData.websocket;
197197
}
198+
if (Object.prototype.hasOwnProperty.call(parsedData, 'additional_info')) {
199+
error.additionalInfo = parsedData.additional_info ;
200+
}
198201
return error;
199202
}
200203
return null;

webapp/redux/middleware/middleware.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const processError = (response) => {
3939
return {
4040
errorMessage: parsedResponse.message,
4141
errorDetails: parsedResponse.details,
42+
additionalInfo: parsedResponse.additionalInfo
4243
};
4344
}
4445
return false;
@@ -106,6 +107,26 @@ const simulateNetwork = (payload) => createSimulateBackendCall(
106107
GEPPETTO.Resources.RUNNING_SIMULATION,
107108
);
108109

110+
class PythonMessageFilter {
111+
errorIds = new Set();
112+
shouldLaunch(e) {
113+
const errorId = e.additionalInfo?.sim_id ;
114+
if (!errorId)
115+
return true ;
116+
if (errorId)
117+
{
118+
if(this.errorIds.has(errorId))
119+
return false ;
120+
else {
121+
this.errorIds.add(errorId);
122+
return true ;
123+
}
124+
}
125+
}
126+
}
127+
128+
const errorMessageFilter = new PythonMessageFilter();
129+
109130
export default (store) => (next) => (action) => {
110131
const switchLayoutAction = (edit = true, reset = true) => {
111132
previousLayout[store.getState().general.editMode ? 'edit' : 'network'] = store.getState().layout;
@@ -129,7 +150,10 @@ export default (store) => (next) => (action) => {
129150

130151
const pythonErrorCallback = (error) => {
131152
console.debug(Utils.getPlainStackTrace(error.errorDetails));
132-
return next(openBackendErrorDialog(error));
153+
if (errorMessageFilter.shouldLaunch(error))
154+
return next(openBackendErrorDialog(error));
155+
else
156+
return next(action);
133157
};
134158

135159
switch (action.type) {
@@ -166,12 +190,14 @@ export default (store) => (next) => (action) => {
166190
break;
167191
}
168192
case CREATE_SIMULATE_NETWORK: {
169-
simulateNetwork({ allTrials: false })
193+
const payload = { allTrials: false, simId: new Date().getTime() }
194+
simulateNetwork(payload)
170195
.then(toNetworkCallback(false), pythonErrorCallback);
171196
break;
172197
}
173198
case SIMULATE_NETWORK:
174-
simulateNetwork({ allTrials: action.payload, usePrevInst: false })
199+
const payload = { allTrials: action.payload, simId: new Date().getTime(), usePrevInst: false }
200+
simulateNetwork(payload)
175201
.then(toNetworkCallback(false), pythonErrorCallback);
176202
break;
177203
case PYTHON_CALL: {

0 commit comments

Comments
 (0)