mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 14:35:27 +00:00
export: Convert a bunch of error cases to AssertionError.
This reflects the fact that these are just defensive programming (we don't expect them to ever happen) and also nicely makes these lines not show up in our missing test coverage reports.
This commit is contained in:
@@ -226,7 +226,7 @@ class Config:
|
|||||||
self.parent = None
|
self.parent = None
|
||||||
|
|
||||||
if virtual_parent is not None and normal_parent is not None:
|
if virtual_parent is not None and normal_parent is not None:
|
||||||
raise ValueError('''
|
raise AssertionError('''
|
||||||
If you specify a normal_parent, please
|
If you specify a normal_parent, please
|
||||||
do not create a virtual_parent.
|
do not create a virtual_parent.
|
||||||
''')
|
''')
|
||||||
@@ -236,18 +236,18 @@ class Config:
|
|||||||
elif virtual_parent is not None:
|
elif virtual_parent is not None:
|
||||||
virtual_parent.children.append(self)
|
virtual_parent.children.append(self)
|
||||||
elif is_seeded is None:
|
elif is_seeded is None:
|
||||||
raise ValueError('''
|
raise AssertionError('''
|
||||||
You must specify a parent if you are
|
You must specify a parent if you are
|
||||||
not using is_seeded.
|
not using is_seeded.
|
||||||
''')
|
''')
|
||||||
|
|
||||||
if self.id_source is not None:
|
if self.id_source is not None:
|
||||||
if self.virtual_parent is None:
|
if self.virtual_parent is None:
|
||||||
raise ValueError('''
|
raise AssertionError('''
|
||||||
You must specify a virtual_parent if you are
|
You must specify a virtual_parent if you are
|
||||||
using id_source.''')
|
using id_source.''')
|
||||||
if self.id_source[0] != self.virtual_parent.table:
|
if self.id_source[0] != self.virtual_parent.table:
|
||||||
raise ValueError('''
|
raise AssertionError('''
|
||||||
Configuration error. To populate %s, you
|
Configuration error. To populate %s, you
|
||||||
want data from %s, but that differs from
|
want data from %s, but that differs from
|
||||||
the table name of your virtual parent (%s),
|
the table name of your virtual parent (%s),
|
||||||
@@ -273,7 +273,7 @@ def export_from_config(response: TableData, config: Config, seed_object: Optiona
|
|||||||
exported_tables = [table]
|
exported_tables = [table]
|
||||||
else:
|
else:
|
||||||
if config.custom_tables is None:
|
if config.custom_tables is None:
|
||||||
raise ValueError('''
|
raise AssertionError('''
|
||||||
You must specify config.custom_tables if you
|
You must specify config.custom_tables if you
|
||||||
are not specifying config.table''')
|
are not specifying config.table''')
|
||||||
exported_tables = config.custom_tables
|
exported_tables = config.custom_tables
|
||||||
@@ -294,7 +294,7 @@ def export_from_config(response: TableData, config: Config, seed_object: Optiona
|
|||||||
if config.custom_tables:
|
if config.custom_tables:
|
||||||
for t in config.custom_tables:
|
for t in config.custom_tables:
|
||||||
if t not in response:
|
if t not in response:
|
||||||
raise Exception('Custom fetch failed to populate %s' % (t,))
|
raise AssertionError('Custom fetch failed to populate %s' % (t,))
|
||||||
|
|
||||||
elif config.concat_and_destroy:
|
elif config.concat_and_destroy:
|
||||||
# When we concat_and_destroy, we are working with
|
# When we concat_and_destroy, we are working with
|
||||||
@@ -877,16 +877,16 @@ def export_files_from_s3(realm: Realm, bucket_name: str, output_dir: Path,
|
|||||||
# This can happen if an email address has moved realms
|
# This can happen if an email address has moved realms
|
||||||
if 'realm_id' in key.metadata and key.metadata['realm_id'] != str(realm.id):
|
if 'realm_id' in key.metadata and key.metadata['realm_id'] != str(realm.id):
|
||||||
if email_gateway_bot is None or key.metadata['user_profile_id'] != str(email_gateway_bot.id):
|
if email_gateway_bot is None or key.metadata['user_profile_id'] != str(email_gateway_bot.id):
|
||||||
raise Exception("Key metadata problem: %s %s / %s" % (key.name, key.metadata, realm.id))
|
raise AssertionError("Key metadata problem: %s %s / %s" % (key.name, key.metadata, realm.id))
|
||||||
# Email gateway bot sends messages, potentially including attachments, cross-realm.
|
# Email gateway bot sends messages, potentially including attachments, cross-realm.
|
||||||
print("File uploaded by email gateway bot: %s / %s" % (key.name, key.metadata))
|
print("File uploaded by email gateway bot: %s / %s" % (key.name, key.metadata))
|
||||||
elif processing_avatars:
|
elif processing_avatars:
|
||||||
if 'user_profile_id' not in key.metadata:
|
if 'user_profile_id' not in key.metadata:
|
||||||
raise Exception("Missing user_profile_id in key metadata: %s" % (key.metadata,))
|
raise AssertionError("Missing user_profile_id in key metadata: %s" % (key.metadata,))
|
||||||
if int(key.metadata['user_profile_id']) not in user_ids:
|
if int(key.metadata['user_profile_id']) not in user_ids:
|
||||||
raise Exception("Wrong user_profile_id in key metadata: %s" % (key.metadata,))
|
raise AssertionError("Wrong user_profile_id in key metadata: %s" % (key.metadata,))
|
||||||
elif 'realm_id' not in key.metadata:
|
elif 'realm_id' not in key.metadata:
|
||||||
raise Exception("Missing realm_id in key metadata: %s" % (key.metadata,))
|
raise AssertionError("Missing realm_id in key metadata: %s" % (key.metadata,))
|
||||||
|
|
||||||
record = dict(s3_path=key.name, bucket=bucket_name,
|
record = dict(s3_path=key.name, bucket=bucket_name,
|
||||||
size=key.size, last_modified=key.last_modified,
|
size=key.size, last_modified=key.last_modified,
|
||||||
@@ -906,7 +906,7 @@ def export_files_from_s3(realm: Realm, bucket_name: str, output_dir: Path,
|
|||||||
else:
|
else:
|
||||||
fields = key.name.split('/')
|
fields = key.name.split('/')
|
||||||
if len(fields) != 3:
|
if len(fields) != 3:
|
||||||
raise Exception("Suspicious key %s" % (key.name))
|
raise AssertionError("Suspicious key with invalid format %s" % (key.name))
|
||||||
dirname = os.path.join(output_dir, fields[1])
|
dirname = os.path.join(output_dir, fields[1])
|
||||||
filename = os.path.join(dirname, fields[2])
|
filename = os.path.join(dirname, fields[2])
|
||||||
record['path'] = os.path.join(fields[1], fields[2])
|
record['path'] = os.path.join(fields[1], fields[2])
|
||||||
|
|||||||
Reference in New Issue
Block a user