flyingcircusio / batou

batou is a universal, fractal deployment utility using Python.
https://batou.readthedocs.org
Other
47 stars 12 forks source link

Track component initialisations for error messages #420

Closed elikoga closed 2 weeks ago

elikoga commented 6 months ago

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:

image

ctheune commented 4 months ago

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.)

elikoga commented 2 months ago

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

elikoga commented 2 weeks ago

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 ============================================
image
elikoga commented 2 weeks ago

image This is what the output looks like now

zagy commented 2 weeks ago

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.