Skip to content

fix: handle DataNotLoadedError and session load failures gracefully (…#249

Open
nirvik34 wants to merge 5 commits into
IAmTomShaw:mainfrom
nirvik34:fix/245-data-not-loaded-error
Open

fix: handle DataNotLoadedError and session load failures gracefully (…#249
nirvik34 wants to merge 5 commits into
IAmTomShaw:mainfrom
nirvik34:fix/245-data-not-loaded-error

Conversation

@nirvik34

Copy link
Copy Markdown

Closes #245

Problem

When session data fails to load, the app crashes with a raw FastF1
traceback — confusing for users who don't know what
DataNotLoadedError means.

Changes

src/f1_data.py

  • Added robust error handling in load_session() helper
  • Catches DataNotLoadedError → session may not exist yet or still processing
  • Catches ConnectionError → tells user to check network
  • Catches metadata errors → prompts user to verify year/round inputs
  • App exits cleanly with friendly message instead of raw traceback

main.py

  • Added exit_on_failure=False flag for secondary qualifying data load
  • Race replay now continues even if qualifying/DRS zone data is unavailable

Before vs After

Before:

fastf1.exceptions.DataNotLoadedError: The data you are trying to access has not been loaded yet. See Session.load

After:

[ERROR] Session data could not be loaded.
This usually means:

  • The session hasn't happened yet
  • There's a network connectivity issue
  • The FastF1 cache is corrupted (try deleting .fastf1-cache/)

Testing

  • Valid session → loads normally
  • Invalid round number → friendly error shown
  • Missing qualifying data → race replay still continues

@HEPNARL HEPNARL left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good long term solution for the problem, and could cause unexpected issues in the future. Major changes are required.

Comment thread src/f1_data.py Outdated
session.load(telemetry=True, weather=True)
try:
session = fastf1.get_session(year, round_number, session_type)
except Exception as e:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching all exceptions as a generic exception and potentially ignoring them can cause problems in future. fastf1 provides list of possible thrown exception and they should be treated as needed. If there's no match the the program should exit with fail code no matter what happens.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored load_session to catch specific fastf1 and requests exceptions instead of using generic ones.

Comment thread src/f1_data.py Outdated
@nirvik34 nirvik34 requested a review from HEPNARL March 12, 2026 03:36
@HEPNARL

HEPNARL commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

can you add some test cases or give specific calls that hit each catch clause for those that are possible to replicate? Just trying to do what the test case tells the problem is doesn't appear to be doing anything and falls as exception somewhere else.

@nirvik34

Copy link
Copy Markdown
Author
Screenshot from 2026-03-17 17-10-57 Screenshot from 2026-03-17 17-00-12

I added some screenshots of the improved terminal errors showing testing of each case.

@nirvik34

Copy link
Copy Markdown
Author

are thes changes fine?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fastf1.exceptions.DataNotLoadedError: The data you are trying to access has not been loaded yet. See Session.load

2 participants