tonyandrewmeyer/charming-with-claude/testing-exception-wrapping

Claude Code and agent skill by tonyandrewmeyer/charming-with-claude

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Install

npx vskill@latest install tonyandrewmeyer/charming-with-claude/testing-exception-wrapping

SKILL.md

The same SKILL.md was published earlier as tonyandrewmeyer/charming-with-claude/testing-exception-wrapping.

Skill: Adopt SCENARIO_BARE_CHARM_ERRORS

Enable bare exception propagation in ops.testing so that charm exceptions surface directly instead of being wrapped in UncaughtCharmError.

When to Use

Use this when a charm has unit tests using ops.testing and you want cleaner tracebacks and more natural exception assertions.

Prerequisites

  • ops >= 3.5.0
  • The charm has unit tests using ops.testing

Step 1: Check Current Exception Handling

Search test files for:

  • UncaughtCharmError — tests catching the wrapper
  • e.__cause__ — tests unwrapping to get the original exception
  • Broad except Exception in test code around ctx.run() calls

Step 2: Set the Environment Variable

Add SCENARIO_BARE_CHARM_ERRORS=true to the test environment.

In tox.ini:
ini
[testenv:unit]
setenv =
SCENARIO_BARE_CHARM_ERRORS=true
Or in pyproject.toml (if using pytest directly):
toml
[tool.pytest.ini_options]
env = [
"SCENARIO_BARE_CHARM_ERRORS=true",
]

Step 3: Update Affected Tests

Tests catching UncaughtCharmError
python
# Before:
from ops.testing import UncaughtCharmError
def test_bad_config():
ctx = testing.Context(MyCharm)
with pytest.raises(UncaughtCharmError) as exc_info:
ctx.run(ctx.on.config_changed(), state)
assert isinstance(exc_info.value.__cause__, ValueError)
# After:
def test_bad_config():
ctx = testing.Context(MyCharm)
with pytest.raises(ValueError, match="Invalid config"):
ctx.run(ctx.on.config_changed(), state)
Tests that don't check exceptions

Tests that don't catch UncaughtCharmError are unaffected — they'll just get better tracebacks when things go wrong.

Step 4: Verify

  1. Run tox -e unit — all tests should pass.
  2. Intentionally break something and verify the traceback is cleaner (shows the original exception directly).

Exemplar Charms

No downstream charm has adopted this yet. Reference:

  • [canonical/operator](https://github.com/canonical/operator) (tox.ini) — ops' own tests use this env var.

Common Mistakes

  • Don't set this in production code — it's a testing-only environment variable.
  • Don't forget to update tests that explicitly catch UncaughtCharmError — they'll start failing because the exception type changes.
  • The variable name is SCENARIO_BARE_CHARM_ERRORS (legacy name from the ops-scenario era) — don't misspell it.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
5

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/tonyandrewmeyer/charming-with-claude/testing-exception-wrapping/badge)](https://verified-skill.com/skills/tonyandrewmeyer/charming-with-claude/testing-exception-wrapping)

Something wrong with this skill or its page? Tell us.