PyTerraBackTyl icon indicating copy to clipboard operation
PyTerraBackTyl copied to clipboard

Misconfigured backend surfaces misleading error

Open dev-dull opened this issue 1 month ago • 0 comments

Unless you squint at the error message, a misconfigured backend can result in a misleading KeyError: 'backend' error message.

2025-10-13 08:07:51,886 - PyTerraBackTyl - ERROR - Exception on / [GET]
Traceback (most recent call last):
  File "/Users/alastairdrong/wip/PyTerraBackTyl/.venv/lib/python3.13/site-packages/flask/app.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/alastairdrong/wip/PyTerraBackTyl/.venv/lib/python3.13/site-packages/flask/app.py", line 919, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/alastairdrong/wip/PyTerraBackTyl/.venv/lib/python3.13/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/alastairdrong/wip/PyTerraBackTyl/.venv/lib/python3.13/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/alastairdrong/wip/PyTerraBackTyl/pyterrabacktyl.py", line 144, in tf_backend
    t = _backends[_env][C.TYL_KEYWORD_BACKEND].get_tfstate()
        ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'backend'
2025-10-13 08:07:51,888 - werkzeug - INFO - 127.0.0.1 - - [13/Oct/2025 08:07:51] "GET /?env=InT HTTP/1.1" 500 -

The result from the backend should be tested for a valid response and surfaced to the user. In the instance above, the real error was, FileNotFoundError: [Errno 2] No such file or directory: '/opt/pyterrabacktyl/data/InT_terraform_state' which only appears many lines above the KeyError and is easy to miss.

dev-dull avatar Oct 13 '25 17:10 dev-dull