From 56392e233856601410a0ae24d7a3fa1916012bd3 Mon Sep 17 00:00:00 2001 From: David Cui Date: Tue, 1 Dec 2020 13:39:45 -0800 Subject: [PATCH 1/6] added error messages for Explain and more detailed messages for invalid Run --- workbench/public/components/Main/main.tsx | 4 +-- .../public/components/PPLPage/PPLPage.tsx | 19 ++++++++++++- .../public/components/SQLPage/SQLPage.tsx | 28 ++++++++++++++++--- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/workbench/public/components/Main/main.tsx b/workbench/public/components/Main/main.tsx index 40a7beef03..0eeed51c38 100644 --- a/workbench/public/components/Main/main.tsx +++ b/workbench/public/components/Main/main.tsx @@ -103,7 +103,7 @@ export function getQueryResultsForTable( if (!queryResultResponseDetail.fulfilled) { return { fulfilled: queryResultResponseDetail.fulfilled, - errorMessage: queryResultResponseDetail.errorMessage, + errorMessage: queryResultResponseDetail.errorMessage + ', this query is not runnable.', }; } else { let databaseRecords: { [key: string]: any }[] = []; @@ -332,7 +332,7 @@ export class Main extends React.Component { this.processQueryResponse(response as IHttpResponse) ); const resultTable: ResponseDetail[] = getQueryResultsForTable(results); - + console.log('resutlTable is', resultTable); this.setState( { queries: queries, diff --git a/workbench/public/components/PPLPage/PPLPage.tsx b/workbench/public/components/PPLPage/PPLPage.tsx index b34fb77fa2..1dceee06a3 100644 --- a/workbench/public/components/PPLPage/PPLPage.tsx +++ b/workbench/public/components/PPLPage/PPLPage.tsx @@ -69,6 +69,23 @@ export class PPLPage extends React.Component { const closeModal = () => this.setIsModalVisible(false); const showModal = () => this.setIsModalVisible(true); + const pplTranslationsNotEmpty = () => { + if (this.props.pplTranslations.length > 0) { + return this.props.pplTranslations[0].fulfilled; + } + return false; + } + + const showExplainErrorMessage = () => { + return this.props.pplTranslations.map((queryTranslation: any) => JSON.stringify( + queryTranslation.errorMessage + ": This query is not explainable", null, 2 + )); + } + + const explainContent = pplTranslationsNotEmpty() + ? this.props.pplTranslations.map((queryTranslation: any) => JSON.stringify(queryTranslation.data, null, 2)).join("\n") + : showExplainErrorMessage(); + let modal; if (this.state.isModalVisible) { @@ -85,7 +102,7 @@ export class PPLPage extends React.Component { fontSize="m" isCopyable > - {this.props.pplTranslations.map((queryTranslation: any) => JSON.stringify(queryTranslation.data, null, 2)).join("\n")} + {explainContent} diff --git a/workbench/public/components/SQLPage/SQLPage.tsx b/workbench/public/components/SQLPage/SQLPage.tsx index d6c658ba14..469af18dc6 100644 --- a/workbench/public/components/SQLPage/SQLPage.tsx +++ b/workbench/public/components/SQLPage/SQLPage.tsx @@ -48,7 +48,7 @@ interface SQLPageProps { interface SQLPageState { sqlQuery: string, translation: string, - isModalVisible: boolean + isModalVisible: boolean, } export class SQLPage extends React.Component { @@ -57,7 +57,7 @@ export class SQLPage extends React.Component { this.state = { sqlQuery: this.props.sqlQuery, translation: "", - isModalVisible: false + isModalVisible: false, }; } @@ -72,6 +72,23 @@ export class SQLPage extends React.Component { const closeModal = () => this.setIsModalVisible(false); const showModal = () => this.setIsModalVisible(true); + const sqlTranslationsNotEmpty = () => { + if (this.props.sqlTranslations.length > 0) { + return this.props.sqlTranslations[0].fulfilled; + } + return false; + } + + const showExplainErrorMessage = () => { + return this.props.sqlTranslations.map((queryTranslation: any) => JSON.stringify( + queryTranslation.errorMessage + ": This query is not explainable", null, 2 + )); + } + + const explainContent = sqlTranslationsNotEmpty() + ? this.props.sqlTranslations.map((queryTranslation: any) => JSON.stringify(queryTranslation.data, null, 2)).join("\n") + : showExplainErrorMessage(); + let modal; if (this.state.isModalVisible) { @@ -88,7 +105,7 @@ export class SQLPage extends React.Component { fontSize="m" isCopyable > - {this.props.sqlTranslations.map((queryTranslation: any) => JSON.stringify(queryTranslation.data, null, 2)).join("\n")} + {explainContent} @@ -148,7 +165,10 @@ export class SQLPage extends React.Component { this.props.onTranslate(this.props.sqlQuery) } > - + Explain {modal} From 7471df942e627a960af27e8e243ba72295ff3d75 Mon Sep 17 00:00:00 2001 From: David Cui Date: Tue, 1 Dec 2020 13:44:21 -0800 Subject: [PATCH 2/6] remove console log statement --- workbench/public/components/Main/main.tsx | 1 - workbench/public/components/SQLPage/SQLPage.tsx | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/workbench/public/components/Main/main.tsx b/workbench/public/components/Main/main.tsx index 0eeed51c38..164837aebe 100644 --- a/workbench/public/components/Main/main.tsx +++ b/workbench/public/components/Main/main.tsx @@ -332,7 +332,6 @@ export class Main extends React.Component { this.processQueryResponse(response as IHttpResponse) ); const resultTable: ResponseDetail[] = getQueryResultsForTable(results); - console.log('resutlTable is', resultTable); this.setState( { queries: queries, diff --git a/workbench/public/components/SQLPage/SQLPage.tsx b/workbench/public/components/SQLPage/SQLPage.tsx index 469af18dc6..cb6ea74206 100644 --- a/workbench/public/components/SQLPage/SQLPage.tsx +++ b/workbench/public/components/SQLPage/SQLPage.tsx @@ -48,7 +48,7 @@ interface SQLPageProps { interface SQLPageState { sqlQuery: string, translation: string, - isModalVisible: boolean, + isModalVisible: boolean } export class SQLPage extends React.Component { @@ -57,7 +57,7 @@ export class SQLPage extends React.Component { this.state = { sqlQuery: this.props.sqlQuery, translation: "", - isModalVisible: false, + isModalVisible: false }; } From 70ec10c9fea3f7626e227eebf9dd4355ca50552a Mon Sep 17 00:00:00 2001 From: David Cui Date: Tue, 1 Dec 2020 13:59:06 -0800 Subject: [PATCH 3/6] added punctuation to explain error --- workbench/public/components/PPLPage/PPLPage.tsx | 2 +- workbench/public/components/SQLPage/SQLPage.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/workbench/public/components/PPLPage/PPLPage.tsx b/workbench/public/components/PPLPage/PPLPage.tsx index 1dceee06a3..7a59a6d2e8 100644 --- a/workbench/public/components/PPLPage/PPLPage.tsx +++ b/workbench/public/components/PPLPage/PPLPage.tsx @@ -78,7 +78,7 @@ export class PPLPage extends React.Component { const showExplainErrorMessage = () => { return this.props.pplTranslations.map((queryTranslation: any) => JSON.stringify( - queryTranslation.errorMessage + ": This query is not explainable", null, 2 + queryTranslation.errorMessage + ": This query is not explainable.", null, 2 )); } diff --git a/workbench/public/components/SQLPage/SQLPage.tsx b/workbench/public/components/SQLPage/SQLPage.tsx index cb6ea74206..e2c3e1d92f 100644 --- a/workbench/public/components/SQLPage/SQLPage.tsx +++ b/workbench/public/components/SQLPage/SQLPage.tsx @@ -81,7 +81,7 @@ export class SQLPage extends React.Component { const showExplainErrorMessage = () => { return this.props.sqlTranslations.map((queryTranslation: any) => JSON.stringify( - queryTranslation.errorMessage + ": This query is not explainable", null, 2 + queryTranslation.errorMessage + ": This query is not explainable.", null, 2 )); } From 53a90c093e58ef113f76efe7ab555341cde065a4 Mon Sep 17 00:00:00 2001 From: David Cui Date: Tue, 1 Dec 2020 17:17:18 -0800 Subject: [PATCH 4/6] add API response in error output for Run --- workbench/public/components/Main/main.tsx | 13 +++++++++++-- workbench/server/services/QueryService.ts | 1 + workbench/server/services/TranslateService.ts | 1 - 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/workbench/public/components/Main/main.tsx b/workbench/public/components/Main/main.tsx index 164837aebe..b79f32f98c 100644 --- a/workbench/public/components/Main/main.tsx +++ b/workbench/public/components/Main/main.tsx @@ -34,6 +34,7 @@ import { CoreStart } from 'kibana/public'; interface ResponseData { ok: boolean; resp: any; + body: any; } export interface ResponseDetail { @@ -94,6 +95,12 @@ interface MainState { const SUCCESS_MESSAGE = 'Success'; +const errorQueryResponse = (queryResultResponseDetail: any) => { + let errorMessage = queryResultResponseDetail.errorMessage + ', this query is not runnable. \n \n' + + queryResultResponseDetail.data; + return errorMessage; +} + // It gets column names and row values to display in a Table from the json API response export function getQueryResultsForTable( queryResults: ResponseDetail[] @@ -103,7 +110,7 @@ export function getQueryResultsForTable( if (!queryResultResponseDetail.fulfilled) { return { fulfilled: queryResultResponseDetail.fulfilled, - errorMessage: queryResultResponseDetail.errorMessage + ', this query is not runnable.', + errorMessage: errorQueryResponse(queryResultResponseDetail), }; } else { let databaseRecords: { [key: string]: any }[] = []; @@ -254,7 +261,7 @@ export class Main extends React.Component { return { fulfilled: false, errorMessage: response.data.resp, - data: '', + data: response.data.body, }; } @@ -331,6 +338,8 @@ export class Main extends React.Component { const results: ResponseDetail[] = response.map((response) => this.processQueryResponse(response as IHttpResponse) ); + console.log('responsePromise is', responsePromise); + console.log('results is', results); const resultTable: ResponseDetail[] = getQueryResultsForTable(results); this.setState( { diff --git a/workbench/server/services/QueryService.ts b/workbench/server/services/QueryService.ts index d916d31f04..f35b8579cb 100644 --- a/workbench/server/services/QueryService.ts +++ b/workbench/server/services/QueryService.ts @@ -45,6 +45,7 @@ export default class QueryService { data: { ok: false, resp: err.message, + body: err.body, }, }; } diff --git a/workbench/server/services/TranslateService.ts b/workbench/server/services/TranslateService.ts index af9ad61dce..33c3e2eac3 100644 --- a/workbench/server/services/TranslateService.ts +++ b/workbench/server/services/TranslateService.ts @@ -41,7 +41,6 @@ export default class TranslateService { }; return ret; } catch (err) { - console.log(err); return { data: { ok: false, From 7f15f67d2faaa2c7857e7c2eca8b68d4d8d92b66 Mon Sep 17 00:00:00 2001 From: David Cui Date: Tue, 1 Dec 2020 17:18:43 -0800 Subject: [PATCH 5/6] remove console log statements from main, add back in TranslateService --- workbench/public/components/Main/main.tsx | 2 -- workbench/server/services/TranslateService.ts | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/workbench/public/components/Main/main.tsx b/workbench/public/components/Main/main.tsx index b79f32f98c..3646f0bf7d 100644 --- a/workbench/public/components/Main/main.tsx +++ b/workbench/public/components/Main/main.tsx @@ -338,8 +338,6 @@ export class Main extends React.Component { const results: ResponseDetail[] = response.map((response) => this.processQueryResponse(response as IHttpResponse) ); - console.log('responsePromise is', responsePromise); - console.log('results is', results); const resultTable: ResponseDetail[] = getQueryResultsForTable(results); this.setState( { diff --git a/workbench/server/services/TranslateService.ts b/workbench/server/services/TranslateService.ts index 33c3e2eac3..af9ad61dce 100644 --- a/workbench/server/services/TranslateService.ts +++ b/workbench/server/services/TranslateService.ts @@ -41,6 +41,7 @@ export default class TranslateService { }; return ret; } catch (err) { + console.log(err); return { data: { ok: false, From 5dd385bd8452b9ff5a48188768d680ca2b508105 Mon Sep 17 00:00:00 2001 From: David Cui Date: Wed, 2 Dec 2020 09:47:07 -0800 Subject: [PATCH 6/6] Changed format of error body --- workbench/public/components/Main/main.tsx | 11 ++++++++++- workbench/server/services/QueryService.ts | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/workbench/public/components/Main/main.tsx b/workbench/public/components/Main/main.tsx index 3646f0bf7d..e0d438f460 100644 --- a/workbench/public/components/Main/main.tsx +++ b/workbench/public/components/Main/main.tsx @@ -249,6 +249,15 @@ export class Main extends React.Component { }; } + formatQueryErrorBody(data: any) { + let prettyErrorMessage = ""; + prettyErrorMessage += 'reason: ' + data.errorReason + '\n'; + prettyErrorMessage += 'details: ' + data.errorDetails + '\n'; + prettyErrorMessage += 'type: ' + data.errorType + '\n'; + prettyErrorMessage += 'status: ' + data.status; + return prettyErrorMessage; + } + processQueryResponse(response: IHttpResponse): ResponseDetail { if (!response) { return { @@ -261,7 +270,7 @@ export class Main extends React.Component { return { fulfilled: false, errorMessage: response.data.resp, - data: response.data.body, + data: this.formatQueryErrorBody(response.data), }; } diff --git a/workbench/server/services/QueryService.ts b/workbench/server/services/QueryService.ts index f35b8579cb..ede6c9dfde 100644 --- a/workbench/server/services/QueryService.ts +++ b/workbench/server/services/QueryService.ts @@ -41,11 +41,15 @@ export default class QueryService { }; } catch (err) { console.log(err); + const errorObj = JSON.parse(err.body); return { data: { ok: false, resp: err.message, - body: err.body, + errorReason: errorObj.error.reason, + errorDetails: errorObj.error.details, + errorType: errorObj.error.type, + status: errorObj.status }, }; }