You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default exceptions raised by library keywords stop executing the current test (except for possible teardown) and move execution to the next test. We have, however, some special exceptions that change this logic:
Continuable failures allow execution to continue. The test will be marked failed in the end anyway.
Fatal errors stop the whole test execution.
Skip marks the test skipped, not failed.
The way users can mark exceptions continuable or fatal is by adding special attribute ROBOT_CONTINUE_ON_FAILURE or ROBOT_EXIT_ON_FAILURE, respectively, and the plan is to support the same approach with skip as well. There have been two reasons for using special attributes instead of exposing custom exceptions via the robot.api module:
Attributes work also with Java based exceptions when using Jython.
We wanted it to be possible to write library code without needing to have a dependency to the robot module.
Both of the above reasons are still valid, but it would nevertheless often be useful to be able to import custom exceptions directly without a need to create them. I propose the following:
Create custom exceptions for continuable failures, fatal errors and skip.
Expose them via the robot.api module.
Internally keep using the special attributes for detecting these special exceptions. This means that all old code will continue to work.
The hardest part of implementing this issue is, as it often is, naming:
Where exactly to put these exceptions? Should they go directly to robot.api or possibly a submodule like robot.api.error? Most of the API is exposed directly via robot.api (most of the stuff is implemented elsewhere) but we also have robot.api.logger and robot.api.deco. I consider these somewhat special cases and believe it would be best to put exceptions directly to robot.api.
What exception names to use?
FatalError sounds like a good name for fatal errors.
Continuable failure could be simply ContinuableFailure but we could also consider something like SoftFailure to use terminology other tools (at least TestNG) uses. This terminology change would require updating the User Guide and would require its own issue.
Skipping could be implemented with with SkipExecution or just Skip.
Regardless the names we decide to use, I believe all exceptions should use another special attribute ROBOT_SUPPRESS_NAME to avoid showing the actual exception name in the final error message.
If we add and expose exceptions for special cases, should we also add and expose keywords for normal failures? We could add Failure that extends AssertionError to match ContinuableFailure (or SoftFailure) and FatalError (or FatalFailure).
If we add Failure to be used with normal failing validations, should we also add Error to be used with invalid usages and other non-validation related failures? Robot doesn't separate failures and errors but on library level there's a semantic difference.
Should we expose existing PassExecution? It's used by the Pass Execution keyword and can mark the test passed without executing it fully. The idea has been that libraries shouldn't be allowed to do that, but they can already now import this exception from robot.errors which is not considered to be part of the public API and this functionality isn't documented either. I don't see any harm with this but I'm not sure is this worth the effort either.
Should we expose existing ContinueForLoop, ExitForLoop and ReturnFromKeyword? I think that's not a good idea as these exceptions are used for internal communication related to Robot syntax.
The more I think about it, the more I like the term "soft failure" over "continuable failure". I submitted #3692 about changing the terminology with an idea to do that already in RF 4.0. If there are objections, the decision can still be reverted.
Failure and Error are basically aliases for AssertionError and RuntimeError, respectively, but they also act as base classes for ContinuableFailure and FatalError.
Decided to use ContinuableFailure, not SoftFailure, because there weren't that much interest towards renaming the terminology (#3692). ContinuableFailure also better explains how the exception behaves.
These exceptions are implemented in new robot.api.exceptions module but they are also exposed directly via the robot.api package.
@adiralashiva8 You ought to be able to prefix the message with *HTML* like *HTML* <b>Skipped from execution</b> like you can with all error messages. I like the idea to add a separate html argument, though. If you submit an issue about it, we could add it in the future.
HTML support was added by the commit above. A functional change caused by this change is that these exceptions now require a message. That means, for example, that
raise SkipExecution
doesn't work anymore and you need to use
raise SkipExecution('Some message')
instead. I consider that good but if someone has use cases for raising these exceptions without a message changing this can be still changed.
Activity
pekkaklarck commentedon Sep 28, 2020
The hardest part of implementing this issue is, as it often is, naming:
Where exactly to put these exceptions? Should they go directly to
robot.apior possibly a submodule likerobot.api.error? Most of the API is exposed directly viarobot.api(most of the stuff is implemented elsewhere) but we also haverobot.api.loggerandrobot.api.deco. I consider these somewhat special cases and believe it would be best to put exceptions directly torobot.api.What exception names to use?
FatalErrorsounds like a good name for fatal errors.Continuable failure could be simply
ContinuableFailurebut we could also consider something likeSoftFailureto use terminology other tools (at least TestNG) uses. This terminology change would require updating the User Guide and would require its own issue.Skipping could be implemented with with
SkipExecutionor justSkip.Regardless the names we decide to use, I believe all exceptions should use another special attribute
ROBOT_SUPPRESS_NAMEto avoid showing the actual exception name in the final error message.aaltat commentedon Sep 28, 2020
I vote for
ContinuableFailurepekkaklarck commentedon Sep 28, 2020
Other things to consider:
If we add and expose exceptions for special cases, should we also add and expose keywords for normal failures? We could add
Failurethat extendsAssertionErrorto matchContinuableFailure(orSoftFailure) andFatalError(orFatalFailure).If we add
Failureto be used with normal failing validations, should we also addErrorto be used with invalid usages and other non-validation related failures? Robot doesn't separate failures and errors but on library level there's a semantic difference.Should we expose existing
PassExecution? It's used by thePass Executionkeyword and can mark the test passed without executing it fully. The idea has been that libraries shouldn't be allowed to do that, but they can already now import this exception fromrobot.errorswhich is not considered to be part of the public API and this functionality isn't documented either. I don't see any harm with this but I'm not sure is this worth the effort either.Should we expose existing
ContinueForLoop,ExitForLoopandReturnFromKeyword? I think that's not a good idea as these exceptions are used for internal communication related to Robot syntax.pekkaklarck commentedon Oct 1, 2020
The more I think about it, the more I like the term "soft failure" over "continuable failure". I submitted #3692 about changing the terminology with an idea to do that already in RF 4.0. If there are objections, the decision can still be reverted.
pekkaklarck commentedon Oct 15, 2020
These exceptions were created in 02bf414:
Failure and Error are basically aliases for AssertionError and RuntimeError, respectively, but they also act as base classes for ContinuableFailure and FatalError.
Decided to use ContinuableFailure, not SoftFailure, because there weren't that much interest towards renaming the terminology (#3692). ContinuableFailure also better explains how the exception behaves.
These exceptions are implemented in new
robot.api.exceptionsmodule but they are also exposed directly via therobot.apipackage.adiralashiva8 commentedon Nov 4, 2020
Need html message format support while raising exceptions
Example:
Current implementation doesn't support this.
Create and expose exceptions for libraries to use.
pekkaklarck commentedon Feb 26, 2021
@adiralashiva8 You ought to be able to prefix the message with
*HTML*like*HTML* <b>Skipped from execution</b>like you can with all error messages. I like the idea to add a separatehtmlargument, though. If you submit an issue about it, we could add it in the future.pekkaklarck commentedon Mar 3, 2021
#3866 was submitted about supporting HTML messages. I think that's a good idea and it's so easy to implement that I'll do that still be fore RF 4.0.
Add HTML support to exceptions exposed via robot.api.
pekkaklarck commentedon Mar 3, 2021
HTML support was added by the commit above. A functional change caused by this change is that these exceptions now require a message. That means, for example, that
doesn't work anymore and you need to use
instead. I consider that good but if someone has use cases for raising these exceptions without a message changing this can be still changed.