Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit f689e6f

Browse files
committed
Better error messages. Move some parsing to before the connects.
1 parent 7276935 commit f689e6f

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

data_diff/__main__.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def _main(
155155
logging.debug(f"Applied run configuration: {__conf__}")
156156
elif verbose:
157157
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT, datefmt=DATE_FORMAT)
158+
else:
159+
logging.basicConfig(level=logging.WARNING, format=LOG_FORMAT, datefmt=DATE_FORMAT)
158160

159161
if limit and stats:
160162
logging.error("Cannot specify a limit when using the -s/--stats switch")
@@ -181,14 +183,6 @@ def _main(
181183
logging.error("Error: threads must be >= 1")
182184
return
183185

184-
db1 = connect(database1, threads1 or threads)
185-
db2 = connect(database2, threads2 or threads)
186-
dbs = db1, db2
187-
188-
if interactive:
189-
for db in dbs:
190-
db.enable_interactive()
191-
192186
start = time.monotonic()
193187

194188
try:
@@ -199,7 +193,7 @@ def _main(
199193
where=where,
200194
)
201195
except ParseError as e:
202-
logging.error("Error while parsing age expression: %s" % e)
196+
logging.error(f"Error while parsing age expression: {e}")
203197
return
204198

205199
differ = TableDiffer(
@@ -210,6 +204,23 @@ def _main(
210204
debug=debug,
211205
)
212206

207+
if database1 is None or database2 is None:
208+
logging.error(f"Error: Databases not specified. Got {database1} and {database2}. Use --help for more information.")
209+
return
210+
211+
try:
212+
db1 = connect(database1, threads1 or threads)
213+
db2 = connect(database2, threads2 or threads)
214+
except Exception as e:
215+
logging.error(e)
216+
return
217+
218+
dbs = db1, db2
219+
220+
if interactive:
221+
for db in dbs:
222+
db.enable_interactive()
223+
213224
table_names = table1, table2
214225
table_paths = [db.parse_table_name(t) for db, t in safezip(dbs, table_names)]
215226

data_diff/databases/connect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,4 @@ def connect(db_conf: Union[str, dict], thread_count: Optional[int] = 1) -> Datab
202202
return connect_to_uri(db_conf, thread_count)
203203
elif isinstance(db_conf, dict):
204204
return connect_with_dict(db_conf, thread_count)
205-
raise TypeError(db_conf)
205+
raise TypeError(f"db configuration must be a URI string or a dictionary. Instead got '{db_conf}'.")

0 commit comments

Comments
 (0)