[ui] ErrorHandler: analyse error (only used by computation for now)

This commit is contained in:
Julien-Haudegond 2020-09-03 14:56:35 +02:00
parent 95c7a9b87f
commit 78f7febeb7
4 changed files with 49 additions and 20 deletions

View file

@ -186,7 +186,9 @@ class TaskManager(BaseObject):
if chunksInConflict:
chunksStatus = set([chunk.status.status.name for chunk in chunksInConflict])
chunksName = [node.name for node in chunksInConflict]
msg = 'TaskManager.compute(): WARNING - Some nodes are already submitted with status: {}\nNodes: {}'.format(
# Syntax and terms are used on QML side to recognize the error
msg = '[COMPUTATION] Already Submitted:\n' \
'WARNING - Some nodes are already submitted with status: {}\nNodes: {}'.format(
', '.join(chunksStatus),
', '.join(chunksName)
)

View file

@ -0,0 +1,32 @@
.pragma library
/**
* Analyse raised errors.
* Works only if errors are written with this specific syntax:
* [Context] ErrorType: ErrorMessage
*
* Maybe it would be better to handle errors on Python side but it should be harder to handle Dialog customization
*/
function analyseError(error) {
const msg = error.toString()
// The use of [^] is like . but it takes in count every character including \n (works as a double negation)
// Group 1: Context
// Group 2: ErrorType
// Group 3: ErrorMessage
const regex = /\[(.*)\]\s(.*):([^]*)/
if(!regex.test(msg))
return {
context: "",
type: "",
msg: ""
}
const data = regex.exec(msg)
return {
context: data[1],
type: data[2],
msg: data[3].startsWith("\n") ? data[3].slice(1) : data[3]
}
}

View file

@ -4,6 +4,7 @@ singleton Colors 1.0 Colors.qml
SortFilterDelegateModel 1.0 SortFilterDelegateModel.qml
Request 1.0 request.js
Format 1.0 format.js
ErrorHandler 1.0 errorHandler.js
# using singleton here causes random crash at application exit
# singleton Clipboard 1.0 Clipboard.qml
# singleton Filepath 1.0 Filepath.qml

View file

@ -166,9 +166,9 @@ ApplicationWindow {
_reconstruction.execute(node)
}
catch (error) {
let msg = error.toString()
msg = msg.split("Error: ")[1] // Remove the QML prefix
computeErrorDialog.openError(msg, node)
const data = ErrorHandler.analyseError(error)
if(data.context === "COMPUTATION")
computeErrorDialog.openError(data.type, data.msg, node)
}
}
}
@ -180,29 +180,26 @@ ApplicationWindow {
MessageDialog {
id: computeErrorDialog
property int errorId // Used to specify signals' behavior
property string errorType // Used to specify signals' behavior
property var currentNode: null
function openError(msg, node) {
// Open specific dialog if the error is related to the following method
// There is maybe a better way to handle this
if(msg.startsWith("TaskManager.compute()"))
this.setupPendingStatusError(msg, node)
else
this.onlyDisplayError(msg)
function openError(type, msg, node) {
errorType = type
switch(type) {
case "Already Submitted": this.setupPendingStatusError(msg, node); break
default: this.onlyDisplayError(msg)
}
this.open()
}
function onlyDisplayError(msg) {
errorId = 0
text = msg
standardButtons = Dialog.Ok
}
function setupPendingStatusError(msg, node) {
errorId = 1
currentNode = node
text = msg + "\n\nDo you want to Clear Pending Status and Start Computing?"
@ -217,17 +214,14 @@ ApplicationWindow {
text: ""
onAccepted: {
switch(errorId) {
case 0: {
close()
break
}
case 1: {
switch(errorType) {
case "Already Submitted": {
close()
_reconstruction.graph.clearSubmittedNodes()
_reconstruction.execute(currentNode)
break
}
default: close()
}
}