Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Need a way to abort charm execution

See original GitHub issue

As a charmer, I’d like a way to abort charm execution from anywhere. Use case: I have a charm with many event handlers, but regardless of which event we’re in, I want the charm to do nothing and exit with blocked state if a certain precondition is not met, say, a certain config value is provided. Right now I have to, for each event handler, add a check:

if not self.condition():
    self.unit.status = ...

I could raise an exception in __init__, but that would leave the charm in error state.

I propose to add a Framework.abort() method that raises an exception that gets caught in main and terminates charm execution without committing any state (status will pass through because that’s committed synchronously).

With that, I would only need to add these three lines:

# in MyCharm.__main__:
if not self.condition():

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:21 (16 by maintainers)

github_iconTop GitHub Comments

beliaev-maksimcommented, Nov 23, 2022

@benhoyt I will add it as part of sdk tutorial and also add “how to” section on

I will let you review it once ready

PietroPasotticommented, Nov 16, 2022

@benhoyt for my best understanding of what happens when in terms of syncing with juju: see the second section of this doc

The logic of the code you wrote above is what we need, the issue is: do we want to expose a high-level callable that abstracts it, or do we leave it to the charmers to remember to call framework.commit() before they exit?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Charm — Charm4py 1.0.0 documentation
abort (message): Aborts the program, printing the specified message and a stack trace of the PE which aborted. It can be called from...
Read more >
Charm hooks - doc - Charmhub - Juju Discourse
Hooks are executable files in a charm's hooks directory; hooks with ... enter an error state if the unit agent process is aborted...
Read more >
A Stay of Execution for Lizzy | Dishonored Wiki - Fandom
An Officer executes three guards. The mission starts outside Coldridge Prison where Daud must infiltrate the building and find Lizzy Stride.
Read more >
I personally think that the report should only be used by a ChaRM administrator or IT-operator, but not by any other users.
Read more >
Charm++ Documentation - Read the Docs
will not interrupt an executing method to start any other work, and all calls ... Every Charm++ program must have at least one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found