marcusvolz / strava_py

Create artistic visualisations with your exercise data (Python version)
MIT License
152 stars 18 forks source link

Exit with better error if no files found #43

Closed hugovk closed 5 months ago

hugovk commented 6 months ago

I accidentally ran this and forgot the * to match all filenames beginning with 2023, activities/2023 instead of activities/2023*, and got an ugly error:

❯ stravavis --activities_path . "activities/2023"
Processing data...
Processing ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━   0% -:--:--
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/bin/stravavis", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/hugo/github/strava_py/src/stravavis/cli.py", line 111, in main
    df = process_data(args.path)
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hugo/github/strava_py/src/stravavis/process_data.py", line 117, in process_data
    df = pd.concat(processed)
         ^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pandas/core/reshape/concat.py", line 380, in concat
    op = _Concatenator(
         ^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pandas/core/reshape/concat.py", line 443, in __init__
    objs, keys = self._clean_keys_and_objs(objs, keys)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pandas/core/reshape/concat.py", line 505, in _clean_keys_and_objs
    raise ValueError("No objects to concatenate")
ValueError: No objects to concatenate

Let's handle that in a better way:

❯ stravavis --activities_path . "activities/2023"
No files found matching activities/2023