Skip to content

Commit 5084295

Browse files
committed
Add 'reason' key that defaults to the exception message
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
1 parent 3c2b63c commit 5084295

6 files changed

Lines changed: 18 additions & 8 deletions

File tree

core/src/main/java/org/opensearch/sql/calcite/utils/CalciteToolsHelper.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import static java.util.Objects.requireNonNull;
3131
import static org.opensearch.sql.monitor.profile.MetricName.OPTIMIZE;
3232

33-
import com.google.common.base.Throwables;
3433
import com.google.common.collect.ImmutableList;
3534
import java.lang.reflect.Type;
3635
import java.sql.Connection;
@@ -480,8 +479,6 @@ public RelNode visit(TableScan scan) {
480479
optimizeTime.set(System.nanoTime() - startTime);
481480
return preparedStatement;
482481
} catch (SQLException e) {
483-
Throwables.throwIfUnchecked(e);
484-
485482
// Detect if error is due to window functions in unsupported context (bins on time fields)
486483
ErrorReport.Builder report =
487484
ErrorReport.wrap(e)

docs/user/ppl/cmd/mvcombine.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,6 @@ source=mvcombine_data
124124

125125
Expected output:
126126
```text
127-
{'context': {'stage': 'analyzing', 'stage_description': 'Parsing and validating the query'}, 'details': 'Field [does_not_exist] not found.', 'location': ['while preparing and validating the query plan'], 'code': 'FIELD_NOT_FOUND', 'type': 'IllegalArgumentException'}
127+
{'context': {'stage': 'analyzing', 'stage_description': 'Parsing and validating the query'}, 'reason': 'Field [does_not_exist] not found.', 'details': 'Field [does_not_exist] not found.', 'location': ['while preparing and validating the query plan'], 'code': 'FIELD_NOT_FOUND', 'type': 'IllegalArgumentException'}
128128
Error: Query returned no data
129129
```

docs/user/ppl/cmd/mvexpand.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,6 @@ source=people
132132

133133
Expected output:
134134
```text
135-
{'context': {'stage': 'analyzing', 'stage_description': 'Parsing and validating the query', 'command': 'mvexpand'}, 'details': "Field 'tags' not found in the schema", 'location': ['while preparing and validating the query plan', 'while evaluating the input field for mvexpand'], 'code': 'FIELD_NOT_FOUND', 'type': 'SemanticCheckException'}
135+
{'context': {'stage': 'analyzing', 'stage_description': 'Parsing and validating the query', 'command': 'mvexpand'}, 'reason': "Field 'tags' not found in the schema", 'details': "Field 'tags' not found in the schema", 'location': ['while preparing and validating the query plan', 'while evaluating the input field for mvexpand'], 'code': 'FIELD_NOT_FOUND', 'type': 'SemanticCheckException'}
136136
Error: Query returned no data
137137
```

docs/user/ppl/cmd/rex.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ source=accounts
228228
The query returns the following results:
229229

230230
```text
231-
{'context': {'stage': 'analyzing', 'stage_description': 'Parsing and validating the query', 'command': 'rex'}, 'details': "Invalid capture group name 'user_name'.", 'location': ['while preparing and validating the query plan', 'while processing the rex command', 'while validating the capture groups for the pattern'], 'code': 'SYNTAX_ERROR', 'type': 'IllegalArgumentException', 'suggestion': 'Java Regex capture groups must be alphanumeric and start with a letter. Update the capture group to be alphanumeric.'}
231+
{'reason': "Invalid capture group name 'user_name'.", 'code': 'SYNTAX_ERROR', 'suggestion': 'Java Regex capture groups must be alphanumeric and start with a letter. Update the capture group to be alphanumeric.', 'context': {'stage': 'analyzing', 'stage_description': 'Parsing and validating the query', 'command': 'rex'}, 'details': "Invalid capture group name 'user_name'.", 'location': ['while preparing and validating the query plan', 'while processing the rex command', 'while validating the capture groups for the pattern'], 'type': 'IllegalArgumentException'}
232232
Error: Query returned no data
233233
```
234234

docs/user/ppl/interfaces/protocol.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Expected output:
125125
"index_name": "unknown",
126126
"stage_description": "Parsing and validating the query"
127127
},
128+
"reason": "no such index [unknown]",
128129
"details": "no such index [unknown]",
129130
"location": [
130131
"while preparing and validating the query plan",

opensearch/src/main/java/org/opensearch/sql/opensearch/response/error/ErrorMessage.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,20 @@ public String toString() {
6363
}
6464

6565
private JSONObject getErrorAsJson() {
66-
if (exception instanceof ErrorReport) {
67-
return new JSONObject(((ErrorReport) exception).toJsonMap());
66+
if (exception instanceof ErrorReport errorReport) {
67+
JSONObject errorJson = new JSONObject(errorReport.toJsonMap());
68+
// Add 'reason' field for backward compatibility with existing clients
69+
// Use the underlying exception message as 'reason' (broad error description)
70+
// while 'details' contains the more precise handwritten message
71+
if (!errorJson.has("reason")) {
72+
Exception cause = errorReport.getCause();
73+
String reasonMessage =
74+
cause.getLocalizedMessage() != null ? cause.getLocalizedMessage() : cause.getMessage();
75+
if (reasonMessage != null) {
76+
errorJson.put("reason", reasonMessage);
77+
}
78+
}
79+
return errorJson;
6880
}
6981

7082
JSONObject errorJson = new JSONObject();

0 commit comments

Comments
 (0)