Skip to content

Commit

Permalink
Improve error message and remove needless clone
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
Co-authored-by: Sophie <29753584+Druue@users.noreply.github.com>
  • Loading branch information
3 people committed May 1, 2024
1 parent b54bc96 commit 00d73dc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions psl/diagnostics/src/error.rs
Expand Up @@ -333,12 +333,12 @@ impl DatamodelError {
}

pub fn new_shadow_database_is_same_as_main_url_error(source_name: &str, span: Span) -> DatamodelError {
let msg = format!("shadowDatabaseUrl is the same as url for datasource \"{source_name}\". Please specify a different database as shadow database.");
let msg = format!("shadowDatabaseUrl is the same as url for datasource \"{source_name}\". Please specify a different database as shadow database to avoid data loss.");
Self::new(msg, span)
}

pub fn new_shadow_database_is_same_as_direct_url_error(source_name: &str, span: Span) -> DatamodelError {
let msg = format!("shadowDatabaseUrl is the same as directUrl for datasource \"{source_name}\". Please specify a different database as shadow database.");
let msg = format!("shadowDatabaseUrl is the same as directUrl for datasource \"{source_name}\". Please specify a different database as shadow database to avoid data loss.");
Self::new(msg, span)
}

Expand Down
6 changes: 3 additions & 3 deletions psl/psl-core/src/validate/datasource_loader.rs
Expand Up @@ -163,8 +163,8 @@ fn lift_datasource(
None => (None, None),
};

if let Some((shadow_url, _)) = shadow_database_url.clone() {
if let (Some(direct_url), Some(direct_url_span)) = (direct_url.clone(), direct_url_span) {
if let Some((shadow_url, _)) = &shadow_database_url {
if let (Some(direct_url), Some(direct_url_span)) = (&direct_url, direct_url_span) {
if shadow_url == direct_url {
diagnostics.push_error(DatamodelError::new_shadow_database_is_same_as_direct_url_error(
source_name,
Expand All @@ -173,7 +173,7 @@ fn lift_datasource(
}
}

if shadow_url == url {
if shadow_url == &url {
diagnostics.push_error(DatamodelError::new_shadow_database_is_same_as_main_url_error(
source_name,
url_span,
Expand Down
Expand Up @@ -11,7 +11,7 @@ datasource testds {
//  3 |  url = "mysql://testurl"
//  4 |  directUrl = "mysql://testurl"
//  | 
// [1;91merror[0m: [1mshadowDatabaseUrl is the same as url for datasource "testds". Please specify a different database as shadow database.[0m
// [1;91merror[0m: [1mshadowDatabaseUrl is the same as url for datasource "testds". Please specify a different database as shadow database to avoid data loss.�[0m
// --> schema.prisma:3
//  | 
//  2 |  provider = "mysql"
Expand Down
Expand Up @@ -4,7 +4,7 @@ datasource testds {
shadowDatabaseUrl = "mysql://testurl"
}

// [1;91merror[0m: [1mshadowDatabaseUrl is the same as url for datasource "testds". Please specify a different database as shadow database.[0m
// [1;91merror[0m: [1mshadowDatabaseUrl is the same as url for datasource "testds". Please specify a different database as shadow database to avoid data loss.�[0m
// --> schema.prisma:3
//  | 
//  2 |  provider = "mysql"
Expand Down

0 comments on commit 00d73dc

Please sign in to comment.