batou
batou copied to clipboard
Track component initialisations for error messages
closes #278
provides a warning if a component is initialized, but not prepared:
Say we have the tutorial-helloworld
:
component.py
:
class Hello(Component):
def configure(self):
self += File("hello", content="Hello world")
File("")
This gives us an error message like this:
batou/2.5.dev0 (cpython 3.7.16-final0, Darwin 23.1.0 arm64)
================================== Preparing ===================================
main: Loading environment `tutorial`...
main: Verifying repository ...
main: Loading secrets ...
================== Connecting hosts and configuring model ... ==================
localhost: Connecting via local (1/1)
WARN: A Component 'File' was initialized but was not prepared (configured).
This may not be what you want
================================== Deploying ===================================
localhost: Scheduling component hello ...
=================================== Summary ====================================
Deployment took total=0.23s, connect=0.23s, deploy=0.00s
============================= DEPLOYMENT FINISHED ==============================
Of course the warning is yellow too:
What does the output look like now? Does the user have a chance to figure out where this happened? (We can keep track of the call stack during init and then use that to indicate the problem later.)
We can keep track of the call stack during init and then use that to indicate the problem later.)
PR doesn't included that yet so I'll draft this one
Currently looks like this:
On input:
from batou.component import Component
from batou.lib.file import File
class Hello(Component):
def configure(self):
self += File("hello", content="Hello world")
self += FooComponent()
class FooComponent(Component):
def configure(self):
BarComponent()
class BarComponent(Component):
pass
batou/2.5.0b3.dev0 (cpython 3.11.9-final0, Darwin 23.5.0 arm64)
================================================= Preparing =================================================
main: Loading environment `tutorial`...
main: Verifying repository ...
main: Loading secrets ...
================================ Connecting hosts and configuring model ... =================================
localhost: Connecting via local (1/1)
WARN: Unused components:
'BarComponent': Hello -> FooComponent
================================================= Deploying =================================================
localhost: Scheduling component hello ...
================================================== Summary ==================================================
Deployment took total=0.24s, connect=0.24s, deploy=0.00s
============================================ DEPLOYMENT FINISHED ============================================
This is what the output looks like now
See the note about that this should be erroring out instead of just warning.
We don't want to have an error here. We just don't know what people are doing out there and having an error where you have no means of getting out of it is bad.