Skip to content

Add handling for config directory with .yml/.yaml extension #1293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

winstonallo
Copy link

Description

Prevents a (probably mistakenly created) config.yml/ directory from being attempted to open as a regular file, resulting in a misleading PermissionError (source: just happened to me).

Before: PermissionError: [Errno 13] Permission denied: 'config.yml'
After: config.yml/ directory is treated as a valid config directory (falls through to existing directory handling logic).

Copy link
Collaborator

@trebedea trebedea left a comment

Choose a reason for hiding this comment

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

Looks good! Nice catch 👍

@Pouyanpi Pouyanpi requested a review from Copilot July 18, 2025 11:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where a directory with a .yml or .yaml extension would be incorrectly treated as a configuration file, causing a misleading PermissionError when attempting to open it. The fix adds an explicit file check to ensure only actual files with these extensions are processed as YAML config files, while directories fall through to the existing directory handling logic.

  • Added os.path.isfile() check to prevent directories with YAML extensions from being treated as config files
  • Maintains existing functionality for actual YAML config files
  • Improves error handling and user experience when config directories are mistakenly created with YAML extensions

@Pouyanpi
Copy link
Collaborator

@winstonallo thanks! would you please run the pre-commits per the contributing guideline.

Also this PR misses a regression test covering the directory with yml extension scenario

so a test case like:

def test_yaml_directory_handling():
    # like create a directory named whatever_config.yml
    # verify it's handled as a directory, not a file

this test should fail on the develop branch prior to this PR and go green afterwards.

@winstonallo
Copy link
Author

Hey, sorry for the late response, I will get to that on Wednesday:)

@winstonallo
Copy link
Author

Hey @Pouyanpi, I added the test and ran the pre-commit hooks:) Let me know if there is anything else I can do

@codecov-commenter
Copy link

codecov-commenter commented Jul 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.20%. Comparing base (cd14a07) to head (90cd8e1).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1293   +/-   ##
========================================
  Coverage    70.20%   70.20%           
========================================
  Files          161      161           
  Lines        16123    16123           
========================================
  Hits         11319    11319           
  Misses        4804     4804           
Flag Coverage Δ
python 70.20% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
nemoguardrails/rails/llm/config.py 90.32% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@winstonallo winstonallo reopened this Jul 23, 2025
@Pouyanpi Pouyanpi added this to the v0.16.0 milestone Aug 1, 2025
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.

4 participants