Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data-explorer: introduce error handling for long questions #1666

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ export class ExplorerService {
const logger = this.logger.child({ questionId: questionId });
const normalizedQuestion = this.normalizeQuestion(q);
if (normalizedQuestion.length > 512) {
throw new APIError(400, 'The question is too long, please shorten it.');
const message = `The question is too long, please shorten it.`;
throw new ExplorerPrepareQuestionError(message, QuestionFeedbackType.ErrorQuestionIsTooLong, {
message: message
});
}

// Prepare the new question.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ export enum QuestionFeedbackType {
ErrorEmptyResult = "error-empty-result",
ErrorSummaryGenerate = "error-summary-generate",
ErrorUnknown = "error-unknown",
ErrorQuestionIsTooLong = "error-question-too-long",
}
1 change: 1 addition & 0 deletions web/src/api/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export enum QuestionErrorType {
EMPTY_RESULT = 'error-empty-result',
SUMMARY_GENERATE = 'error-summary-generate',
UNKNOWN = 'error-unknown',
QUESTION_IS_TOO_LONG = 'error-question-too-long',
}

export interface PlanStep {
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/explore/_components/SqlSection/ErrorMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default function ErrorMessage ({ error }: { error: unknown }) {
return <Typography variant="body1">Failed to generate SQL. Optimize your question for effective SQL, or get ideas from <Link to='/explore/'>popular questions</Link>.</Typography>;
case QuestionErrorType.SQL_CAN_NOT_ANSWER:
return <Typography variant="body1">Sorry, I can&apos;t generate SQL as your question is not GitHub-related or beyond our data source.</Typography>;
case QuestionErrorType.QUESTION_IS_TOO_LONG:
return <Typography variant="body1">Sorry, your question is too long. Please simplify it to a few sentences.</Typography>;
case QuestionErrorType.VALIDATE_SQL: {
const errorDetails = getErrorDetails(QuestionErrorType.VALIDATE_SQL, question.error);
if (notNullish(errorDetails)) {
Expand Down
Loading