Skip to content

Commit

Permalink
Indicate exception types to sip
Browse files Browse the repository at this point in the history
Exposes the full Python exception when an error occurs in createInstance()
  • Loading branch information
nyalldawson committed Feb 20, 2019
1 parent 03cc355 commit 979adbb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Expand Up @@ -63,7 +63,7 @@ a pre-initialized copy of the algorithm.



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

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

Raises a QgsProcessingException if a new algorithm instance could not be created,
e.g. if there is an issue with the subclass' createInstance() method.

.. seealso:: :py:func:`initAlgorithm`
%End

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

protected:

virtual QgsProcessingAlgorithm *createInstance() const = 0 /Factory/;
virtual QgsProcessingAlgorithm *createInstance() const = 0 /Factory,VirtualErrorHandler=processing_exception_handler/;
%Docstring
Creates a new instance of the algorithm class.

Expand Down
7 changes: 5 additions & 2 deletions src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -122,9 +122,12 @@ class CORE_EXPORT QgsProcessingAlgorithm
* algorithms in a model, allowing them to adjust their behavior at run time
* according to some user configuration.
*
* Raises a QgsProcessingException if a new algorithm instance could not be created,
* e.g. if there is an issue with the subclass' createInstance() method.
*
* \see initAlgorithm()
*/
QgsProcessingAlgorithm *create( const QVariantMap &configuration = QVariantMap() ) const SIP_TRANSFERBACK;
QgsProcessingAlgorithm *create( const QVariantMap &configuration = QVariantMap() ) const SIP_THROW( QgsProcessingException ) SIP_TRANSFERBACK;

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

/**
* Initializes the algorithm using the specified \a configuration.
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgsprocessingalgrunner.py
Expand Up @@ -103,7 +103,7 @@ def test_bad_script_dont_crash(self): # spellok

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


if __name__ == '__main__':
Expand Down

0 comments on commit 979adbb

Please sign in to comment.