Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-25218

Improve exception management when throwing a NuxeoException from an automation script

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 10.2-SNAPSHOT
    • Fix Version/s: QualifiedToSchedule
    • Component/s: Automation

      Description

      Use case

      • As a developer building an application based on Web UI, I want to be sure the content of a document creation / edit form is validated server-side so that my content integrity is ensured.

      Example: make sure that my end date property for a Contract document type is ulterior to my start date property (see NXDOC-1578 ).

      WHAT HAPPENS CURRENTLY

      • Whitelist NuxeoException using an XML extension
          <require>org.nuxeo.automation.scripting.classfilter</require>
          <extension target="org.nuxeo.automation.scripting.internals.AutomationScriptingComponent" point="classFilter">
            <classFilter>
              <allow>org.nuxeo.ecm.core.api.NuxeoException</allow>
            </classFilter>
          </extension>
        
      • Create an automation script with the following content:
        function run(input, params) {
          throw new org.nuxeo.ecm.core.api.NuxeoException("FooBar3000");
        }
        
      • Associate it to an event handler on about to create and before doc modification
      • Save, deploy and create a new doc

      =>

      ****** chain ******
      Name: javascript.bla
      Exception: OperationException
      Caught error: Failed to invoke operation javascript.bla
      Caused by: org.nuxeo.ecm.automation.OperationException: Failed to invoke operation javascript.bla
      ****** Hierarchy calls ******
          org.nuxeo.automation.scripting.internals.ScriptingOperationImpl
      
              at org.nuxeo.ecm.automation.core.trace.TracerFactory.onTrace(TracerFactory.java:198)
              at org.nuxeo.ecm.automation.core.trace.Tracer.popContext(Tracer.java:73)
              at org.nuxeo.ecm.automation.core.trace.Tracer.onChainExit(Tracer.java:86)
              at org.nuxeo.ecm.automation.core.impl.OperationChainCompiler$CompiledChainImpl.lambda$invoke$0(OperationChainCompiler.java:227)
              ... 138 more
      Caused by: java.lang.reflect.UndeclaredThrowableException
          at com.sun.proxy.$Proxy168.run(Unknown Source)
          at org.nuxeo.automation.scripting.internals.ScriptingOperationImpl.run(ScriptingOperationImpl.java:66)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.nuxeo.ecm.automation.core.impl.InvokableMethod.doInvoke(InvokableMethod.java:170)
          at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:175)
          ... 140 more
      Caused by: java.lang.reflect.InvocationTargetException
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.nuxeo.automation.scripting.internals.AutomationScriptingServiceImpl$Bridge$1.invoke(AutomationScriptingServiceImpl.java:111)
          ... 148 more
      Caused by: <eval>:2:2 org.nuxeo.ecm.core.api.NuxeoException: FooBar3000
          at jdk.nashorn.internal.runtime.ECMAException.create(ECMAException.java:113)
          at jdk.nashorn.internal.scripts.Script$Recompilation$4$28AA$\^eval\_.run(<eval>:2)
          at org.nuxeo.automation.scripting.internals.ScriptingOperationImpl$Runnable$$NashornJavaAdapter.run(Unknown Source)
          ... 153 more
      Caused by: org.nuxeo.ecm.core.api.NuxeoException: FooBar3000
          ... 155 more
      

      TODO

      Deal with the InvocationTargetException / UndeclaredThrowableException to rethrow properly what comes from JavaScript.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                bchauvin Bertrand Chauvin
                Participants:
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: