cancel
Showing results for 
Search instead for 
Did you mean: 

JavaScript API debugging

jonathanscorner
Champ in-the-making
Champ in-the-making
I tried to make a script to make a set of directories and set permissions on them. I followed the API steps, or tried to, but nothing seemed to happen. Then I realized that I knew how to write some JavaScript, but not how to intelligently debug it–I know a couple of client-side tricks, but I can't make a client-side popup to display information.

How do people intelligently debug JavaScript that uses the API? Is it through the debugger briefly mentioned, or something else?

Thanks,
10 REPLIES 10

davidc
Star Contributor
Star Contributor
The debugger is probably easiest - see http://wiki.alfresco.com/wiki/JavaScript_API#Alfresco_Javascript_Debugger

You can also add log statements to your js - see http://wiki.alfresco.com/wiki/JavaScript_API#Logging_API

jonathanscorner
Champ in-the-making
Champ in-the-making
The debugger is probably easiest - see http://wiki.alfresco.com/wiki/JavaScript_API#Alfresco_Javascript_Debugger

You can also add log statements to your js - see http://wiki.alfresco.com/wiki/JavaScript_API#Logging_API

I was able to turn on the debugger, and when I repeated the interaction, I got:

Please correct the errors below then click OK.
* A system error happened during the operation: Unknown Exception in Transaction.

I think I may be able to get somewhere with the logging API, but is the debugger supposed to give a catchall exception? I was expecting something more descriptive…

jonathanscorner
Champ in-the-making
Champ in-the-making
P.S.

I added logging statements; the first statement is a log call. But the alfresco.log has none of the log messages. The closest I found to a diagnostic was:

13:58:22,033 ERROR [org.alfresco.web.ui.common.Utils] A system error happened during the operation: Unknown Exception in Transaction.
org.alfresco.error.AlfrescoRuntimeException: Unknown Exception in Transaction.
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:292)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:155)
        at org.alfresco.web.bean.dialog.BaseDialogBean.finish(BaseDialogBean.java:124)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
        at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
        at javax.faces.component.UICommand.broadcast(UICommand.java:109)
        at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
        at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
        at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
        at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
        at java.lang.Thread.run(Thread.java:595)
        at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:430)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:239)
        … 32 more
        at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:171)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
        at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:238)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
        at $Proxy48.executeScript(Unknown Source)
        at org.alfresco.repo.action.executer.ScriptActionExecuter.executeImpl(ScriptActionExecuter.java:157)
        at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:120)
        at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:537)
        at org.alfresco.repo.action.executer.CompositeActionExecuter.executeImpl(CompositeActionExecuter.java:72)
        at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:120)
        at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:537)
        at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:472)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:399)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
        at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
        at $Proxy19.executeAction(Unknown Source)
        at org.alfresco.repo.rule.RuleServiceImpl.executeRule(RuleServiceImpl.java:918)
        at org.alfresco.repo.rule.RuleServiceImpl.executePendingRule(RuleServiceImpl.java:886)
        at org.alfresco.repo.rule.RuleServiceImpl.executePendingRulesImpl(RuleServiceImpl.java:857)
        at org.alfresco.repo.rule.RuleServiceImpl.executePendingRules(RuleServiceImpl.java:830)
        at org.alfresco.repo.rule.RuleTransactionListener.beforeCommit(RuleTransactionListener.java:69)
        at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.beforeCommit(AlfrescoTransactionSupport.java:626)
        at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:48)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:821)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:637)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:624)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:307)
        at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:420)
        … 33 more
Caused by: org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/39978960-9deb-11dc-9af1-b535eafe6daa': missing ) after formal parameters (AlfrescoScript#18)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:146)
        at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:167)
        … 90 more
Caused by: org.alfresco.error.AlfrescoRuntimeException: missing ) after formal parameters (AlfrescoScript#18)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:518)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:142)
        … 91 more
Caused by: org.mozilla.javascript.EvaluatorException: missing ) after formal parameters (AlfrescoScript#18)
        at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:95)
        at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:82)
        at org.mozilla.javascript.Parser.addError(Parser.java:123)
        at org.mozilla.javascript.Parser.reportError(Parser.java:129)
        at org.mozilla.javascript.Parser.mustMatchToken(Parser.java:215)
        at org.mozilla.javascript.Parser.function(Parser.java:514)
        at org.mozilla.javascript.Parser.parse(Parser.java:345)
        at org.mozilla.javascript.Parser.parse(Parser.java:290)
        at org.mozilla.javascript.Context.compileImpl(Context.java:2250)
        at org.mozilla.javascript.Context.compileString(Context.java:1296)
        at org.mozilla.javascript.Context.compileString(Context.java:1285)
        at org.mozilla.javascript.Context.evaluateString(Context.java:1141)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:510)
        … 92 more

It seems to be complaining about a missing right parenthesis, but I can't find that with my editor; line 18, the one line number mentioned, has one open parenthesis followed by one closed parenthesis.

jonathanscorner
Champ in-the-making
Champ in-the-making
After trying this, I was asked to log in again, and I can no longer log in as admin/admin, or as an un-privileged user.

Suggested fixes?

jonathanscorner
Champ in-the-making
Champ in-the-making
(After a restartSmiley Happy

I get a Tomcat 404 when viewing /alfresco/ .

mikeh
Star Contributor
Star Contributor
When you say "restart" do you mean reboot, or restart Tomcat/Alfresco?

In either case, the alfresco.log file should indicate if there's a problem.

Thanks,
Mike

jonathanscorner
Champ in-the-making
Champ in-the-making
When you say "restart" do you mean reboot, or restart Tomcat/Alfresco?

Restarting Alfresco. The immediate (i.e. unserviceable) problem stopped manifesting after rebooting the computer.

jonathanscorner
Champ in-the-making
Champ in-the-making

mikeh
Star Contributor
Star Contributor
That's actually the debugger's way of outputting the array of Nodes which you've got hold of. You've got 4 ScriptNodes in an array there - company_children.length should return 4. Further, company_children[0].name will give you the name of the first Node returned - possibly the Data Dictionary space.

See http://wiki.alfresco.com/wiki/JavaScript_API#ScriptNode_API for how to access and manipulate Nodes.

There are some examples of this towards the bottom of the wiki page.

Thanks,
Mike