Uploaded image for project: 'Runtime'
  1. Runtime
  2. RUNTIME-214

Remove multiple logging of exceptions in PluginManager

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • 2.0.0 M3
    • 1.1.2
    • None
    • None

      When there is something wrong with the initialization or configuration of the PluginManager we get from multiple exceptions logged.
      Each exception shows the same kind of message, just with a different stack trace.

          [RUNTIME-214] Remove multiple logging of exceptions in PluginManager

          Closing for allowing import/export of the project in the ametys.org instance

          Cédric Damioli added a comment - Closing for allowing import/export of the project in the ametys.org instance

          Improvement is working after rebuilding the runtime.

          Sébastien Launay (Inactive) added a comment - Improvement is working after rebuilding the runtime.

          Fixed in revision 514 as this lack of improvement has been a pain in the ass recently!

          Sébastien Launay (Inactive) added a comment - Fixed in revision 514 as this lack of improvement has been a pain in the ass recently!

          I propose to fix this issue in trunk (2.0).

          Sébastien Launay (Inactive) added a comment - I propose to fix this issue in trunk (2.0).

          targetting this issue for 2. only

          Cédric Damioli added a comment - targetting this issue for 2. only

          From my understanding none quality framework internally logged exceptions if the exception is severe and is rethrown.
          I understand if the client write dirty code (e.g. catch without logging) that we may lose precious debugging information but IMHO this is not a framework issue but more of a newbie issue.

          That's why i want to get rid of the double logged exceptions and sensitize developers to prevent these kind of errors.

          A good reason is also that they tend to ignore red lines in LogFactor because there is too much exceptions and for them it's normal...
          I there was less exceptions and better access to them (only one by issue) they IMHO will be more involved with fixing these exceptions.

          Sébastien Launay (Inactive) added a comment - From my understanding none quality framework internally logged exceptions if the exception is severe and is rethrown . I understand if the client write dirty code (e.g. catch without logging) that we may lose precious debugging information but IMHO this is not a framework issue but more of a newbie issue . That's why i want to get rid of the double logged exceptions and sensitize developers to prevent these kind of errors . A good reason is also that they tend to ignore red lines in LogFactor because there is too much exceptions and for them it's normal ... I there was less exceptions and better access to them (only one by issue) they IMHO will be more involved with fixing these exceptions.

          +1 for the bottom modif (in initialize method) => may happen only at startup
          -1 for the top modif (in lookup method) => may happen in any badly-written code

          Raphaël Franchet added a comment - +1 for the bottom modif (in initialize method) => may happen only at startup -1 for the top modif (in lookup method) => may happen in any badly-written code

          So i proposed the following patch, for improving logs readability:

          Index: main/kernel/src/org/ametys/runtime/plugin/component/ThreadSafeComponentManager.java
          ===================================================================
          --- main/kernel/src/org/ametys/runtime/plugin/component/ThreadSafeComponentManager.java	(revision 323)
          +++ main/kernel/src/org/ametys/runtime/plugin/component/ThreadSafeComponentManager.java	(working copy)
          @@ -112,9 +112,7 @@
           
                   if (role == null)
                   {
          -            String message = "ThreadSafeComponentManager attempted to retrieve component with null role.";
          -            getLogger().error(message);
          -            throw new ComponentException(role, message);
          +            throw new ComponentException(role, "ThreadSafeComponentManager attempted to retrieve component with null role.");
                   }
                   
                   T component = _components.get(role);
          @@ -127,9 +125,7 @@
                       }
                       catch (Exception e)
                       {
          -                String errorMessage = "Unable to initialize component " + role;
          -                getLogger().error(errorMessage, e);
          -                throw new ComponentException(role, errorMessage, e);
          +                throw new ComponentException(role, "Unable to initialize component " + role, e);
                       }
                       
                       _components.put(role, component);
          @@ -175,9 +171,7 @@
               {
                   if (_initialized)
                   {
          -            String errorMessage = "ComponentManager has already been initialized";
          -            getLogger().error(errorMessage);
          -            throw new IllegalStateException(errorMessage);
          +            throw new IllegalStateException("ComponentManager has already been initialized");
                   }
                   
                   synchronized (this)
          @@ -196,13 +190,8 @@
                               }
                               catch (Exception e)
                               {
          -                        if (getLogger().isErrorEnabled())
          -                        {
          -                            getLogger().error("Caught an exception trying to initialize the component " + role, e);
          -
          -                            // Rethrow the exception
          -                            throw e;
          -                        }
          +                        // Rethrow the exception
          +                        throw new Exception("Caught an exception trying to initialize the component " + role, e);
                               }
                           }
                       }
          

          I can ensure that the resulting exceptions are logged by the caller (aka Cocoon).

          Sébastien Launay (Inactive) added a comment - So i proposed the following patch, for improving logs readability: Index: main/kernel/src/org/ametys/runtime/plugin/component/ThreadSafeComponentManager.java =================================================================== --- main/kernel/src/org/ametys/runtime/plugin/component/ThreadSafeComponentManager.java (revision 323) +++ main/kernel/src/org/ametys/runtime/plugin/component/ThreadSafeComponentManager.java (working copy) @@ -112,9 +112,7 @@ if (role == null) { - String message = "ThreadSafeComponentManager attempted to retrieve component with null role."; - getLogger().error(message); - throw new ComponentException(role, message); + throw new ComponentException(role, "ThreadSafeComponentManager attempted to retrieve component with null role."); } T component = _components.get(role); @@ -127,9 +125,7 @@ } catch (Exception e) { - String errorMessage = "Unable to initialize component " + role; - getLogger().error(errorMessage, e); - throw new ComponentException(role, errorMessage, e); + throw new ComponentException(role, "Unable to initialize component " + role, e); } _components.put(role, component); @@ -175,9 +171,7 @@ { if (_initialized) { - String errorMessage = "ComponentManager has already been initialized"; - getLogger().error(errorMessage); - throw new IllegalStateException(errorMessage); + throw new IllegalStateException("ComponentManager has already been initialized"); } synchronized (this) @@ -196,13 +190,8 @@ } catch (Exception e) { - if (getLogger().isErrorEnabled()) - { - getLogger().error("Caught an exception trying to initialize the component " + role, e); - - // Rethrow the exception - throw e; - } + // Rethrow the exception + throw new Exception("Caught an exception trying to initialize the component " + role, e); } } } I can ensure that the resulting exceptions are logged by the caller (aka Cocoon).

            yabon Sébastien Launay (Inactive)
            yabon Sébastien Launay (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: