File tree Expand file tree Collapse file tree
libs/user-facing-errors/src
sql-migration-tests/tests/migrations Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -314,6 +314,10 @@ pub struct DatabaseSchemaInconsistent {
314314 pub explanation : String ,
315315}
316316
317+ #[ derive( Debug , SimpleUserFacingError ) ]
318+ #[ user_facing( code = "P4003" , message = "No URL defined in the configured datasource" ) ]
319+ pub struct MissingConfigDatasourceUrl ;
320+
317321#[ cfg( test) ]
318322mod tests {
319323 use super :: * ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ use schema_core::{
88} ;
99use structopt:: StructOpt ;
1010use tokio_util:: sync:: CancellationToken ;
11+ use user_facing_errors:: schema_engine:: MissingConfigDatasourceUrl ;
1112
1213#[ derive( Debug , StructOpt ) ]
1314pub ( crate ) struct Cli {
@@ -40,7 +41,7 @@ impl Cli {
4041
4142 let url = datasource_urls
4243 . url
43- . ok_or_else ( || ConnectorError :: from_msg ( "No URL defined in the configured datasource" . to_owned ( ) ) ) ?;
44+ . ok_or_else ( || ConnectorError :: user_facing ( MissingConfigDatasourceUrl ) ) ?;
4445
4546 let work = async {
4647 match self . command {
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ pub mod commands;
1010
1111pub use :: commands:: { CoreError , CoreResult , GenericApi } ;
1212pub use json_rpc;
13+ use user_facing_errors:: schema_engine:: MissingConfigDatasourceUrl ;
1314
1415mod core_error;
1516mod extensions;
@@ -126,8 +127,7 @@ fn schema_to_connector(
126127 )
127128 } ;
128129
129- let connection_string = connection_string
130- . ok_or_else ( || CoreError :: from_msg ( "No URL defined in the configured datasource" . to_owned ( ) ) ) ?;
130+ let connection_string = connection_string. ok_or_else ( || CoreError :: user_facing ( MissingConfigDatasourceUrl ) ) ?;
131131
132132 let params = ConnectorParams {
133133 connection_string,
@@ -148,7 +148,7 @@ fn initial_datamodel_to_connector(
148148 let params = ConnectorParams {
149149 connection_string : datasource_urls
150150 . url ( )
151- . ok_or_else ( || CoreError :: from_msg ( "No URL defined in the configured datasource" . to_owned ( ) ) ) ?
151+ . ok_or_else ( || CoreError :: user_facing ( MissingConfigDatasourceUrl ) ) ?
152152 . to_owned ( ) ,
153153 preview_features,
154154 shadow_database_connection_string : datasource_urls. shadow_database_url ( ) . map ( <_ >:: to_owned) ,
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ use std::{
2424} ;
2525use tokio:: sync:: { Mutex , mpsc, oneshot} ;
2626use tracing_futures:: { Instrument , WithSubscriber } ;
27+ use user_facing_errors:: schema_engine:: MissingConfigDatasourceUrl ;
2728
2829/// The container for the state of the schema engine. It can contain one or more connectors
2930/// corresponding to a database to be reached or that we are already connected to.
@@ -218,7 +219,7 @@ impl EngineState {
218219 Ok ( self
219220 . validate_datasource_urls ( & datasource) ?
220221 . url_with_config_dir ( datasource. active_connector . flavour ( ) , Path :: new ( & container. config_dir ) )
221- . ok_or_else ( || CoreError :: from_msg ( "No URL defined in the configured datasource" . to_owned ( ) ) ) ?
222+ . ok_or_else ( || CoreError :: user_facing ( MissingConfigDatasourceUrl ) ) ?
222223 . into_owned ( ) )
223224 }
224225
Original file line number Diff line number Diff line change @@ -48,14 +48,6 @@ impl DatasourceUrls {
4848 }
4949 }
5050
51- /// Creates a `DatasourceUrls` instance with both primary and shadow database URLs.
52- pub fn from_url_and_shadow_database_url ( url : impl Into < String > , shadow_database_url : impl Into < String > ) -> Self {
53- Self {
54- url : Some ( url. into ( ) ) ,
55- shadow_database_url : Some ( shadow_database_url. into ( ) ) ,
56- }
57- }
58-
5951 /// Validates the URLs.
6052 pub fn validate (
6153 & self ,
Original file line number Diff line number Diff line change @@ -376,7 +376,10 @@ fn from_empty_to_migrations_directory(mut api: TestApi) {
376376 let host = Arc :: new ( TestConnectorHost :: default ( ) ) ;
377377 tok ( diff_cli (
378378 params,
379- & DatasourceUrls :: from_url_and_shadow_database_url ( "postgres://not-used" , api. connection_string ( ) ) ,
379+ & DatasourceUrls {
380+ url : Some ( "postgres://not-used" . to_string ( ) ) ,
381+ shadow_database_url : Some ( api. connection_string ( ) . to_owned ( ) ) ,
382+ } ,
380383 host. clone ( ) ,
381384 & NoExtensionTypes ,
382385 ) )
You can’t perform that action at this time.
0 commit comments