Replace assert statements with proper error handling
- Replace assert with ValueError in git_time_tracker/source/csv_file.py - Replace assert with ValueError in git_time_tracker/source/git_repo.py - Replace assert with TypeError in personal_data/util.py - Fix isinstance call to use tuple for efficiency 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2087460a7f
commit
b79ea804b2
|
@ -10,7 +10,8 @@ logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def iterate_samples_from_dicts(rows: list[dict[str, Any]]) -> Iterator[ActivitySample]:
|
def iterate_samples_from_dicts(rows: list[dict[str, Any]]) -> Iterator[ActivitySample]:
|
||||||
assert len(rows) > 0
|
if len(rows) == 0:
|
||||||
|
raise ValueError("No rows provided")
|
||||||
|
|
||||||
if True:
|
if True:
|
||||||
event_data = rows[len(rows) // 2] # Hopefully select a useful representative.
|
event_data = rows[len(rows) // 2] # Hopefully select a useful representative.
|
||||||
|
@ -18,8 +19,8 @@ def iterate_samples_from_dicts(rows: list[dict[str, Any]]) -> Iterator[ActivityS
|
||||||
logger.info('Found possible keys: %s', possible_keys)
|
logger.info('Found possible keys: %s', possible_keys)
|
||||||
del event_data
|
del event_data
|
||||||
|
|
||||||
assert len(possible_keys.time_start) + len(possible_keys.time_end) >= 1
|
if len(possible_keys.time_start) + len(possible_keys.time_end) < 1:
|
||||||
assert len(possible_keys.image) >= 0
|
raise ValueError("No time columns found in data")
|
||||||
|
|
||||||
for event_data in rows:
|
for event_data in rows:
|
||||||
"""
|
"""
|
||||||
|
@ -46,5 +47,6 @@ def iterate_samples_from_dicts(rows: list[dict[str, Any]]) -> Iterator[ActivityS
|
||||||
def iterate_samples_from_csv_file(file_path: Path) -> Iterator[ActivitySample]:
|
def iterate_samples_from_csv_file(file_path: Path) -> Iterator[ActivitySample]:
|
||||||
dicts = load_csv_file(file_path)
|
dicts = load_csv_file(file_path)
|
||||||
samples = list(iterate_samples_from_dicts(dicts))
|
samples = list(iterate_samples_from_dicts(dicts))
|
||||||
assert len(samples) > 0, 'Did not found any samples'
|
if len(samples) == 0:
|
||||||
|
raise ValueError('Did not find any samples')
|
||||||
yield from samples
|
yield from samples
|
||||||
|
|
|
@ -27,7 +27,8 @@ def determine_project_name(repo: git.Repo) -> str:
|
||||||
|
|
||||||
def get_samples_from_project(repo: git.Repo) -> Iterator[ActivitySample]:
|
def get_samples_from_project(repo: git.Repo) -> Iterator[ActivitySample]:
|
||||||
project_name = determine_project_name(repo)
|
project_name = determine_project_name(repo)
|
||||||
assert project_name is not None
|
if project_name is None:
|
||||||
|
raise ValueError("Could not determine project name")
|
||||||
|
|
||||||
# TODO: Branch on main or master or default
|
# TODO: Branch on main or master or default
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,8 @@ def dataclass_to_dict(obj) -> dict[str, Any]:
|
||||||
def normalize_dict(d: dict[str, Any] | frozendict[str, Any]) -> frozendict[str, Any]:
|
def normalize_dict(d: dict[str, Any] | frozendict[str, Any]) -> frozendict[str, Any]:
|
||||||
if not isinstance(d, dict) and not isinstance(d, frozendict):
|
if not isinstance(d, dict) and not isinstance(d, frozendict):
|
||||||
d = dataclass_to_dict(d)
|
d = dataclass_to_dict(d)
|
||||||
assert isinstance(d, dict) or isinstance(d, frozendict), 'Not a dict'
|
if not isinstance(d, (dict, frozendict)):
|
||||||
|
raise TypeError('Expected dict or frozendict')
|
||||||
safe_values = [
|
safe_values = [
|
||||||
(k, csv_import.csv_str_to_value(csv_import.csv_safe_value(v)))
|
(k, csv_import.csv_str_to_value(csv_import.csv_safe_value(v)))
|
||||||
for k, v in d.items()
|
for k, v in d.items()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user