docs: document two related Indigo exec/open() gotchas#42
Conversation
IndigoPluginHost3 runs Python with a locale where open() defaults to ASCII encoding, not UTF-8. Any code that does open(path).read() on a file containing common UTF-8 characters (em-dash, arrows, currency symbols, accented letters) crashes with: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 ... This bites scripts that exec() another script to reuse functions, plugins reading bundled JSON/text resources, and any code loading UTF-8 user content. Add a subsection under "Python 3 Issues" in troubleshooting/common-issues.md covering symptom, cause, common byte sequences seen, and the fix: always pass encoding="utf-8" to open() and Path.read_text(). Confirmed 14-May-2026 on Indigo 2025.2 / Python 3.13.9 — four trigger scripts using the exec(open(controller_path).read()) pattern all failed at byte 134 (em-dash in the controller's Description header). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds a troubleshooting guide for ChangesUnicodeDecodeError Troubleshooting Documentation
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsStopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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
🤖 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 `@docs/plugin-dev/troubleshooting/common-issues.md`:
- Around line 453-455: The fenced code block containing the UnicodeDecodeError
message is missing a language tag and triggers markdownlint MD040; update the
fenced block in docs/plugin-dev/troubleshooting/common-issues.md to include a
language identifier (e.g., replace the opening "```" with "```text") so the
snippet is treated as plain text and the linter warning is resolved.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: b5cdba78-4ac9-4a0d-a0b0-de0ad95afcba
📒 Files selected for processing (1)
docs/plugin-dev/troubleshooting/common-issues.md
The "exec a shared library" pattern hits a second non-obvious failure
mode under Indigo, separate from the UTF-8 default:
NameError: name 'log' is not defined
after a successful exec(). Cause: Indigo runs embedded trigger/action
scripts inside a function wrapper, so globals() != locals() at the
exec() call site. Per Python's documented semantics, exec() in that
case puts definitions into locals() only — they never reach the
module global namespace where subsequent code looks for them.
Fix: pass globals() explicitly to exec():
exec(_f.read(), globals())
The two gotchas (ASCII default open() + locals-bound exec()) are
companions — the exec-a-shared-library pattern needs both to work
reliably under Indigo. Documented together in the same Python 3
Issues subsection so anyone hitting one finds the other.
Confirmed 14-May-2026 on Indigo 2025.2 / Python 3.13.9 — same garage
door controller refactor that exposed the UTF-8 issue then hit
NameError on every function call once encoding was fixed.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
CodeRabbit flagged two bare ``` fences (the UnicodeDecodeError and NameError symptom blocks) as triggering markdownlint MD040. Add `text` language tags to both so they're treated as plain text and the linter warning clears. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Summary
Adds two related, undocumented gotchas to
docs/plugin-dev/troubleshooting/common-issues.md(under "Python 3 Issues"). Both bite the same "exec another script to reuse its functions" pattern that's common in larger Indigo automation setups.Gotcha 1 —
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2IndigoPluginHost3runs Python with a locale that defaultsopen()to ASCII. Files containing—,→,°,£, accented letters etc. crash on read. Fix: passencoding=\"utf-8\"explicitly to everyopen()call (and toPath.read_text()).Gotcha 2 —
NameError: name '<function>' is not definedafterexec()Indigo runs embedded trigger/action scripts inside a function wrapper, so
globals()andlocals()are different dicts at theexec()call site. Per Python's documented semantics,exec()then binds new definitions tolocals()only — they never reach the module globals where subsequent code looks for them. Fix:exec(code, globals()).The two are companions: the "exec a shared library" pattern needs both
encoding=\"utf-8\"AND explicitglobals()to work reliably under Indigo. Anyone hitting one will likely hit the other next, so they're documented together.Why this matters
Hit both on 14-May-2026 during a real automation refactor:
exec(open(controller_path).read())all crashed at byte 134 — the em-dash in the controller's# Description:headerencoding=\"utf-8\", every script then failed withNameError: name 'log' is not definedon the next lineBoth errors mislead developers: the first blames the file being read, the second suggests the library didn't define the function. Neither symptom points at
open()'s default encoding orexec()'s scope handling.Pure documentation change — no code touched.
Test plan
common-issues.mdunder "Python 3 Issues"exec()/globals()section🤖 Generated with Claude Code