Error in restarting a phase via Jython Script

I have a piece of code that we use to restart a phase when there is an issue found when running the template. (The issue occurs outside of the template process, such as code errors, so we restart the phase to allow new code to be deployed for a given release phase.) The code works to restart the phase, but it does show a failure each time it runs, then recovers and restarts the phase. I believe I have narrowed it down to one of the last 2 lines of the script, but can’t determine where the failure is actually coming from. Code is:

from com.xebialabs.xlrelease.repository import PhaseVersion
release = getCurrentRelease()
planningPhaseTitle = “Planning”
firstPlanningPhaseTaskTitle = “Testing in lower environments?”
planningPhase = phaseApi.searchPhasesByTitle(planningPhaseTitle,[-1]
firstPlanningTask = taskApi.searchTasksByTitle(firstPlanningPhaseTaskTitle, planningPhase.title,[-1]
releaseApi.restartPhase(release, planningPhase, firstPlanningTask, PhaseVersion.LATEST, True)

Does anyone see anything that stands out that would produce a failure of the script, but allows it to recover and restart the phase?

Hi CindyA, what error message you are getting ? Which line is failing ?