Skip to content

Commit 6631642

Browse files
Merge pull request #13 from actiontech/fix/type-error
fix: prevent undefined column access in SQL result viewer
2 parents a60fe00 + f420062 commit 6631642

File tree

4 files changed

+4
-5
lines changed

4 files changed

+4
-5
lines changed

webapp/packages/core-sdk/src/ServerInternalError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ export class ServerInternalError extends DetailsError implements ServerError {
2828
}
2929

3030
hasDetails(): boolean {
31-
return this.stack !== undefined && this.stack.length > 0 && this.errorType !== ServerErrorType.QUOTE_EXCEEDED;
31+
return this.stack !== undefined && (this.stack?.length ?? 0) > 0 && this.errorType !== ServerErrorType.QUOTE_EXCEEDED;
3232
}
3333
}

webapp/packages/plugin-data-viewer/src/DatabaseDataModel/Actions/ResultSet/ResultSetFormatAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class ResultSetFormatAction
3838
}
3939

4040
getHeaders(): string[] {
41-
return this.view.columns.map(column => column.name!).filter(name => name !== undefined);
41+
return this.view.columns.map(column => column?.name).filter((name): name is string => name !== undefined && name !== null);
4242
}
4343

4444
getLongestCells(offset = 0, count?: number): string[] {

webapp/packages/plugin-data-viewer/src/DatabaseDataModel/Actions/ResultSet/ResultSetViewAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class ResultSetViewAction extends DatabaseDataAction<any, IDatabaseResult
3939
}
4040

4141
get columns(): SqlResultColumn[] {
42-
return this.columnsOrder.map(i => this.data.columns[i]);
42+
return this.columnsOrder.map(i => this.data.columns[i]).filter(column => column !== undefined);
4343
}
4444

4545
private columnsOrder: number[] = [];

webapp/packages/plugin-data-viewer/src/TableViewer/TableError.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,11 @@ export const TableError = observer<Props>(function TableError({ model, loading,
215215
errorInfo.error = model.source.error || null;
216216
errorInfo.display = !!model.source.error;
217217
}
218-
console.log(error, model.source.error);
219218
const isSqlContextError = error.errorCode === SQL_CONTEXT_ERROR_CODE || /SQL context .* not found/i.test(error.message || '');
220219
if (isSqlContextError) {
221220
handleReopenEditor();
222221
}
223-
}, [error.message, handleReopenEditor, model.source.error, errorInfo]);
222+
}, [error.message, handleReopenEditor, model.source.error, errorInfo, error.errorCode]);
224223

225224
return styled(style)(
226225
<error {...use({ animated, collapsed: !errorInfo.display, errorHidden })} className={className}>

0 commit comments

Comments
 (0)