Tuesday, March 04, 2014

"TypeError: Object has no method 'match'" using angularJs

I was getting the following error:

TypeError: Object 4 has no method 'match'

In some angular code I have written.
took some time to debug but it turns out the isolated scope of one of my directives had a property that was not a string. somewhere inside angular it seems that it is expected that the properties of the isolated scope would all be strings and thus have a .match method....

so
   .directive('myDirective',
      function() {
return {
restrict: "E",
replace: false,
scope: {
        x:4,
},


resulted in the said error.

just so that you will know...

Thursday, January 02, 2014

Why was I getting a "java.lang.IllegalArgumentException: Type mismatch" when trying a projection query on GAE

I was about to ask the following Q on StackOverflow.com but ended up finding the answer myself before even posting so I decided to make this into a new blog post.

I have two code snippets which I am trying to run on the development server of Google App Engine SDK v1.8.8 for Java.

The first:

    return datastore.get(KeyFactory.createKey(Kinds.Provider,provider_id));
    
works as expected and returns the Provider Entity from the Data Store.

But when I tried to change it to a projection Query so that it will return only some of the fields like this: 

    Filter filter=new FilterPredicate(Entity.KEY_RESERVED_PROPERTY,
                                      Query.FilterOperator.EQUAL,
                                      KeyFactory.createKey(Kinds.Provider,provider_id));
    Query q = new Query(Kinds.Provider)
                .setFilter(filter)
.addProjection(new PropertyProjection("address", String.class))
       .addProjection(new PropertyProjection("last_modified", String.class));;
}
    PreparedQuery pq = datastore.prepare(q);
    log.info("query:" + q.toString());
    
    Entity result = pq.asSingleEntity();

I am getting a the following Exception:


    java.lang.IllegalArgumentException: Type mismatch.
    at com.google.appengine.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:96)
    at com.google.appengine.api.datastore.RawValue.asType(RawValue.java:61)
    at com.google.appengine.api.datastore.PropertyProjection.getValue(PropertyProjection.java:65)
    at com.google.appengine.api.datastore.EntityTranslator.createFromPb(EntityTranslator.java:29)
    at com.google.appengine.api.datastore.QueryResultsSourceImpl.processQueryResult(QueryResultsSourceImpl.java:199)
    at com.google.appengine.api.datastore.QueryResultsSourceImpl.loadMoreEntities(QueryResultsSourceImpl.java:106)
    at com.google.appengine.api.datastore.QueryResultIteratorImpl.ensureLoaded(QueryResultIteratorImpl.java:155)
    at com.google.appengine.api.datastore.QueryResultIteratorImpl.nextList(QueryResultIteratorImpl.java:110)
    at com.google.appengine.api.datastore.LazyList.forceResolveToIndex(LazyList.java:93)
    at com.google.appengine.api.datastore.LazyList.resolveToIndex(LazyList.java:73)
    at com.google.appengine.api.datastore.LazyList.resolveToIndex(LazyList.java:56)
    at com.google.appengine.api.datastore.LazyList.isEmpty(LazyList.java:260)
    at com.google.appengine.api.datastore.PreparedQueryImpl.asSingleEntity(PreparedQueryImpl.java:74)

as I was copying This exception For my StackOverflow.com Q I discovered that there was another exception before that

12:09:18 PM com.google.appengine.api.datastore.dev.LocalCompositeIndexManager updateIndexFile
SEVERE: Unable to write some_path\war\WEB-INF\datastore-indexes.xml
java.io.FileNotFoundException: some_path\war\WEB-INF\appengine-generated\datastore-indexes-auto.xml (Access is denied)

Now it makes more sense...
Projection Queries require indexes to be created as explained here If the datastore-indexes-auto.xml is read only... well you now know what happens then...

well...
I thought this was the end of it but no... After making the file writeable, GAE indeed added an index to it but I still get the original 
IllegalArgumentException 

logging the querys .toString() yeilded:

SELECT last_modified, address FROM Provider WHERE __key__ = Provider(99)


Finally It turned out the error was absolutely justified...
In:

.addProjection(new PropertyProjection("last_modified", String.class));;

Last Modified was a Long and not a String...

Sunday, July 28, 2013

Suggested improvement for nodejs LOAD_AS_DIRECTORY module loading algorithm

In  the process for module loading is described.

on LOAD_AS_DIRECTORY(X) it says


1. If X/package.json is a file,
   a. Parse X/package.json, and look for "main" field.
   b. let M = X + (json main field)
   c. LOAD_AS_FILE(M)
2. If X/index.js is a file, load X/index.js as JavaScript text.  STOP
3. If X/index.node is a file, load X/index.node as binary addon.  STOP
It is nice to be able to require a folder name and have it automatically try to load index.js,
however when editing multiple modules having multiple index.js files open might become confusing or at least uncomfortable.

I wanted to suggest to add 


4. If X/LAST_PATH_FRAGMENT(X).js is a file, load X/LAST_PATH_FRAGMENT(X).jsas JavaScript text.  STOP5. If X/LAST_PATH_FRAGMENT(X).node is a file, load X/LAST_PATH_FRAGMENT(X).node as binary addon.  STOP

this way I can name the main js with the same name as the folder and stile just use require('mymodule') and it will load mymodule/mymodule.js.


Monday, April 29, 2013

Finding breaking changes in Adobe Cordova for PGB users

I have encountered a problem with Phonegap Build where some of my code stopped running.
Turns out there was a breaking change:


Before Cordova 2.2.0, the Connection object existed at: navigator.network.connection.
To match the spec, this was changed to navigator.connection in 2.2.0.
navigator.network.connection was left in place but was deprecated and was removed in 2.3.0.

I was not able to find any single place to read about such breaking changes.
see my Q to the people at phonegap build here:
http://community.phonegap.com/nitobi/topics/phonegap_version_upgrade_checkup_list_for_pgb_users

Eventually I ended up with the following Google search:


site:docs.phonegap.com ("API Changes" || "API change")

I hope this will help some one else.
If you know of a better way to keep track of breaking API changes - please leave a comment.

Monday, February 25, 2013

echoing bash and mysql commands when running in "batch mode"

I was working on doing some migrations on a Linux machine.

Those migrations required me to execute some Unix commands (using a bash script file) and running some SQL statements to make some changes to my MySql DB.

The entire set of commands was to be called from the console after executing a script -t 2>~/mylog.time -a ~/mylog.script command so that the execution output would be saved to a file.

The problem was that the log file did not show the actual commands that where executing, only their output and on the MySql script not even the output was displayed.

So I was looking fro something like the old dos "Echo On" command.

After doing some reading I found the following:
As the first command within my bash script (after the #!/bin/bash) I added the command set -vx.

  •  -v Prints shell input lines as they are read. 
  •  -x Print command traces before executing command. (so that variables names are replaced with their values). 
To disable this echoing set +vx at the end of the bash script.

As previously stated, in my shell script I also wanted to execute some SQL statements on my DB.

So I created a do_sql.sh file that had the following single line:
mysql -u rewardy --password=mypass --database=mydb --default-character-set=utf8.

Redirecting of stdin to this file like ./do_sql.sh < sql_statements.sql got the statements in sql_statements.sql to execute on the DB but I didn't even see the output of the SQL commands (and obviously not the commands themselves either).

To make this work I modified the file do_sql.sh by adding two parameters at the end of the original line: mysql -u rewardy --password=mypass --database=mydb --default-character-set=utf8 -vvv -t


  • -vvv Causes the echoing I wanted
  • -t      forces printing to use the same formatting as used on interactive console sessions
I hope this helps.

 
Clicky Web Analytics