From 032728231373670a5ede26c55f84f794d2eac52e Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Fri, 22 Apr 2022 03:59:00 -0700 Subject: [PATCH] Fixes an issue with no database selected Summary: ^ Not exactly sure how to reproduce the issue. Having said that: - A database id is a non-zero number (1..n) - If there's no selected database and/or there's no databases, then selectedDatabase is '0', which is an invalid database id. - It is safer to check if the selected database id falls within bounds before attempting to obtain the tables from it. From Logview, if the database id is '0', which is invalid, then we attempt to access a database at index -1 (database[selectedDatabase - 1]) which is definitely invalid. The returned object is undefined and hence the error. Changelog: Fixes an issue on the databases plugin when there is no selected database. Reviewed By: mweststrate Differential Revision: D35810827 fbshipit-source-id: 4c9f112eebcd0aa3fcd5df316749f48f3922381c --- desktop/plugins/public/databases/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/desktop/plugins/public/databases/index.tsx b/desktop/plugins/public/databases/index.tsx index e2785a607..d5f20076b 100644 --- a/desktop/plugins/public/databases/index.tsx +++ b/desktop/plugins/public/databases/index.tsx @@ -116,6 +116,8 @@ export function plugin(client: PluginClient) { (Object.values(databases)[0] ? Object.values(databases)[0].id : 0); const selectedTable = state.selectedDatabaseTable && + selectedDatabase > 0 && + databases.length >= selectedDatabase && databases[selectedDatabase - 1].tables.includes( state.selectedDatabaseTable, )