Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 9, 2025

Plan: Add graceful handling of malformed YAML files

  • Explore the repository and understand current implementation
  • Run existing tests to ensure they pass
  • Test current behavior with malformed YAML (crashes with stack trace)
  • Add error handling to config.py to catch YAML parsing errors
  • Add clear error messages with filename, line number, and issue description
  • Add logging to capture configuration errors
  • Create tests for malformed YAML handling
  • Run all tests to ensure nothing is broken
  • Update documentation if needed
  • Resolve merge conflicts with main branch

Summary

Successfully implemented graceful handling of malformed YAML configuration files with clear, actionable error messages. Merge conflicts with main branch have been resolved.

Changes Made

Code Changes (chatrixcd/config.py):

  • Added logging and sys imports for error handling
  • Wrapped yaml.safe_load() in try-except block to catch yaml.YAMLError
  • Extract and display detailed error information:
    • Configuration file path
    • Line and column number where error occurred
    • Problem description (e.g., "expected , but found ''")
    • Context of the parsing error
  • Added separate exception handler for file I/O errors (permissions, etc.)
  • Exit with status code 1 on configuration errors
  • Merged: New greeting configuration fields from main branch

Test Coverage (tests/test_config.py):

  • Test for malformed YAML with missing closing quote
  • Test for malformed YAML with unclosed bracket
  • Test for malformed YAML with invalid indentation
  • Test for unreadable config file (permission errors)
  • Merged: Tests for greeting configuration from main branch
  • All 11 config tests pass successfully

Documentation Updates:

  • docs/support.md: Added detailed explanation of YAML error messages with example output
  • docs/configuration.md: Updated troubleshooting section to mention automatic error detection
  • CHANGELOG.md: Documented the improvement in the Unreleased section, merged with changes from main

Merge Resolution

Resolved conflicts in:

  • CHANGELOG.md: Combined both "Improved" (YAML error handling) and "Fixed" (encrypted rooms) sections
  • tests/test_config.py: Kept all tests from both branches

Example Error Output

Before:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  ...
yaml.parser.ParserError: while parsing a block mapping
  in "/tmp/test.yaml", line 2, column 3
  expected <block end>, but found '<scalar>'
  in "/tmp/test.yaml", line 7, column 9

After:

ERROR: Failed to parse YAML configuration file 'config.yaml'
  Error at line 7, column 9
  Problem: expected <block end>, but found '<scalar>'
  Context: while parsing a block mapping

The error messages are now user-friendly and provide actionable information for fixing configuration issues.

Original prompt

Add graceful handling of malformed yaml files, with clear output as to why the config.yaml file couldn't not parse.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits October 9, 2025 03:34
Co-authored-by: CJFWeatherhead <6923098+CJFWeatherhead@users.noreply.github.com>
Co-authored-by: CJFWeatherhead <6923098+CJFWeatherhead@users.noreply.github.com>
Copilot AI changed the title [WIP] Add graceful handling of malformed yaml files Add graceful handling of malformed YAML config files with clear error messages Oct 9, 2025
Copilot AI requested a review from CJFWeatherhead October 9, 2025 03:38
@CJFWeatherhead
Copy link
Owner

@copilot Resolve the merge conflicts

Resolved conflicts:
- CHANGELOG.md: Combined both Improved and Fixed sections
- tests/test_config.py: Kept all tests from both branches (YAML error handling + greeting config tests)

All tests pass (11/11 config tests)
Copy link
Contributor Author

Copilot AI commented Oct 9, 2025

@copilot Resolve the merge conflicts

Resolved merge conflicts with main branch in commit 9753bea.

Conflicts resolved:

  • CHANGELOG.md: Combined both the "Improved" section (YAML error handling) and "Fixed" section (encrypted rooms support)
  • tests/test_config.py: Kept all tests from both branches - 4 YAML error handling tests + 3 greeting configuration tests

All 11 config tests pass successfully. The YAML error handling feature works correctly with the new greeting configuration fields from main.

@CJFWeatherhead CJFWeatherhead marked this pull request as ready for review October 9, 2025 03:53
@CJFWeatherhead CJFWeatherhead merged commit 1d64fa5 into main Oct 9, 2025
8 checks passed
@CJFWeatherhead CJFWeatherhead deleted the copilot/handle-malformed-yaml-files branch October 10, 2025 00:29
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