Closing a Vision Window on Error in visionWindowOpened

I have an instance where a Try:Catch is throwing an exception in my visionWindowOpened. In this case, I want to display a MessageBox for the operator and then close out the Window once they acknowledge the error.
The message box piece works, but I cannot seem to close the window. I get a Java error when I try to close the window. I assume this is because the Window has not completed the Open at this point. Is there a way around this?

Example:
system.gui.messageBox(“Please verify system is online.”,“System Unavailable.”)
system.nav.closeWindow("{Window Name}")

Also tried system.nav.closeWindow(event.source)

Can you post your complete script of your visionWindowOpened?

try:
if	system.gui.getParentWindow(event).getComponentForPath('Root Container.tblLocationCodes').data == None
system.gui.getParentWindow(event).getComponentForPath('Root Container').errorWindowsClose = False
except:
	system.gui.messageBox("Please verify system is online","System Unavailable.")
	system.nav.closeWindow("addLocationCode")

I am reaching the MessageBox as expected, but am getting a Java NullPointer error on the closeWindow. I pulled out all of the code except for the closeWindow command and got the same error.

Are you sure that is the exact spelling of your window name? What happens if you use this instead
system.nav.closeParentWindow(event)

Using system.nav.closeParentWindow(event) yields the same java error.

Get the error again, click on “Details” in the error message box, and paste that here.

Please also show the lines that open that popup window.

window = system.nav.openWindow('addLocationCode', {'parentPath':parentPath, 'componentName':componentName, 'agvSystemID': agvSystemID})
system.nav.centerWindow(window)

Error on Close:
Traceback (most recent call last):
File “event:actionPerformed”, line 11, in
java.lang.NullPointerException: java.lang.NullPointerException

caused by NullPointerException

Ignition v8.1.7 (b2021060314)
Java: Azul Systems, Inc. 11.0.11

I was able to get around this by setting a custom property and then checking for that property to change in the Root Container Script. It works, but seems like a lot of extra code.