Adding new StringFormat node#13997
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds a new StringFormat node to the string utilities module. The node accepts an autogrowing mapping 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
comfy_extras/nodes_string.py (1)
33-36: ⚡ Quick winConsider adding error handling for format exceptions.
The
str.format()method can raiseKeyError(missing key in template) orValueError(invalid format specifier) for malformed format strings. Other nodes in this file (RegexMatch,RegexExtract,JsonExtractString) catch expected exceptions and return safe defaults, providing better user experience.Consider wrapping the format call in a try-except block to handle format errors gracefully.
♻️ Proposed error handling
`@classmethod` def execute( cls, values: io.Autogrow.Type, f_string: str ) -> io.NodeOutput: - return io.NodeOutput(f_string.format(**values)) + try: + return io.NodeOutput(f_string.format(**values)) + except (KeyError, ValueError) as e: + return io.NodeOutput(f"Format error: {str(e)}")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@comfy_extras/nodes_string.py` around lines 33 - 36, The execute method in the class (execute in comfy_extras/nodes_string.py) calls f_string.format(**values) without guarding against formatting errors; wrap that call in a try/except that catches KeyError and ValueError (and optionally Exception) and return a safe default via io.NodeOutput (e.g., empty string or the original template) on error, and log or include the error message if appropriate so behavior matches other nodes like RegexMatch/RegexExtract/JsonExtractString.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@comfy_extras/nodes_string.py`:
- Around line 12-25: The autogrow template (io.Autogrow.TemplateNames used for
the "values" input) sets min=0 but the default f_string is "{a}", which can
KeyError when no parameters exist; update either autogrow to require at least
one parameter by changing min from 0 to 1, or make the default f_string safe
(e.g., set default to an empty string "") so the node_id "StringFormat" / input
"f_string" no longer references a missing parameter—choose and apply one of
these fixes consistently in the Schema definition.
---
Nitpick comments:
In `@comfy_extras/nodes_string.py`:
- Around line 33-36: The execute method in the class (execute in
comfy_extras/nodes_string.py) calls f_string.format(**values) without guarding
against formatting errors; wrap that call in a try/except that catches KeyError
and ValueError (and optionally Exception) and return a safe default via
io.NodeOutput (e.g., empty string or the original template) on error, and log or
include the error message if appropriate so behavior matches other nodes like
RegexMatch/RegexExtract/JsonExtractString.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 757ff8de-d5fd-4975-ad42-73261104ac09
📒 Files selected for processing (1)
comfy_extras/nodes_string.py
Co-authored-by: Alexis Rolland <alexis@comfy.org>

This PR adds in a new StringFormat node that just uses Python's string format method.
Similar to the MathExpression node, it supports a maximum of 26 different arguments (a-z).
The Python string format method is very useful: