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

Check if db exists before switching to it, throw if not #1007

Merged
merged 1 commit into from
Dec 4, 2019
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
8 changes: 8 additions & 0 deletions e2e_tests/integration/multi-db.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
}
})
11 changes: 11 additions & 0 deletions src/shared/services/commandInterpreterHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down