[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated (ca2a2b9 -> 81d0605)
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated (ca2a2b9 -> 81d0605) |
Date: |
Wed, 13 Oct 2021 13:20:30 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a change to branch master
in repository anastasis.
from ca2a2b9 allow 'back' to unselect country
new e6ff49f do not transition into error states
new 81d0605 document error handling
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.gitignore | 2 +
doc/sphinx/reducer.rst | 56 +++++++++++++---------
src/reducer/anastasis_api_recovery_redux.c | 75 ++++++++++++------------------
3 files changed, 64 insertions(+), 69 deletions(-)
diff --git a/.gitignore b/.gitignore
index a0bb536..0d5dbc1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -128,3 +128,5 @@ doc/anastasis.info
src/cli/test_reducer.err
.vscode
vgcore*
+__pycache__
+tags
diff --git a/doc/sphinx/reducer.rst b/doc/sphinx/reducer.rst
index defd088..d1dc0f5 100644
--- a/doc/sphinx/reducer.rst
+++ b/doc/sphinx/reducer.rst
@@ -89,13 +89,23 @@ above would look like following for the transition action_
``select_continent``:
]
}
+An action may also result into an *error response* instead of a new state.
+Clients should then render this error response to the user and allow the user
+to continue from the old state. An error response looks like this:
+
+.. code-block:: json
+
+ {
+ "code": 123,
+ "hint": "something went wrong",
+ "details": "parameter foo failed to frobnify"
+ }
+
States
^^^^^^
Overall, the reducer knows the following states:
- - **ERROR**: The transition led to an error. No further transitions are
possible from
- this state, but the client may want to continue from a previous
state.
- **CONTINENT_SELECTING**: The user should specify the continent where they
are living,
so that we can show a list of countries to choose from.
- **COUNTRY_SELECTING**: The user should specify the country where they are
living,
@@ -607,16 +617,18 @@ to it:
}
If required attributes are missing, do not match the required regular
-expression, or fail the custom validation logic, the reducer SHOULD transition
-to an error state indicating what was wrong about the input. A reducer that
-does not support some specific validation logic MAY accept the invalid input
-and proceed anyway. The error state will include a Taler error code that
-is specific to the failure, and optional details. Example:
+expression, or fail the custom validation logic, the reducer SHOULD return an
+error response indicating that the transition has failed and what is wrong
about
+the input and not transition to a new state. A reducer that does not support
+some specific validation logic MAY accept the invalid input and proceed anyway.
+The error state will include a Taler error code that is specific to the
+failure, and optional details.
+
+Example:
.. code-block:: json
{
- "backup_state": "ERROR",
"code": 8404,
"hint": "An input did not match the regular expression.",
"detail": "social_security_number"
@@ -709,8 +721,8 @@ response:
]
}
-If the index is invalid, the reducer will instead
-transition into an ``ERROR`` state.
+If the index is invalid, the reducer will return an error
+response instead of making a transition.
**next** (from ``AUTHENTICATIONS_EDITING``):
@@ -785,8 +797,8 @@ policy. The ``methods`` array specifies the index of the
``authentication_method`` in the ``authentication_methods`` array, as well as
the provider that was selected to supervise this authentication.
-If no authentication method was provided, the reducer will transition into an
-``ERROR`` state instead of suggesting policies.
+If no authentication method was provided, the reducer will
+return an error response instead of making a transition.
**add_policy**:
@@ -873,7 +885,7 @@ the "policies" array, returning an updated state:
If the new policy is invalid, for example because it adds an unknown
authentication method, or the selected provider does not support the type of
-authentication, the reducer will transition into an ``ERROR`` state instead of
+authentication, the reducer return an error response instead of
adding the new policy.
@@ -904,7 +916,7 @@ An example for a possible argument would thus be:
If the new policy is invalid, for example because it adds an unknown
authentication method, or the selected provider does not support the type of
-authentication, the reducer will transition into an ``ERROR`` state instead of
+authentication, the reducer will return an error response instead of
modifying the policy.
@@ -967,7 +979,7 @@ be:
]
}
-If the index given is invalid, the reducer will transition into an ``ERROR``
state
+If the index given is invalid, the reducer will return an error response
instead of deleting a policy.
@@ -1028,7 +1040,7 @@ be:
]
}
-If the index given is invalid, the reducer will transition into an ``ERROR``
state
+If the index given is invalid, the reducer will return an error response
instead of deleting a challenge.
@@ -1052,8 +1064,8 @@ given policy expiration time. This is an array because
fees could
be in different currencies. The final cost may be lower if the
user already paid for some of the time.
-If the array of ``policies`` is currently empty, the reducer will transition
-into an ``ERROR`` state instead of allowing the user to continue.
+If the array of ``policies`` is currently empty, the reducer will
+return an error response instead of allowing the user to continue.
**enter_secret:**
@@ -1158,8 +1170,8 @@ Using this transition, the user confirms that the secret
and expiration
settings in the current state are acceptable. The transition does not take any
arguments.
-If the secret is currently empty, the reducer will transition into an
-``ERROR`` state instead of allowing the user to continue.
+If the secret is currently empty, the reducer will return an
+error response instead of allowing the user to continue.
After adding a secret, the reducer may transition into different states
depending on whether payment(s) are necessary. If payments are needed, the
@@ -1236,14 +1248,13 @@ will wait this long before giving up. If no timeout is
given, the check is
done as quickly as possible without additional delays. The reducer will
continue
to either an updated state with the remaining payment requests, to the
``BACKUP_FINISHED`` state (if all payments have been completed and the backup
-finished), or into an ``ERROR`` state in case there was an irrecoverable error,
+finished), or return an error response in case there was an irrecoverable
error,
indicating the specific provider and how it failed. An example for this
final error state would be:
.. code-block:: json
{
- "backup_state": "ERROR",
"http_status" : 500,
"upload_status" : 52,
"provider_url" : "https://bad.example.com/",
@@ -1359,7 +1370,6 @@ message together with a transition failure:
.. code-block:: json
{
- "recovery_state": "ERROR",
"error_message": "account unknown to Anastasis server",
"error_code": 9,
}
diff --git a/src/reducer/anastasis_api_recovery_redux.c
b/src/reducer/anastasis_api_recovery_redux.c
index 94e5e10..17fe639 100644
--- a/src/reducer/anastasis_api_recovery_redux.c
+++ b/src/reducer/anastasis_api_recovery_redux.c
@@ -250,15 +250,16 @@ sctx_free (void *cls)
/**
- * Update @a state to reflect the error provided in @a rc.
+ * Call the action callback with an error result
*
- * @param[in,out] state state to update
+ * @param cb action callback to call
+ * @param cb_cls closure for @a cb
* @param rc error code to translate to JSON
- * @return error code to use
*/
-static enum TALER_ErrorCode
-update_state_by_error (json_t *state,
- enum ANASTASIS_RecoveryStatus rc)
+void
+fail_by_error (ANASTASIS_ActionCallback cb,
+ void *cb_cls,
+ enum ANASTASIS_RecoveryStatus rc)
{
const char *msg = NULL;
enum TALER_ErrorCode ec = TALER_EC_INVALID;
@@ -311,17 +312,10 @@ update_state_by_error (json_t *state,
ec = TALER_EC_ANASTASIS_REDUCER_POLICY_LOOKUP_FAILED;
break;
}
- GNUNET_assert (0 ==
- json_object_set_new (state,
- "error_message",
- json_string (msg)));
- GNUNET_assert (0 ==
- json_object_set_new (state,
- "error_code",
- json_integer (rc)));
- set_state (state,
- ANASTASIS_RECOVERY_STATE_ERROR);
- return ec;
+ ANASTASIS_redux_fail_ (cb,
+ cb_cls,
+ ec,
+ msg);
}
@@ -341,7 +335,6 @@ core_secret_cb (void *cls,
size_t secret_size)
{
struct SelectChallengeContext *sctx = cls;
- enum TALER_ErrorCode ec;
sctx->r = NULL;
if (ANASTASIS_RS_SUCCESS == rc)
@@ -373,11 +366,9 @@ core_secret_cb (void *cls,
sctx_free (sctx);
return;
}
- ec = update_state_by_error (sctx->state,
- rc);
- sctx->cb (sctx->cb_cls,
- ec,
- sctx->state);
+ fail_by_error (sctx->cb,
+ sctx->cb_cls,
+ rc);
sctx_free (sctx);
}
@@ -550,11 +541,10 @@ answer_feedback_cb (
if (NULL == rd)
{
GNUNET_break (0);
- set_state (sctx->state,
- ANASTASIS_RECOVERY_STATE_ERROR);
- sctx->cb (sctx->cb_cls,
- TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
- sctx->state);
+ ANASTASIS_redux_fail_ (sctx->cb,
+ sctx->cb_cls,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "unable to serialize recovery state");
sctx_free (sctx);
return;
}
@@ -863,11 +853,10 @@ answer_feedback_cb (
if (NULL == c)
{
GNUNET_break (0);
- set_state (sctx->state,
- ANASTASIS_RECOVERY_STATE_ERROR);
- sctx->cb (sctx->cb_cls,
- TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
- sctx->state);
+ ANASTASIS_redux_fail_ (sctx->cb,
+ sctx->cb_cls,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ NULL);
sctx_free (sctx);
return;
}
@@ -2368,7 +2357,6 @@ core_early_secret_cb (void *cls,
{
struct PolicyDownloadEntry *pd = cls;
struct RecoverSecretState *rss = pd->rss;
- enum TALER_ErrorCode ec;
pd->recovery = NULL;
GNUNET_assert (NULL == secret);
@@ -2381,11 +2369,9 @@ core_early_secret_cb (void *cls,
return; /* wait for another one */
/* all failed! report failure! */
GNUNET_assert (ANASTASIS_RS_SUCCESS != rc);
- ec = update_state_by_error (rss->state,
- rc);
- rss->cb (rss->cb_cls,
- ec,
- rss->state);
+ fail_by_error (rss->cb,
+ rss->cb_cls,
+ rc);
rss->cb = NULL;
free_rss (rss);
}
@@ -2591,8 +2577,6 @@ policy_lookup_cb (void *cls,
{
json_decref (challenges);
json_decref (policies);
- set_state (rss->state,
- ANASTASIS_RECOVERY_STATE_ERROR);
ANASTASIS_redux_fail_ (rss->cb,
rss->cb_cls,
TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
@@ -2639,11 +2623,10 @@ policy_lookup_cb (void *cls,
if (NULL == rd)
{
GNUNET_break (0);
- set_state (rss->state,
- ANASTASIS_RECOVERY_STATE_ERROR);
- rss->cb (rss->cb_cls,
- TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
- rss->state);
+ ANASTASIS_redux_fail_ (rss->cb,
+ rss->cb_cls,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "unable to serialize recovery state");
free_rss (rss);
return;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-anastasis] branch master updated (ca2a2b9 -> 81d0605),
gnunet <=