Skip to content

Commit

Permalink
Refine error message of invalid database url (prisma#4340)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Piotrowski <[email protected]>
  • Loading branch information
onichandame and janpio authored Nov 3, 2023
1 parent 575e022 commit 0a4f17d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 11 additions & 0 deletions schema-engine/cli/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ fn test_create_database_mssql(api: TestApi) {
assert!(output.status.success());
}

#[test_connector(tags(Sqlite))]
fn test_sqlite_url(api: TestApi) {
let base_dir = tempfile::tempdir().unwrap();
let sqlite_path = base_dir.path().join("test.db");
let url = format!("{}", sqlite_path.to_string_lossy());
let output = api.run(&["--datasource", &url, "can-connect-to-database"]);
assert!(!output.status.success());
let message = String::from_utf8(output.stderr).unwrap();
assert!(message.contains("The provided database string is invalid. The scheme is not recognized in database URL."));
}

#[test_connector(tags(Sqlite))]
fn test_create_sqlite_database(api: TestApi) {
let base_dir = tempfile::tempdir().unwrap();
Expand Down
4 changes: 1 addition & 3 deletions schema-engine/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ fn connector_for_connection_string(
let connector = MongoDbSchemaConnector::new(params);
Ok(Box::new(connector))
}
Some(other) => Err(CoreError::url_parse_error(format!(
"`{other}` is not a known connection URL scheme. Prisma cannot determine the connector."
))),
Some(_other) => Err(CoreError::url_parse_error("The scheme is not recognized")),
None => Err(CoreError::user_facing(InvalidConnectionString {
details: String::new(),
})),
Expand Down

0 comments on commit 0a4f17d

Please sign in to comment.