-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QML API 1.2: Handle JS exceptions in callbacks from Python
Also improve error message in pyotherside.send() callback handler to include filename and line number.
- Loading branch information
Showing
4 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import QtQuick 2.0 | ||
import io.thp.pyotherside 1.2 | ||
|
||
// Test if PyOtherSide correctly reports JS errors happening in callbacks | ||
// in signal error(string traceback) for both imports and function calls. | ||
|
||
Python { | ||
property var tests: ([]) | ||
|
||
function test_next() { | ||
if (tests.length) { | ||
tests.pop()(); | ||
} else { | ||
console.log('Tests done'); | ||
Qt.quit(); | ||
} | ||
} | ||
|
||
Component.onCompleted: { | ||
tests.unshift(function () { | ||
console.log('Expecting ReferenceError for "invalid" on import'); | ||
importModule('os', function (success) { | ||
invalid; | ||
}); | ||
}); | ||
tests.unshift(function() { | ||
console.log('Expecting TypeError for "lock" property'); | ||
call('os.getcwd', [], function (result) { | ||
console.lock(result); | ||
}); | ||
}); | ||
test_next(); | ||
} | ||
|
||
onError: { | ||
// Remove full path to .qml file | ||
var msg = traceback.replace(Qt.resolvedUrl('.'), ''); | ||
console.log('Got error: ' + msg); | ||
test_next(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Expecting ReferenceError for "invalid" on import | ||
Got error: test_callback_errors.qml:23: ReferenceError: invalid is not defined | ||
Expecting TypeError for "lock" property | ||
Got error: test_callback_errors.qml:29: TypeError: Property 'lock' of object [object Object] is not a function | ||
Tests done |