Skip to content

fix: Raise proper error message for invalid format functions#68

Merged
Ruari-Phipps merged 3 commits intomainfrom
ruari/fix/improve_error_message_untyped_functions
Apr 10, 2026
Merged

fix: Raise proper error message for invalid format functions#68
Ruari-Phipps merged 3 commits intomainfrom
ruari/fix/improve_error_message_untyped_functions

Conversation

@Ruari-Phipps
Copy link
Copy Markdown
Collaborator

@Ruari-Phipps Ruari-Phipps commented Apr 10, 2026

Summary

Fixes two related issues: untyped or unsupported function parameters now raise a clear ValueError instead of crashing with AttributeError, and merge-conflicted files are correctly excluded from modified_files in project_status and handled without crashing in get_diffs. Also surfaces all CLI errors as structured JSON when --json is set.

Motivation

In v0.6.x, functions with untyped parameters (e.g. def f(conv, booking_ref)) caused _extract_decorators to crash with AttributeError: 'NoneType' has no attribute 'id'. Separately, files with merge conflicts were being passed to read_local_resource, which would now raise rather than silently fail. Both issues needed to be fixed together for poly status and poly diff to be reliable after a branch pull with conflicts.

Closes #

Changes

  • _extract_decorators: guard arg.annotation access before reading .id; raise ValueError with a distinct message for missing vs unsupported type annotations; remove the try/except SyntaxError wrapper so errors propagate to the user
  • resource.py: rename get_statusis_modified, removing merge conflict detection from the resource itself
  • project_status: check for merge conflicts on raw file content before calling read_local_resource; conflicted files now appear only in files_with_conflicts, not also in modified_files
  • get_diffs: same conflict-before-parse pattern; shows diff of conflict markers vs original; fix type(resource_type) key bug and missing second arg to get_diff
  • cli.py: wrap the command dispatch in try/except; when --json is set, errors are returned as {"success": false, "error": "...", "traceback": "..."} instead of raising
  • src/poly/docs/functions.md: note that all parameters must have a supported type annotation

Test strategy

  • Added/updated unit tests
  • Manual CLI testing (poly <command>)
  • Tested against a live Agent Studio project
  • N/A (docs, config, or trivial change)

Checklist

  • ruff check . and ruff format --check . pass
  • pytest passes
  • No breaking changes to the poly CLI interface (or migration path documented)
  • Commit messages follow conventional commits

Screenshots / Logs

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

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

Improves ADK’s robustness when parsing function decorators and handling merge-conflicted files so poly status, poly diff, and --json error output behave predictably instead of crashing on edge cases.

Changes:

  • Make _extract_decorators raise clear ValueErrors for missing/unsupported type annotations (instead of crashing).
  • Exclude merge-conflicted files from modified_files and avoid parsing conflicted content in project_status / get_diffs.
  • Emit structured JSON errors (with traceback) from the CLI when --json is set; update docs and tests accordingly.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/poly/resources/function.py Updates decorator extraction to validate annotations and raise ValueError on invalid formats.
src/poly/resources/resource.py Renames status API to is_modified() and removes merge-conflict detection from the resource layer.
src/poly/project.py Detects merge conflicts from raw file contents before parsing; adjusts status/diff behavior.
src/poly/cli.py Wraps command dispatch to return structured JSON error payloads when --json is used.
src/poly/docs/functions.md Documents that parameters must have supported type annotations.
src/poly/tests/resources_test.py Adds unit tests covering new decorator-extraction error cases.
src/poly/tests/project_test.py Updates merge-conflict status expectations (conflicts no longer count as modified).

Comment thread src/poly/resources/function.py
Comment thread src/poly/project.py
Comment thread src/poly/cli.py
@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report

Base (main) PR Change
71.5% 71.5% +0.0% ✅

Changed file coverage

File Coverage Change
poly/cli.py 43.5% -0.2% ⚠️
poly/project.py 66.6% -0.1% ⚠️
poly/resources/pronunciation.py 78.1% +6.2% ✅
poly/resources/resource.py 79.5% -0.1% ⚠️
poly/resources/function.py 80.9% -0.5% ⚠️

Copy link
Copy Markdown
Contributor

@bill-parker bill-parker left a comment

Choose a reason for hiding this comment

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

lgtm!

@Ruari-Phipps Ruari-Phipps merged commit 5222f3e into main Apr 10, 2026
3 checks passed
@Ruari-Phipps Ruari-Phipps deleted the ruari/fix/improve_error_message_untyped_functions branch April 10, 2026 14:59
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.

3 participants