result_handling_policies.h
Go to the documentation of this file.
1
#pragma once
2
3
namespace
armarx::skills::client
4
{
5
6
/**
7
* @brief Result handling policies.
8
*
9
* These policies are meant to be used to handle common use-cases in handling outputs of skill
10
* executions to avoid boilerplate. Since the skill outputs should be std::expected and
11
* expected is defined as [[nodiscard]], unhandled outputs will result in compiler warnings.
12
* Thus, to get rid of the warnings, the output must be stored in a local variable and handled
13
* as such:
14
*
15
* ```cpp
16
* auto result = skill({.params = …});
17
* if (result != Success)
18
* {
19
* <handling the error or ignoring the error or printing it or ...>
20
* }
21
* ```
22
*
23
* The purpose of these policies is to allow skill business object authors to define operators
24
* to handle common use-cases in a one liner. Specifically, by overwriting operator||() and the
25
* given policy as parameter as follows:
26
*
27
* ```cpp
28
* void operator||(std::expected<Skill:Output, Skill::ErrorOutput> const& skillResult,
29
* armarx::skills::client::result_handling_policies::Continue const& policy)
30
* {
31
* // Silently ignore any outcome.
32
* }
33
* ```
34
*
35
* a fluent skill execution can be written that handles the outcome as follows:
36
*
37
* ```cpp
38
* using namespace armarx::skills::client::result_handling_policies; // Pull the policies into
39
* the current scope.
40
*
41
* skill({.params = …}) or Continue(); // This will handle the outcome and supress the warning.
42
* ```
43
*
44
* The currently supported policies are defined in this namespace. The skill business object
45
* author is responsible for supplying these overloads if they want to support this feature.
46
*/
47
namespace
result_handling_policies
48
{
49
/**
50
* @brief Ignore any skill outcome and just continue.
51
*/
52
class
Continue
53
{
54
};
55
56
/**
57
* @brief Print a warning on failure but continue in any case.
58
*/
59
class
WarnOnFailureAndContinue
60
{
61
};
62
63
/**
64
* @brief Escalate any failures by throwing an exception.
65
*/
66
class
Escalate
67
{
68
};
69
}
// namespace result_handling_policies
70
71
}
// namespace armarx::skills::client
armarx::skills::client::result_handling_policies::Continue
Ignore any skill outcome and just continue.
Definition
result_handling_policies.h:53
armarx::skills::client::result_handling_policies::Escalate
Escalate any failures by throwing an exception.
Definition
result_handling_policies.h:67
armarx::skills::client::result_handling_policies::WarnOnFailureAndContinue
Print a warning on failure but continue in any case.
Definition
result_handling_policies.h:60
armarx::skills::client::result_handling_policies
Result handling policies.
Definition
result_handling_policies.h:48
armarx::skills::client
Definition
ErrorType.h:4
RobotAPI
libraries
skills
client
result_handling_policies.h
Generated by
1.13.2