diff --git a/e2e_tests/integration/multi-db.spec.js b/e2e_tests/integration/multi-db.spec.js index 7097a34a6d7..91ffeeb9e19 100644 --- a/e2e_tests/integration/multi-db.spec.js +++ b/e2e_tests/integration/multi-db.spec.js @@ -139,5 +139,13 @@ describe('Multi database', () => { .first() resultFrame.should('contain', 'cannot be declared') }) + it('shows error when trying to use a db that doesnt exist', () => { + cy.executeCommand(':clear') + cy.executeCommand(':use nonexistingdb') + const resultFrame = cy + .get('[data-testid="frame"]', { timeout: 10000 }) + .first() + resultFrame.should('contain', 'could not be found') + }) } }) diff --git a/src/shared/services/commandInterpreterHelper.js b/src/shared/services/commandInterpreterHelper.js index 27ea911a326..9f292f7846a 100644 --- a/src/shared/services/commandInterpreterHelper.js +++ b/src/shared/services/commandInterpreterHelper.js @@ -200,6 +200,17 @@ const availableCommands = [ 'No multi db support detected.' ) } + const databaseNames = getDatabases(store.getState()).map(db => + db.name.toLowerCase() + ) + // Do we have a db with that name? + if (!databaseNames.includes(dbName.toLowerCase())) { + const error = new Error( + `A database with the "${dbName}" name could not be found.` + ) + error.code = 'NotFound' + throw error + } put(useDb(dbName)) put( frames.add({