Skip to content

Commit

Permalink
Merge pull request #575 from okp4/refactor/logic-answer-on-error
Browse files Browse the repository at this point in the history
🧠 Enhancing logic query response on errors
  • Loading branch information
ccamel authored Feb 28, 2024
2 parents 14e5718 + 09e9ec3 commit 16e42f8
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 215 deletions.
14 changes: 4 additions & 10 deletions docs/proto/logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ Gives:
"height": "7235",
"gas_used": "9085",
"answer": {
"success": true,
"has_more": false,
"variables": [
"X"
Expand All @@ -121,10 +120,7 @@ Gives:
"substitutions": [
{
"variable": "X",
"term": {
"name": "john",
"arguments": []
}
"expression": "john"
}
]
}
Expand All @@ -151,13 +147,12 @@ The response is an object that contains the following fields:
- `height`: the height of the block at which the query was evaluated.
- `gas_used`: the amount of gas used to evaluate the query.
- `answer`: the result of the query. It is an object that contains the following fields:
- `success`: a boolean that indicates whether the query was successful or not. Successful means that solutions were
found, i.e. the query was satisfiable.
- `has_more`: a boolean that indicates whether there are more results to be retrieved. It's just informative since no
more results can be retrieved.
- `variables`: an array of strings that contains the names of the variables that were used in the query.
- `results`: an array of objects that contains the results of the query. Each result is an object that contains the
- `results`: an array of objects that contains the solutions of the query. Each result is an object that contains the
following fields:
- `error`: an optional string that contains an error message if the query failed for the current solution.
- `substitutions`: an array of objects that contains the substitutions that were made to satisfy the query. A
substitution is a set of variable-value pairs that is used to replace variables with constants. A substitution
is the result of unification. A substitution is used to replace variables with constants when evaluating a rule.
Expand Down Expand Up @@ -351,8 +346,6 @@ Answer represents the answer to a logic query.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `success` | [bool](#bool) | | success specifies if the query was successful. |
| `error` | [string](#string) | | error specifies the error message if the query caused an error. |
| `has_more` | [bool](#bool) | | has_more specifies if there are more solutions than the ones returned. |
| `variables` | [string](#string) | repeated | variables represent all the variables in the query. |
| `results` | [Result](#logic.v1beta2.Result) | repeated | results represent all the results of the query. |
Expand All @@ -365,6 +358,7 @@ Result represents the result of a query.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `error` | [string](#string) | | error specifies the error message if the query caused an error. |
| `substitutions` | [Substitution](#logic.v1beta2.Substitution) | repeated | substitutions represent all the substitutions made to the variables in the query to obtain the answer. |

<a name="logic.v1beta2.Substitution"></a>
Expand Down
11 changes: 3 additions & 8 deletions proto/logic/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ description: |
"height": "7235",
"gas_used": "9085",
"answer": {
"success": true,
"has_more": false,
"variables": [
"X"
Expand All @@ -117,10 +116,7 @@ description: |
"substitutions": [
{
"variable": "X",
"term": {
"name": "john",
"arguments": []
}
"expression": "john"
}
]
}
Expand All @@ -147,13 +143,12 @@ description: |
- `height`: the height of the block at which the query was evaluated.
- `gas_used`: the amount of gas used to evaluate the query.
- `answer`: the result of the query. It is an object that contains the following fields:
- `success`: a boolean that indicates whether the query was successful or not. Successful means that solutions were
found, i.e. the query was satisfiable.
- `has_more`: a boolean that indicates whether there are more results to be retrieved. It's just informative since no
more results can be retrieved.
- `variables`: an array of strings that contains the names of the variables that were used in the query.
- `results`: an array of objects that contains the results of the query. Each result is an object that contains the
- `results`: an array of objects that contains the solutions of the query. Each result is an object that contains the
following fields:
- `error`: an optional string that contains an error message if the query failed for the current solution.
- `substitutions`: an array of objects that contains the substitutions that were made to satisfy the query. A
substitution is a set of variable-value pairs that is used to replace variables with constants. A substitution
is the result of unification. A substitution is used to replace variables with constants when evaluating a rule.
Expand Down
17 changes: 8 additions & 9 deletions proto/logic/v1beta2/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ message Substitution {
message Result {
option (gogoproto.goproto_stringer) = true;

// error specifies the error message if the query caused an error.
string error = 5 [
(gogoproto.nullable) = true,
(gogoproto.moretags) = "yaml:\"error\",omitempty"
];

// substitutions represent all the substitutions made to the variables in the query to obtain the answer.
repeated Substitution substitutions = 1 [
repeated Substitution substitutions = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"substitutions\",omitempty"
];
Expand All @@ -31,18 +37,11 @@ message Result {
message Answer {
option (gogoproto.goproto_stringer) = true;

// success specifies if the query was successful.
bool success = 1 [(gogoproto.moretags) = "yaml:\"success\",omitempty"];
// error specifies the error message if the query caused an error.
string error = 5 [
(gogoproto.nullable) = true,
(gogoproto.moretags) = "yaml:\"error\",omitempty"
];
// has_more specifies if there are more solutions than the ones returned.
bool has_more = 2 [(gogoproto.moretags) = "yaml:\"has_more\",omitempty"];
// variables represent all the variables in the query.
repeated string variables = 3 [
(gogoproto.nullable) = true,
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"variables\",omitempty"
];
// results represent all the results of the query.
Expand Down
Loading

0 comments on commit 16e42f8

Please sign in to comment.