Skip to content

Misconfigured backend surfaces misleading error #64

@dev-dull

Description

@dev-dull

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions