Skip to content

Commit

Permalink
fix(errors): Mention correct db in postgres DatabaseDoesNotExist
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhoule committed Apr 7, 2022
1 parent ba8e3c2 commit e851507
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libs/user-facing-errors/src/quaint.rs
Expand Up @@ -48,9 +48,9 @@ pub fn render_quaint_error(kind: &ErrorKind, connection_info: &ConnectionInfo) -
}))
}

(ErrorKind::DatabaseDoesNotExist { .. }, ConnectionInfo::Postgres(url)) => {
(ErrorKind::DatabaseDoesNotExist { db_name }, ConnectionInfo::Postgres(url)) => {
Some(KnownError::new(common::DatabaseDoesNotExist::Postgres {
database_name: url.dbname().to_owned(),
database_name: db_name.to_string(),
database_schema_name: url.schema().to_owned(),
database_host: url.host().to_owned(),
database_port: url.port(),
Expand Down
Expand Up @@ -126,6 +126,27 @@ fn db_execute_error_path(api: TestApi) {
assert!(result.is_err());
}

#[test_connector(tags(Postgres))]
fn db_execute_drop_database_that_doesnt_exist_error(api: TestApi) {
let script = r#"
DROP DATABASE "thisisadatabaseweassumedoesntexist";
"#;

let generic_api = migration_core::migration_api(None, None).unwrap();
let result = tok(generic_api.db_execute(DbExecuteParams {
datasource_type: DbExecuteDatasourceType::Url(UrlContainer {
url: api.connection_string().to_owned(),
}),
script: script.to_owned(),
}));

let error = result.unwrap_err().to_string();
let expectation = expect![[r#"
Database `thisisadatabaseweassumedoesntexist.prisma-tests` does not exist on the database server at `localhost:5433`.
"#]];
expectation.assert_eq(&error);
}

#[test]
fn sqlite_db_execute_with_schema_datasource_resolves_relative_paths_correctly() {
let tmpdir = tempfile::tempdir().unwrap();
Expand Down

0 comments on commit e851507

Please sign in to comment.