batou icon indicating copy to clipboard operation
batou copied to clipboard

Track component initialisations for error messages

Open elikoga opened this issue 1 year ago • 2 comments

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

elikoga avatar Dec 19 '23 00:12 elikoga

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

ctheune avatar Feb 28 '24 10:02 ctheune

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 avatar Apr 23 '24 09:04 elikoga

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 avatar Jun 20 '24 01:06 elikoga

image This is what the output looks like now

elikoga avatar Jun 25 '24 02:06 elikoga

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.

zagy avatar Jun 25 '24 09:06 zagy