Skip to content

fix: avoid NameError in time-frame error message (file_path -> file_name) - #613

Open
Anai-Guo wants to merge 1 commit into
coding-kitties:mainfrom
Anai-Guo:fix-filepath-nameerror
Open

fix: avoid NameError in time-frame error message (file_path -> file_name)#613
Anai-Guo wants to merge 1 commit into
coding-kitties:mainfrom
Anai-Guo:fix-filepath-nameerror

Conversation

@Anai-Guo

Copy link
Copy Markdown

Problem

In investing_algorithm_framework/app/reporting/generate.py, get_time_frame_from_file_name(file_name) builds a helpful error message that references an undefined name file_path:

def get_time_frame_from_file_name(file_name: str) -> TimeFrame:
    ...
    try:
        return TimeFrame.from_string(time_frame_str)
    except ValueError:
        raise ValueError(
            f"Could not extract time frame from file name: {file_path}. "   # <- file_path is never defined
            ...
        )

The function parameter is file_name; file_path is not defined in this scope (nor imported anywhere), so the except ValueError handler itself raises NameError: name 'file_path' is not defined instead of the intended, informative ValueError.

Impact

TimeFrame.from_string() raises ValueError("Could not convert ... to TimeFrame") for any unrecognized time-frame token (investing_algorithm_framework/domain/models/time_frame.py). get_time_frame_from_file_name is called in a loop over data files in add_ohlcv_data_completeness_charts (generate.py:129). So whenever an OHLCV CSV's file name contains an unrecognized time-frame segment, the report generation crashes with a confusing NameError in the error path, masking the real diagnostic the code was trying to surface.

Fix

Reference the actual parameter name, file_name:

-            f"Could not extract time frame from file name: {file_path}. "
+            f"Could not extract time frame from file name: {file_name}. "

One-word change, no behavior change beyond the error message now rendering correctly.

🤖 Generated with Claude Code

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.

1 participant