Report uncaught Python exceptions with a GUI popup
This commit is contained in:
@@ -21,8 +21,10 @@ HPopup {
|
||||
property alias details: details
|
||||
|
||||
property string okText: qsTr("OK")
|
||||
property string okIcon: "ok"
|
||||
property bool okEnabled: true
|
||||
property bool okClicked: false
|
||||
property string cancelText: qsTr("Cancel")
|
||||
|
||||
|
||||
Binding on height {
|
||||
@@ -40,8 +42,8 @@ HPopup {
|
||||
clickButtonOnEnter: "ok"
|
||||
|
||||
buttonModel: [
|
||||
{ name: "ok", text: okText, iconName: "ok", enabled: okEnabled},
|
||||
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
|
||||
{ name: "ok", text: okText, iconName: okIcon, enabled: okEnabled},
|
||||
{ name: "cancel", text: cancelText, iconName: "cancel" },
|
||||
]
|
||||
|
||||
buttonCallbacks: ({
|
||||
|
39
src/gui/Popups/UnexpectedErrorPopup.qml
Normal file
39
src/gui/Popups/UnexpectedErrorPopup.qml
Normal file
@@ -0,0 +1,39 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import "../Base"
|
||||
|
||||
BoxPopup {
|
||||
summary.text: qsTr("Unexpected error occured: <i>%1</i>").arg(errorType)
|
||||
summary.textFormat: Text.StyledText
|
||||
|
||||
okText: qsTr("Report")
|
||||
okIcon: "report-error"
|
||||
okEnabled: false // TODO
|
||||
cancelText: qsTr("Ignore")
|
||||
box.focusButton: "cancel"
|
||||
|
||||
|
||||
property string errorType
|
||||
property var errorArguments: []
|
||||
property string traceback: ""
|
||||
|
||||
|
||||
HScrollableTextArea {
|
||||
text: traceback || qsTr("No traceback available")
|
||||
area.readOnly: true
|
||||
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
HCheckBox {
|
||||
text: qsTr("Hide this type of error until restart")
|
||||
onCheckedChanged:
|
||||
checked ?
|
||||
window.hideErrorTypes.add(errorType) :
|
||||
window.hideErrorTypes.delete(errorType)
|
||||
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
@@ -19,21 +19,39 @@ QtObject {
|
||||
let onSuccess = py.privates.pendingCoroutines[uuid].onSuccess
|
||||
let onError = py.privates.pendingCoroutines[uuid].onError
|
||||
|
||||
delete py.privates.pendingCoroutines[uuid]
|
||||
|
||||
if (error) {
|
||||
let type = py.getattr(py.getattr(error, "__class__"), "__name__")
|
||||
let args = py.getattr(error, "args")
|
||||
const type = py.getattr(py.getattr(error, "__class__"), "__name__")
|
||||
const args = py.getattr(error, "args")
|
||||
|
||||
type === "CancelledError" ?
|
||||
console.warn(`python: cancelled: ${uuid}`) :
|
||||
if (type === "CancelledError") {
|
||||
console.warn(`python: cancelled: ${uuid}`)
|
||||
return
|
||||
}
|
||||
|
||||
onError ?
|
||||
onError(type, args, error, traceback) :
|
||||
if (onError) {
|
||||
onError(type, args, error, traceback)
|
||||
return
|
||||
}
|
||||
|
||||
console.error(`python: ${uuid}\n${traceback}`)
|
||||
|
||||
} else if (onSuccess) { onSuccess(result) }
|
||||
if (window.hideErrorTypes.has(type)) {
|
||||
console.warn(
|
||||
"Not showing error popup for this type due to user choice"
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
delete py.privates.pendingCoroutines[uuid]
|
||||
utils.makePopup(
|
||||
"Popups/UnexpectedErrorPopup.qml",
|
||||
window,
|
||||
{ errorType: type, errorArguments: args, traceback },
|
||||
)
|
||||
}
|
||||
|
||||
if (onSuccess) onSuccess(result)
|
||||
}
|
||||
|
||||
|
||||
|
@@ -44,6 +44,8 @@ ApplicationWindow {
|
||||
|
||||
property var theme: null
|
||||
|
||||
property var hideErrorTypes: new Set()
|
||||
|
||||
readonly property alias py: py
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user