Skip to content

Commit b26d05d

Browse files
fix: Improve error handling and logging in CSV extraction process
1 parent ba2ef1c commit b26d05d

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

app/etl/extract.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,21 @@ def extract(path: str = "xyz.csv") -> ________: # TODO (Find & Fix)
3434
# TODO (Find & Fix)
3535
pass
3636
except UnicodeDecodeError:
37-
# TODO (Find & Fix)
38-
pass
37+
print(f"Failed to read with encoding '{encoding}'") # Log the encoding that failed
3938

4039
if df is None:
41-
# TODO (Find & Fix)
42-
pass
40+
raise ValueError(f"❌ Could not read CSV with tried encodings: {encodings}")
4341

4442
# Validate data
4543
if df.empty:
46-
# TODO (Find & Fix)
47-
pass
44+
raise ValueError("❌ File contains no data")
4845

49-
print(f"✅ Extracted {len(df)} rows and {len(df.columns)} columns") # TODO (Find & Fix): Use logging instead of print
46+
print(f"✅ Extracted {len(df)} rows and {len(df.columns)} columns") # TODO: Use logging instead of print
5047
return df
5148

5249
except pd.errors.EmptyDataError:
5350
raise ValueError("❌ File contains no data")
5451
except pd.errors.ParserError as e:
5552
raise ValueError(f"❌ Error parsing CSV: {e}")
5653
except Exception as e:
57-
raise ValueError(f"❌ Unexpected error reading file: {e}")
54+
raise ValueError(f"❌ Unexpected error reading file: {e}")

0 commit comments

Comments
 (0)