Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track component initialisations for error messages #420

Merged
merged 10 commits into from
Jun 25, 2024

Conversation

elikoga
Copy link
Member

@elikoga elikoga commented Dec 19, 2023

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 elikoga marked this pull request as ready for review December 19, 2023 02:11
@elikoga elikoga requested a review from ctheune as a code owner December 19, 2023 02:11
ctheune
ctheune previously approved these changes Dec 19, 2023
src/batou/environment.py Outdated Show resolved Hide resolved
@ctheune ctheune dismissed their stale review December 19, 2023 06:30

incorrectly approved

Copy link
Member

@ctheune ctheune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the note about that this should be erroring out instead of just warning.

@elikoga elikoga force-pushed the 278-track-component-initialisations-for branch from d2f74c9 to b675af2 Compare December 20, 2023 14:19
@ctheune
Copy link
Member

ctheune commented Feb 28, 2024

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

Copy link
Member

@zagy zagy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog is missing.

@elikoga
Copy link
Member Author

elikoga commented Apr 23, 2024

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 elikoga marked this pull request as draft April 23, 2024 09:17
@elikoga elikoga force-pushed the 278-track-component-initialisations-for branch from db868fd to 5380434 Compare June 20, 2024 00:47
@elikoga
Copy link
Member Author

elikoga commented Jun 20, 2024

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 elikoga marked this pull request as ready for review June 20, 2024 01:49
@zagy zagy self-requested a review June 20, 2024 09:25
Copy link
Member

@zagy zagy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning message should be improved:

  • e.g. Component was not added. self += … missing?
  • We know the file and line number from the stack, put it out.

@elikoga
Copy link
Member Author

elikoga commented Jun 25, 2024

image
This is what the output looks like now

@zagy
Copy link
Member

zagy commented Jun 25, 2024

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 zagy dismissed ctheune’s stale review June 25, 2024 09:38

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 zagy merged commit 7e13886 into main Jun 25, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn if subcomponent is not added
3 participants