Titanium Code Processor: Error: Could not run the "titanium" command...

355 views
Skip to first unread message

Hannes Becker

unread,
Nov 27, 2012, 10:01:18 AM11/27/12
to appc-...@googlegroups.com
Hi,
I'm trying to get the code-processor to work, but the following happens:
MyMac:MyProjectDirectory username$ titanium-code-processor -o iphone
info: Analyzing project
error: Could not run the "titanium" command: Error: Command failed: [ERROR] Project directory does not exist

Make sure that the Titanium CLI is installed and a 3.0 or newer SDK is installed.

I have installed the latest Ti-SDK and changed my project to that. I also installed the latest Titanium CLI and it seems to work.

Bryan Hughes

unread,
Nov 27, 2012, 1:23:53 PM11/27/12
to appc-...@googlegroups.com
Can you try running 'titanium project <path-to-project>'? If there are no bugs in the code processor, we should see the same error.

Hannes Becker

unread,
Nov 28, 2012, 4:36:40 AM11/28/12
to appc-...@googlegroups.com
If i try this command I get:
Titanium Command-Line Interface, CLI version 3.0.18, Titanium SDK version 3.1.0.v20121126154201
Copyright (c) 2012, Appcelerator, Inc.  All Rights Reserved.

Please report bugs to http://jira.appcelerator.org/

[ERROR] Invalid project directory "."

Use the --project-dir property to specify the project's directory

If I try
titanium project --project-dir [project-name]
than, it works fine...

Bryan Hughes

unread,
Nov 28, 2012, 2:19:54 PM11/28/12
to appc-...@googlegroups.com
I posted an update to the code processor. Look for a line that says "info: Analyzing project at ..." and make sure the path looks correct. The code processor does some path resolving under the hood and I wonder if it isn't resolving correctly. Then take that path and  into titanium project --project-dir [project-name] and see if that fails.

Hannes Becker

unread,
Nov 28, 2012, 3:10:28 PM11/28/12
to appc-...@googlegroups.com
I updated the code processor and tried exactly what you told me and got this:
MyMac:ProjectDir macuser$ titanium-code-processor -o iphone "/Users/macuser/Documents/Titanium Studio Workspace/TestProject"
info: Analyzing project at "/Users/macuser/Documents/Titanium Studio Workspace/TestProject"
error: Could not run the "titanium" command: Error: Command failed: [ERROR] Project directory does not exist
Make sure that the Titanium CLI is installed and a 3.0 or newer SDK is installed.

Bryan Hughes

unread,
Nov 28, 2012, 6:02:17 PM11/28/12
to appc-...@googlegroups.com
It's fixed now. Turns out there was a bug dealing with paths with spaces. If you update the code processor it should work now.

Hannes Becker

unread,
Nov 28, 2012, 6:26:09 PM11/28/12
to appc-...@googlegroups.com
Thank you. it works fine now! Seems to be a pretty useful tool!
I've got another issue now with the error analysis but I am not sure if it's just me misthinking:
I have an event-listener with an anonymous callback-function e.g.:
tableView.addEventListener('click', function(e) {
if (condition) {
return; // line in code which throws exception
}
doSomeOtherStuff();
});

The code-processor gives me following error (and prevents me from finding more bugs in my code because it seems to only show one error...):
An exception was thrown but not caught: Return must be called from within a function

I understand that returning a value could lead to unpredictable behaviour here, but a void-return should do no harm, right?

Bryan Hughes

unread,
Nov 28, 2012, 6:49:57 PM11/28/12
to appc-...@googlegroups.com
That's a flat out bug in the code processor, your code is fine. For whatever reason, it thinks that the return statement is in global scope, not function scope. If you had a file that contained nothing but a return statement, it would (legitimately) throw this exception. This bug is a little more complex, so I won't be able to get to it right away, but I did file a bug to track it at https://jira.appcelerator.org/browse/TIMOB-11889

In the mean time, if you turn on error recovery exception by passing '-c nativeExceptionRecovery=true', you should be able to get around it for now.

Hannes Becker

unread,
Nov 28, 2012, 7:03:09 PM11/28/12
to appc-...@googlegroups.com
Thanks again for your quick response. I did further testing and commented out this return. The problem now is, that no more errors could be found in the whole project - which I highly doubt. It is a large project and the processor found only issues in the first window which is opened in the app.
The app "continues" from this window only by clicking on a button, which means the open-method for the next window is in an anonymous callback function. Can this be the cause of trouble again or is this something else then?

Bryan Hughes

unread,
Nov 28, 2012, 7:46:16 PM11/28/12
to appc-...@googlegroups.com
This is the big thing we want to fix: making sure the code processor processes everything it's supposed to, and doesn't process anything it's not supposed to. The nature of the code processor (it's a JavaScript runtime) is that it analysis what it's supposed to, so for example if you have a tone of iOS specific code but run the code processor for android, none of that code will be processed by design. If you look at the output, check the analysis-coverage plugin results. This will tell you which files were processed and how much of them were processed. Also check the results of the require-finder and ti-include-finder plugins and see if there are any missing or unresolved requires/includes. Hopefully this will narrow down what is failing. Also, if you feel brave, you can enable trace level logging and see each and every construct of your code being evaluated.

If nothing becomes obvious or fixable, can you try and create a minimum viable example that reproduces the bug and post it here?

Hannes Becker

unread,
Nov 28, 2012, 8:00:35 PM11/28/12
to appc-...@googlegroups.com
A main issue seems to be that no functions in anonymous event listeners are being processed. another issue I encountered is, that variables in the global scope can't be processed.
Example:
var currentAppWindow;
(function() {
   require('/Bootstrap').start();
}());
leads to
Cannot dereference app of undefined
when I use that variable somewhere deeper in the app.

Bryan Hughes

unread,
Nov 28, 2012, 8:12:24 PM11/28/12
to appc-...@googlegroups.com
Functions passed as arguments to any titanium API are processed in a special mode (they are queued up for evaluation after the "main thread" has been run). If the function isn't being processed, then that means that the addEventListener call itself isn't being processed for some reason.

Regarding the global scope thing: the code processor follows node.js style scoping/CommonJS implementation (which is what Titanium also follows, in theory at least). This means that code is run in "module" scope, not global scope. If file A requires file B, then file A cannot access the global variables of file B and vice versa, by design. This also means that, for example, this.NaN is undefined, even though NaN is part of the global scope (this works in browsers BTW since they don't have global scope). Is this the case in your app, or is something else going on?

Bryan Hughes

unread,
Nov 28, 2012, 8:14:19 PM11/28/12
to appc-...@googlegroups.com
I wish there was an edit button :) The last aside should read "this works in browsers BTW since they don't have module scope"

Bryan Hughes

unread,
Nov 29, 2012, 1:10:51 PM11/29/12
to appc-...@googlegroups.com
I was thinking about your issue some more, and there is another possibility I hadn't considered before: your function is getting converted to unknown for whatever reason. I created a ticket in JIRA to implement a plugin to detect these instances: https://jira.appcelerator.org/browse/TIMOB-11892

Bryan Hughes

unread,
Nov 30, 2012, 9:02:59 PM11/30/12
to appc-...@googlegroups.com
I just release version 0.1.9 of the code processor that includes a fix for this bug
Reply all
Reply to author
Forward
0 new messages