Skip to content

feat: Add IP network validation, enhance error handling with specific… - #398

Closed
AshleshBathina wants to merge 1 commit into
PalisadoesFoundation:mainfrom
AshleshBathina:network-validation
Closed

feat: Add IP network validation, enhance error handling with specific…#398
AshleshBathina wants to merge 1 commit into
PalisadoesFoundation:mainfrom
AshleshBathina:network-validation

Conversation

@AshleshBathina

@AshleshBathina AshleshBathina commented Feb 25, 2026

Copy link
Copy Markdown

… exceptions, and improve input validation for hashstring.

What kind of change does this PR introduce?

Issue Number:

Fixes #

Snapshots/Videos:

If relevant, did you update the documentation?

Summary

Does this PR introduce a breaking change?

Checklist

CodeRabbit AI Review

  • I have reviewed and addressed all critical issues flagged by CodeRabbit AI
  • I have implemented or provided justification for each non-critical suggestion
  • I have documented my reasoning in the PR comments where CodeRabbit AI suggestions were not implemented

Test Coverage

  • I have written tests for all new changes/features
  • I have verified that test coverage meets or exceeds 95%
  • I have run the test suite locally and all tests pass

Other information

Have you read the contributing guide?

Summary by CodeRabbit

  • New Features

    • Added IP network validation capability for CIDR notation.
  • Bug Fixes

    • Improved error handling with more specific exception catching in core modules.
    • Added input validation for SHA parameters with explicit error reporting.
    • Enhanced error handling in file and configuration operations for better reliability.

… exceptions, and improve input validation for hashstring.
@github-actions

github-actions Bot commented Feb 25, 2026

Copy link
Copy Markdown

Our Pull Request Approval Process

We have these basic policies to make the approval process smoother for our volunteer team.

Testing Your Code

Please make sure your code passes all tests. Our test code coverage system will fail if either of these two conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold

The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

Reviewers

When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

🎯 Contacting the person who assigned the mentors is not advised unless they make a request. Do not @ the person who did the assignment otherwise.

@github-actions

Copy link
Copy Markdown

PR validation failed: No linked issue and no valid closing issue reference in PR description

@github-actions github-actions Bot closed this Feb 25, 2026
@coderabbitai

coderabbitai Bot commented Feb 25, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2403731 and 6414c60.

📒 Files selected for processing (6)
  • switchmap/core/configuration.py
  • switchmap/core/data.py
  • switchmap/core/files.py
  • switchmap/core/general.py
  • tests/switchmap_/core/test_data.py
  • tests/switchmap_/core/test_general.py

Walkthrough

This pull request corrects documentation typos, tightens exception handling by replacing bare except blocks with specific Exception catches, adds input validation for SHA parameters, introduces a new IP network validation function, and includes corresponding test coverage.

Changes

Cohort / File(s) Summary
Documentation Fixes
switchmap/core/configuration.py
Corrected typo in docstrings: "Intialize the class." → "Initialize the class." in _Config, ConfigAPIClient, and ConfigAPI constructors.
Exception Handling
switchmap/core/files.py, switchmap/core/general.py
Replaced bare except blocks with specific except Exception in YAML reading and directory creation; narrowed exception handling in MAC and IP validation functions to catch only ValueError instead of broad exceptions.
Input Validation & Logic
switchmap/core/data.py
Added early validation in hashstring() to raise ValueError for invalid SHA values (not in [1, 224, 256, 384, 512]); simplified SHA type selection by removing redundant conditional guard and directly obtaining index via listing.index(sha).
New Functionality
switchmap/core/general.py
Added validate_ip_network(_network) function to validate CIDR notation using ip_network(strict=True), returning IP namedtuple on success or None on failure.
Test Coverage
tests/switchmap_/core/test_data.py
Added test_hashstring_invalid_sha() to validate that data.hashstring() raises ValueError for unrecognized SHA parameters.
Test Coverage
tests/switchmap_/core/test_general.py
Added test_validate_ip_network() to validate the new general.validate_ip_network() function against IPv4/IPv6 networks and invalid cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 With pens and validation so keen,
We tidy the code, scrub it clean,
Add guards to the SHA, net validation supreme,
Each exception now caught like a dream,
Our tests hop ahead—a team at full steam! 🌟

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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