Skip to content

Commit 979adbb

Browse files
committed
Indicate exception types to sip
Exposes the full Python exception when an error occurs in createInstance()
1 parent 03cc355 commit 979adbb

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in

+5-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ a pre-initialized copy of the algorithm.
6363

6464

6565

66-
QgsProcessingAlgorithm *create( const QVariantMap &configuration = QVariantMap() ) const /TransferBack/;
66+
QgsProcessingAlgorithm *create( const QVariantMap &configuration = QVariantMap() ) const throw( QgsProcessingException ) /TransferBack/;
6767
%Docstring
6868
Creates a copy of the algorithm, ready for execution.
6969

@@ -76,6 +76,9 @@ and outputs according to this configuration. This is generally used only for
7676
algorithms in a model, allowing them to adjust their behavior at run time
7777
according to some user configuration.
7878

79+
Raises a QgsProcessingException if a new algorithm instance could not be created,
80+
e.g. if there is an issue with the subclass' createInstance() method.
81+
7982
.. seealso:: :py:func:`initAlgorithm`
8083
%End
8184

@@ -401,7 +404,7 @@ Associates this algorithm with its provider. No transfer of ownership is involve
401404

402405
protected:
403406

404-
virtual QgsProcessingAlgorithm *createInstance() const = 0 /Factory/;
407+
virtual QgsProcessingAlgorithm *createInstance() const = 0 /Factory,VirtualErrorHandler=processing_exception_handler/;
405408
%Docstring
406409
Creates a new instance of the algorithm class.
407410

src/core/processing/qgsprocessingalgorithm.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ class CORE_EXPORT QgsProcessingAlgorithm
122122
* algorithms in a model, allowing them to adjust their behavior at run time
123123
* according to some user configuration.
124124
*
125+
* Raises a QgsProcessingException if a new algorithm instance could not be created,
126+
* e.g. if there is an issue with the subclass' createInstance() method.
127+
*
125128
* \see initAlgorithm()
126129
*/
127-
QgsProcessingAlgorithm *create( const QVariantMap &configuration = QVariantMap() ) const SIP_TRANSFERBACK;
130+
QgsProcessingAlgorithm *create( const QVariantMap &configuration = QVariantMap() ) const SIP_THROW( QgsProcessingException ) SIP_TRANSFERBACK;
128131

129132
/**
130133
* Returns the algorithm name, used for identifying the algorithm. This string
@@ -409,7 +412,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
409412
*
410413
* This method should return a 'pristine' instance of the algorithm class.
411414
*/
412-
virtual QgsProcessingAlgorithm *createInstance() const = 0 SIP_FACTORY;
415+
virtual QgsProcessingAlgorithm *createInstance() const = 0 SIP_FACTORY SIP_VIRTUALERRORHANDLER( processing_exception_handler );
413416

414417
/**
415418
* Initializes the algorithm using the specified \a configuration.

tests/src/python/test_qgsprocessingalgrunner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_bad_script_dont_crash(self): # spellok
103103

104104
task = QgsProcessingAlgRunnerTask(CrashingProcessingAlgorithm(), {}, context=context, feedback=feedback)
105105
self.assertTrue(task.isCanceled())
106-
self.assertEqual(feedback._error, 'Error creating algorithm from createInstance()')
106+
self.assertIn('name \'ExampleProcessingAlgorithm\' is not defined', feedback._error)
107107

108108

109109
if __name__ == '__main__':

0 commit comments

Comments
 (0)