# Aborted deployments and state script cleanup

**URL:** <https://hub.mender.io/t/aborted-deployments-and-state-script-cleanup/5157>\
**Category:** General Discussions\
**Tags:** yocto\
**Created:** [July 31, 2022, 6:17pm UTC](https://hub.mender.io/t/aborted-deployments-and-state-script-cleanup/5157 "2022-07-31T18:17:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [July 31, 2022, 6:17pm UTC](https://hub.mender.io/t/aborted-deployments-and-state-script-cleanup/5157/1 "2022-07-31T18:17:10Z")

</div>

Hi all,

I’m using a state script on Download\_Enter that uses the server API to get the deployment artifact name. I’m using the name of the artifact to communicate meta-data about the update to the device. The application can then, with user input, selectively allow or delay the update based on the specific metadata.

The success case works just fine but in the case of an aborted deployment, I see no way to detect this situation and cleanup. The [docs](https://docs.mender.io/artifact-creation/state-scripts#the-nine-states) state that most states have an “Error” transition but it seems that does not correspond to a state script. I see logging info that the client has detected the aborted deployment but there does not appear any way for that to extend to my state scripts.

I _guess_ the right approach is to cleanup in a Sync\_Leave script. Does anyone have any other suggestions here?

Also, there are two “Leave” transitions from the Sync state; one to Download and one to Idle. Is there any way to know within the state script which transition is happening?

Drew

---

<div class="post-metadata">

**Author:** ![kacf](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kacf/32/146_2.png) [@kacf](https://hub.mender.io/u/kacf)\
**Post date:** [August 10, 2022, 7:23am UTC](https://hub.mender.io/t/aborted-deployments-and-state-script-cleanup/5157/2 "2022-08-10T07:23:13Z")

</div>

> [@drewmoseley](#):
>
> I _guess_ the right approach is to cleanup in a Sync\_Leave script. Does anyone have any other suggestions here?

I believe that `Sync_Leave` happens before `Download_Enter` (you can only be in one state at a time), so I think this won’t work. I suggest cleaning up in `Idle_Enter` instead, which the client will always return to after an update, regardless of whether it was successful or not.

> [@drewmoseley](#):
>
> Also, there are two “Leave” transitions from the Sync state; one to Download and one to Idle. Is there any way to know within the state script which transition is happening?

Not at the time when you leave, no. You’ll have to piece this together by seeing which `Enter` you reach after the `Leave`.
