You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A failed environment creation leaves the window open and shows no error, unlike a failed load #42
In main() (main.py), the call to environmentService.create_environment("Test", numGrids, gridSize) is not wrapped in any error handling, unlike the cached-environment path just above it, which catches the exception from get_environment_by_id, logs it, draws Error loading environment, please check logs. in red, waits about two seconds and calls window.close().
Viron's EnvironmentService.create_environment calls response.raise_for_status(), and requests.post raises when the server is unreachable, so on a failed creation:
the exception propagates out of main(), and the CLI exits with a traceback and status 1;
Creating environment, please wait... is the last thing shown in the window, and no error message is drawn;
window.close() is never called, so Pygame is left initialised for any caller that invokes main() directly and catches the exception;
nothing is written to environments.json, and no environment-created event is reported.
This behaviour is now documented in the README and characterized by tests/test_main.py::test_a_failed_creation_propagates_without_recording_the_environment. That test deliberately does not assert anything about window.close(), so that the inconsistency is not locked in.
Question
It is not evident from the source whether the asymmetry is intended. create_environments.bat depends on the non-zero exit status to report Error occurred while running with size <n>., so any fix that mirrors the load path should still exit non-zero from the CLI (for example by closing the window and re-raising, or by returning a status that the __main__ block passes to sys.exit).
Acceptance criteria
A decision is recorded on whether a failed creation should be handled like a failed load.
If so, the window is closed and an error message is shown on failure, the CLI still exits non-zero, and a unit test under tests/ asserts window.close() is called when create_environment raises.
The same question was found to apply to further paths in main(), which are characterized in #56 without being changed. Each of these also propagates out of main() with Pygame still initialised and no error drawn in the window:
environments.json being empty or not valid JSON (main.py:105)
environments.json holding valid JSON that is not an object, such as [], which fails only after create_environment has run, so an unrecorded Viron environment is left behind on every run
a cache entry with no environment_id, because the lookup at main.py:113 sits just above the try
get_locations_in_environment failing, on the --exit-after-create path (main.py:145) or in the render loop (main.py:157), including straight after a successful load
The decision recorded here could therefore be taken for failures after the window opens in general, rather than for creation alone. As with creation, create_environments.bat depends on the non-zero exit status, so any change would still need the CLI to exit non-zero. Those tests also leave window.close() unasserted.
Activity
dmccoystephenson commentedon Nov 4, 2026
The same question was found to apply to further paths in
main(), which are characterized in #56 without being changed. Each of these also propagates out ofmain()with Pygame still initialised and no error drawn in the window:environments.jsonbeing empty or not valid JSON (main.py:105)environments.jsonholding valid JSON that is not an object, such as[], which fails only aftercreate_environmenthas run, so an unrecorded Viron environment is left behind on every runenvironment_id, because the lookup atmain.py:113sits just above thetryget_locations_in_environmentfailing, on the--exit-after-createpath (main.py:145) or in the render loop (main.py:157), including straight after a successful loadThe decision recorded here could therefore be taken for failures after the window opens in general, rather than for creation alone. As with creation,
create_environments.batdepends on the non-zero exit status, so any change would still need the CLI to exit non-zero. Those tests also leavewindow.close()unasserted.This comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).
drafted by Claude on behalf of Daniel Stephenson
Characterize main's unguarded cache and location failures (#56)