Git Product home page Git Product logo

Comments (5)

mrowe avatar mrowe commented on August 22, 2024

Here is the simplest "solution":

diff --git a/aminator/core.py b/aminator/core.py
index f73f9cf..5c22709 100644
--- a/aminator/core.py
+++ b/aminator/core.py
@@ -55,7 +55,7 @@ class Aminator(object):

     def aminate(self):
         with self.environment(self.config, self.plugin_manager) as env:
-            error = env.provision()
+            error = not env.provision()
             if not error:
                 log.info('Amination complete!')
         return error
diff --git a/aminator/environment.py b/aminator/environment.py
index b3288ea..e4c927e 100644
--- a/aminator/environment.py
+++ b/aminator/environment.py
@@ -56,7 +56,7 @@ class Environment(object):
                     if not success:
                         log.critical('Finalizing failed!')
                         return False
-        return None
+        return True

     def __enter__(self):
         return self

But that feels kind of icky.

from aminator.

bmoyles avatar bmoyles commented on August 22, 2024

Augh, that is entirely my fault again--documentation for sys.exit, of course, says success on 0 or None and says 'any other object' will result in a status code of 1.

The intention was to have whatever the success value was from the environment get passed on down through the stack to sys.exit. If everything succeeded, sys.exit would get None, if there was a failure, sys.exit would get False. sys.exit, it seems, actually returns a status code of 1 for a value of true of all things, so the above code will possibly cause the overall process to fail when it really succeeded:

% python -c 'import sys; sys.exit(True)'; echo $?
1

% python -c 'import sys; sys.exit(None)'; echo $?
0

% python -c 'import sys; sys.exit(False)'; echo $?
0

% python -c 'import sys; sys.exit("banana")'; echo $?
banana
1

The easiest way to fix that? Each of the checks in the context managers:

                    if not success:
                        log.critical('Finalizing failed!')
                        return False

for example, need to return True.

So, given

    def provision(self):
        [...]
                        success = provisioner.provision()
                        if not success:
                            log.critical('Provisioning failed!')
                            return True
                    success = finalizer.finalize()
                    if not success:
                        log.critical('Finalizing failed!')
                        return True
        return None

This

    def aminate(self):
        with self.environment(self.config, self.plugin_manager) as env:
            error = env.provision()
            if not error:
                log.info('Amination complete!')
        return error

has error = True on failure, Amination complete will get logged on success, error is None if success, True if failure, and as we saw, sys.exit(True) is a failed execution. All is right with the world.

from aminator.

bmoyles avatar bmoyles commented on August 22, 2024

That said, for readability's sake, it probably makes a bit more sense to use some kind of value that will clearly indicate failure but doesn't require one to build truth tables to sort out because of funky logic inversion :)

from aminator.

pas256 avatar pas256 commented on August 22, 2024

Does this:
08a47de

Resolve this issue?

from aminator.

coryb avatar coryb commented on August 22, 2024

Yeah, I think it is fixed. Thanks Peter.
-Cory

from aminator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.