Skip to content

Improve error handling in load_expected_versions() function across test notebooks #1266

Open
@coderabbitai

Description

@coderabbitai

Problem

The load_expected_versions() function in test notebooks lacks proper error handling for common failure scenarios:

  1. FileNotFoundError: When expected_versions.json is not found
  2. JSONDecodeError: When the JSON file is malformed or contains invalid JSON

Current Code Pattern

def load_expected_versions() -> dict:
    lock_file = Path('./expected_versions.json')
    data = {}

    with open(lock_file, 'r') as file:
        data = json.load(file)

    return data

Proposed Solution

Add proper exception handling to provide clearer error messages:

def load_expected_versions() -> dict:
    lock_file = Path('./expected_versions.json')
    try:
        with open(lock_file, 'r') as f:
            return json.load(f)
    except FileNotFoundError:
        raise FileNotFoundError(f"expected_versions.json not found in {lock_file.parent}")
    except json.JSONDecodeError as e:
        raise ValueError(f"Invalid JSON in expected_versions.json: {e}")

Scope

This improvement should be applied systematically across all test notebook files that contain this pattern.

Context

Acceptance Criteria

  • Identify all test notebook files with the load_expected_versions() pattern
  • Update all instances to include proper error handling for FileNotFoundError and JSONDecodeError
  • Ensure consistent error messaging across all files
  • Verify tests still pass with improved error handling
  • Consider whether to fail gracefully or provide fallback behavior in test scenarios

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions