Skip to content

Add error handling for missing or malformed legal_sections.json#659

Merged
viru0909-dev merged 1 commit into
viru0909-dev:mainfrom
aryantripathi130306-droid:fix-legal-sections-error-handling
May 30, 2026
Merged

Add error handling for missing or malformed legal_sections.json#659
viru0909-dev merged 1 commit into
viru0909-dev:mainfrom
aryantripathi130306-droid:fix-legal-sections-error-handling

Conversation

@aryantripathi130306-droid
Copy link
Copy Markdown
Contributor

Pull Request

Description

This PR adds proper error handling in _load_legal_sections() for cases where legal_sections.json is missing or contains malformed JSON.

Previously, the application raised generic Python exceptions without providing meaningful feedback.

Changes Made

  • Added handling for FileNotFoundError
  • Added handling for json.JSONDecodeError
  • Prevented unexpected application crashes
  • Improved error reporting using logging

Before

  • Application crashed with generic Python errors when:
    • legal_sections.json was missing
    • JSON format was invalid

After

  • Application now handles these cases gracefully
  • Clear error messages are logged instead of unhandled exceptions

Testing

Tested the following scenarios:

  • Missing legal_sections.json
  • Invalid/malformed JSON content
  • Verified application no longer crashes unexpectedly

@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

@aryantripathi130306-droid is attempting to deploy a commit to the CodeBlooded's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nyaysetu Ready Ready Preview, Comment May 26, 2026 9:15am

Copy link
Copy Markdown
Owner

@viru0909-dev viru0909-dev left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, @aryantripathi130306-droid!

The error handling fix for _load_legal_sections() is a solid improvement — wrapping it in try/except for FileNotFoundError and json.JSONDecodeError prevents the NLP service from crashing when the data file is missing or malformed. Good catch!

However, your branch was forked from an older version of main, which caused 25 merge conflicts across unrelated files. To avoid these conflicts, I've cherry-picked your fix onto a clean branch from the latest main and merged it with credit to you.

For future contributions, please make sure to rebase your branch on the latest main before opening a PR:

git fetch upstream main
git rebase upstream/main

@viru0909-dev viru0909-dev merged commit cca6f27 into viru0909-dev:main May 30, 2026
7 checks passed
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.

2 participants