From 0d317947c22302e6ad3280d65a67a63fd6c8be4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Bo=CC=88hm?= Date: Mon, 8 Jun 2020 14:21:48 +0200 Subject: [PATCH] fix https://github.com/prisma/prisma/issues/2686 --- .../datamodel/core/src/configuration/source/loader.rs | 2 +- .../core/tests/functions/functionals_environment.rs | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/datamodel/core/src/configuration/source/loader.rs b/libs/datamodel/core/src/configuration/source/loader.rs index 142ae1700711..db0a7f591b3b 100644 --- a/libs/datamodel/core/src/configuration/source/loader.rs +++ b/libs/datamodel/core/src/configuration/source/loader.rs @@ -69,8 +69,8 @@ impl SourceLoader { let url_args = args.arg("url")?; let (env_var_for_url, url) = match url_args.as_str_from_env() { + _ if ignore_env_var_errors => (None, format!("{}://", provider)), // glorious hack. ask marcus Ok((env_var, url)) => (env_var, url.trim().to_owned()), - Err(_) if ignore_env_var_errors => (None, format!("{}://", provider)), // glorious hack. ask marcus Err(err) => return Err(err), }; diff --git a/libs/datamodel/core/tests/functions/functionals_environment.rs b/libs/datamodel/core/tests/functions/functionals_environment.rs index 95a52ef25fb3..e0791b23a1ff 100644 --- a/libs/datamodel/core/tests/functions/functionals_environment.rs +++ b/libs/datamodel/core/tests/functions/functionals_environment.rs @@ -19,13 +19,18 @@ fn skipping_of_env_vars() { // must fail without env var parse_error(dml); - // must not fail with flag - // ... + // must not fail when ignore flag is set if let Err(err) = datamodel::parse_datamodel_and_ignore_env_errors(dml) { panic!("Skipping env var errors did not work. Error was {:?}", err) } - // must not fail with env var set + // must not fail with invalid env var set and ignore flag is set + std::env::set_var("POSTGRES_URL", "mysql://"); // wrong protocol + if let Err(err) = datamodel::parse_datamodel_and_ignore_env_errors(dml) { + panic!("Skipping env var errors did not work. Error was {:?}", err) + } + + // must not fail with correct env var set std::env::set_var("POSTGRES_URL", "postgresql://localhost:5432"); parse(dml); }