Skip to content

docs: document two related Indigo exec/open() gotchas#42

Open
Highsteads wants to merge 3 commits into
simons-plugins:mainfrom
Highsteads:clives-utf8-open-gotcha
Open

docs: document two related Indigo exec/open() gotchas#42
Highsteads wants to merge 3 commits into
simons-plugins:mainfrom
Highsteads:clives-utf8-open-gotcha

Conversation

@Highsteads
Copy link
Copy Markdown

@Highsteads Highsteads commented May 14, 2026

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 0xe2
IndigoPluginHost3 runs Python with a locale that defaults open() to ASCII. Files containing , , °, £, accented letters etc. crash on read. Fix: pass encoding=\"utf-8\" explicitly to every open() call (and to Path.read_text()).

Gotcha 2 — NameError: name '<function>' is not defined after exec()
Indigo runs embedded trigger/action scripts inside a function wrapper, so globals() and locals() are different dicts at the exec() call site. Per Python's documented semantics, exec() then binds new definitions to locals() 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 explicit globals() 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:

  1. Four contact-sensor/router scripts using exec(open(controller_path).read()) all crashed at byte 134 — the em-dash in the controller's # Description: header
  2. After fixing with encoding=\"utf-8\", every script then failed with NameError: name 'log' is not defined on the next line

Both 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 or exec()'s scope handling.

Pure documentation change — no code touched.

Test plan

  • Both subsections render correctly in common-issues.md under "Python 3 Issues"
  • Markdown table for byte sequences formats correctly
  • Code blocks use proper fences
  • Cross-reference from UTF-8 section forwards readers to the exec()/globals() section
  • (reviewer) Check tone/structure matches surrounding subsections

🤖 Generated with Claude Code

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Warning

Rate limit exceeded

@Highsteads has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 51 minutes before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c8116dae-83a6-48c3-ac85-0edcef4c6a98

📥 Commits

Reviewing files that changed from the base of the PR and between 74a1d12 and ed91854.

📒 Files selected for processing (1)
  • docs/plugin-dev/troubleshooting/common-issues.md
📝 Walkthrough

Walkthrough

This PR adds a troubleshooting guide for UnicodeDecodeError in the Indigo plugin development documentation. The section explains that IndigoPluginHost3 defaults to ASCII encoding, provides examples of problematic code patterns, and documents the fix of explicitly specifying encoding="utf-8" when reading files.

Changes

UnicodeDecodeError Troubleshooting Documentation

Layer / File(s) Summary
UnicodeDecodeError troubleshooting guide
docs/plugin-dev/troubleshooting/common-issues.md
New subsection under "Python 3 Issues" documents the symptom, trigger patterns using exec(open(...).read()) and open(...).read(), explains that IndigoPluginHost3 locale defaults open() to ASCII, and provides remediation using encoding="utf-8" parameter. Also notes Path.read_text() has the same issue.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A codec tale, oh what a plight,
When ASCII reads what should be UTF-eight,
The plugin host whispered in locale's might,
Add encoding="utf-8" to set things right! 📜✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'docs: document two related Indigo exec/open() gotchas' directly matches the main change: documenting the undocumented ASCII default behavior of open() and Path.read_text() in IndigoPluginHost3.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

Warning

Review ran into problems

🔥 Problems

Stopped 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 @coderabbit review after the pipeline has finished.

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 05c6678 and 74a1d12.

📒 Files selected for processing (1)
  • docs/plugin-dev/troubleshooting/common-issues.md

Comment thread docs/plugin-dev/troubleshooting/common-issues.md Outdated
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>
@Highsteads Highsteads changed the title docs: document open()/ASCII default gotcha in Indigo's Python docs: document two related Indigo exec/open() gotchas May 14, 2026
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>
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.

1 participant