-1

I understand from Chrome Development Tool: [VM] file from javascript that the code executed inside a [VM] file in Google Chrome is code that is not directly tied to a file.

A client recently reported that a geocoding feature is no longer working on their website. It's a Joomla site, so it uses MooTools. The geocoding is done through the Google Maps API v3. I wrote the code years ago, and it just recently started acting up. I've determined exactly where the bug is occurring in my code, but the end of the stack-trace ends up in one of the [VM] files that is obfuscated.

Where the error crops up in my code:

var pf_map = {
    geocoder: new google.maps.Geocoder(),

    geocode: function() {
        var address = '123 Fake St, Nowhere, USA'; // actually a valid address

        // The error occurs somewhere between here
        console.log('This message makes it to the console');
        pf_map.geocoder.geocode({ 'address': address }, function(results, status) {
            // and here
            console.log('This message does not make it to the console');
        });
    }
}

The error that is reported in the console is:

Uncaught TypeError: Cannot read property 'charAt' of undefined

The stack trace looks like this:

console stack trace

It looks to me like MooTools is causing the problem, but I have no clue how to debug this. Clicking on the top of the stack I get something like this:

easy-to-read JavaScript

Very pleasant. I've stepped through the script and this is what the scope looks like when the error is thrown:

scope during the error

Well, I can see that b is indeed undefined, but I already knew that.

I'm pretty sure that the Google geocoder is working just fine. In my frustration I repeatedly clicked on the "Map my Address" button enough to cause a separate Geocode was not successful for the following reason: OVER_QUERY_LIMIT error, on which I'm basing my that particular assumption.

What would you try next in this situation?

Community
  • 1
  • 1
Ben Harold
  • 6,242
  • 6
  • 47
  • 71
  • I would try to find where your undefined variables are supposed to be defined and determining why they're not defined and then defining them. That's obviously the problem as you, and the stack trace, pointed out. – Richard Barker Jul 10 '15 at 23:44
  • 1
    The [code as posted (jsfiddle)](http://jsfiddle.net/geocodezip/c4bpqfas/) works for me. It is something outside of that code. Please post a [Minimal, Complete, Tested and Readable example](http://stackoverflow.com/help/mcve) that demonstrates the issue. If you really think it might be an error in the status returned by the geocoder (like OVER_QUERY_LIMIT), you should check that. – geocodezip Jul 10 '15 at 23:57

1 Answers1

0

I would look at the delta of changes, both in code and environment, from the last point when the code was working as expected.

Did any of the included libraries change revisions? Are they still being downloaded from the same sources? Is there newly added JS code that might be impacting the existing scripts?

If that doesn't work, I would create a dummy page with just the basic elements that are suspect, and see if the error gets reproduced. Running this dummy code as a node app via node-debug and stepping through the code using Chrome dev tools might be helpful as well.

Good luck and let us know how you resolve this (and I'm sure you will!)

Cahit
  • 2,484
  • 19
  • 23
  • Unfortunately this is a Joomla site on an FTP server. It doesn't even have version control. That's going to change (at least for me personally). I was unable to reproduce the problem in a Plunkr, so on a hunch I started messing with the script load order. Sure enough, moved Google Maps to the end of the list and MooTools to the top, and everything started working again. I have no idea how that could have changed, but it did. – Ben Harold Jul 14 '15 at 01:28