Skip to content

fix: Improve Penguin Bindufy configuration validation and error messages.#425

Open
Brian-code-123 wants to merge 1 commit intoGetBindu:mainfrom
Brian-code-123:fix/242-bindufy-config-validation
Open

fix: Improve Penguin Bindufy configuration validation and error messages.#425
Brian-code-123 wants to merge 1 commit intoGetBindu:mainfrom
Brian-code-123:fix/242-bindufy-config-validation

Conversation

@Brian-code-123
Copy link
Copy Markdown

@Brian-code-123 Brian-code-123 commented Mar 30, 2026

Overview / Description
This change adds stricter and more readable configuration validation and error messages before the Penguin SDK bindufy startup flow. In addition to checking required fields, it introduces validation for the format of deployment.url and improves the error message when a handler is not callable.

This improves developer experience and prevents users from encountering obscure KeyError/AttributeError deep in runtime.

Fixes #242

Changes

Added ConfigError (subclassing ValueError) in bindu/penguin/config_validator.py as an explicit configuration-validation error type.
Strengthened required-field error messages: when a single field is missing, report: ConfigError: '' is a required field in the agent configuration.
Added deployment.url format validation: must be a valid http(s) URL.
Improved handler validation error messages in bindu/penguin/bindufy.py to explicitly state that the handler must be a callable function or coroutine.
Added/updated unit tests:
tests/unit/penguin/test_config_validator.py: cases for missing fields and URL scheme/format errors.
tests/unit/penguin/test_bindufy.py: case demonstrating a clear error message when the handler is not callable.
How to Test

Local tests:
uv run pytest tests/unit/penguin/test_config_validator.py tests/unit/penguin/test_bindufy.py
Quality checks:
uv run ruff check bindu/penguin/config_validator.py bindu/penguin/bindufy.py tests/unit/penguin/test_config_validator.py tests/unit/penguin/test_bindufy.py
uv run ruff format --check bindu/penguin/config_validator.py bindu/penguin/bindufy.py tests/unit/penguin/test_config_validator.py tests/unit/penguin/test_bindufy.py
Test environment: Python 3.12
Summary by CodeRabbit

Bug Fixes

Improved error messages for handler and configuration validation failures
Added validation for deployment URLs with specific error reporting
New Features

Introduced new ConfigError exception class for configuration validation errors

Copilot AI review requested due to automatic review settings March 30, 2026 17:22
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 40095e62-41ba-40d8-aaca-99a020ab78e8

📥 Commits

Reviewing files that changed from the base of the PR and between 28166d1 and f01b09f.

📒 Files selected for processing (4)
  • bindu/penguin/bindufy.py
  • bindu/penguin/config_validator.py
  • tests/unit/penguin/test_bindufy.py
  • tests/unit/penguin/test_config_validator.py

📝 Walkthrough

Walkthrough

The changes introduce enhanced error handling and validation for the Penguin SDK. A new ConfigError exception class and dedicated validation module (config_validator.py) were added to validate configuration structure, required fields, and deployment URLs. The bindufy() function now provides a clearer error message for non-callable handlers. New unit tests verify both the improved handler validation and the comprehensive configuration validation logic.

Changes

Cohort / File(s) Summary
Handler Validation Enhancement
bindu/penguin/bindufy.py
Improved error message for non-callable handler parameter, providing clearer feedback to developers when an invalid handler is passed.
Configuration Validation Module
bindu/penguin/config_validator.py
Introduced new ConfigError exception class. Added validation functions: validate_and_process() to check config is a dict, _validate_required_fields() with focused error messages for missing fields, and _validate_deployment_url() to enforce valid http/https URLs with non-empty netloc in deployment configuration.
Test Coverage
tests/unit/penguin/test_bindufy.py, tests/unit/penguin/test_config_validator.py
Added unit tests for non-callable handler error messaging and deployment URL validation (invalid schemes, malformed URLs). Updated test expectations to catch ConfigError instead of ValueError.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop with glee, no more "KeyError" fright!
ConfigError whispers—all is right.
URLs validated, fields all checked,
Deployment ready, perfectly decked!
Clear messages guide where bugs once crept.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copy link
Copy Markdown

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 improves the Penguin SDK startup path by adding stricter pre-flight validation for bindufy configuration and clearer error messages, aiming to fail fast with more actionable feedback (Fixes #242).

Changes:

  • Introduces ConfigError and updates required-field validation to raise clearer, field-specific errors.
  • Adds deployment.url URL validation (must be a valid http(s) URL).
  • Improves bindufy handler validation error message and adds/updates unit tests accordingly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
bindu/penguin/config_validator.py Adds ConfigError, dictionary type check, and deployment.url format validation logic.
bindu/penguin/bindufy.py Improves handler non-callable error message surfaced by bindufy().
tests/unit/penguin/test_config_validator.py Updates expectations to ConfigError and adds URL validation test cases.
tests/unit/penguin/test_bindufy.py Adds test ensuring non-callable handler fails fast with clearer messaging.

Comment on lines +128 to +134
raise ConfigError(
f"ConfigError: missing required fields in the agent configuration:\n"
f"{formatted_fields}\n\n"
f"Example:\n{cls.EXAMPLE_CONFIG}"
)

cls._validate_deployment_url(config)
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

Because deployment.url is already included in REQUIRED_FIELDS, some invalid shapes (e.g. deployment present but not a dict) will be reported as “missing required field 'deployment.url'” and the more specific errors in _validate_deployment_url() won’t be reached. Consider removing deployment.url from REQUIRED_FIELDS and letting _validate_deployment_url() own both presence + format/type validation, or enhance the required-field traversal to surface type errors (e.g. non-dict deployment) before treating it as missing.

Copilot uses AI. Check for mistakes.
Comment on lines +149 to +153
if not isinstance(deployment_url, str) or not deployment_url.strip():
raise ConfigError(
"ConfigError: 'deployment.url' is a required field in the agent configuration."
)

Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

deployment_url type/emptiness validation currently raises a “required field” error even when the key exists but has the wrong type (e.g. url: 123). This makes debugging harder; consider distinguishing “missing/empty” from “must be a non-empty string” (and optionally include the actual type/value in the message).

Suggested change
if not isinstance(deployment_url, str) or not deployment_url.strip():
raise ConfigError(
"ConfigError: 'deployment.url' is a required field in the agent configuration."
)
# Distinguish between missing/empty and wrong-type values for clearer errors.
if deployment_url is None or (
isinstance(deployment_url, str) and not deployment_url.strip()
):
raise ConfigError(
"ConfigError: 'deployment.url' is a required non-empty string field in the agent configuration."
)
if not isinstance(deployment_url, str):
raise ConfigError(
"ConfigError: 'deployment.url' must be a non-empty string in the agent configuration, "
f"got value {deployment_url!r} of type {type(deployment_url).__name__}."
)

Copilot uses AI. Check for mistakes.
@Brian-code-123 Brian-code-123 changed the title fix: 強化 Penguin bindufy 設定驗證與錯誤訊息 fix: Improve Penguin Bindufy configuration validation and error messages. Mar 30, 2026
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.

[Enhancement]: Robust configuration validation and error handling for Penguin SDK

2 participants