Friday, May 25, 2007

Safari: SyntaxError - Parse error

I have now worked my way past this particularly opaque Safari error message twice, which is one time too many, so I am putting the explanation for my error case online. Safari seems to have a few cases where it throws up this utterly useless error message. It does include a line number reference, and double-clicking the error line in the log will take you to the offending line, but heaven help you if it is not clear what is wrong at that point.

I found another reference to this problem on the web, but it wasn't the problem I had.

My problem was that I used "abstract" as a variable name. Because I am working on web pages for viewing presentation abstracts, this seemed natural, however I guess "abstract" is a reserved word of some kind in Safari's Javascript implementation. Firefox showed no errors and happily ran code that Safari could not even parse.

7 comments:

crschmidt said...

In general, Safari is a good thing to have around for this, because IE would have broken but *not* given you an error, so you'd have been left in the dark...

(I don't know if this applies to 'abstract', but it definitely applies to 'long', which sucks for geo developers.)

At least Safari gives you an error message. The fact that Firefox's Javascript engine is so accepting as to choose to not fail on this syntax error is hardly Safari's fault.

Jeremy said...

Thank you so much for posting this. When working with Google Maps, I had to debug a syntax error in a custom marker function (that passed latitude and longitude as "lat" and "long" as parameters. Changed "long" to "lng" and it began working.

An interesting note-- this error does NOT occur in Safari 3 (as of this writing.)

I would suspect that all the browsers have long as a reserved keyword. The behavior might be, in these browsers, to place reserved keywords in a different name space to avoid collisions. Just a hunch, but I would argue that it's safer that bailing like Safari 2 does.

Martin said...

thanks for this! I had same problem - safari didn't like a function called goto. gofigure!

mats said...

Same here. Safari 2 was choking on a variable named 'package'. Safari 3 was fine.

rbrenner said...

I encountered this same difficulty with respect to a missing hyphen in an HTML close comment ("-->") wrapping some JavaScript. Safari threw an error, with this ambiguous message. Much staring was required.

Justin said...

I had this issue too. If you look at the code within safari's develop tool the offending variables will be marked in blue as the browser thinks the are reserve terms.

Neer Friedman said...

same goes for the 'class' keyword, as well as all of the following: class enum extends super const export import (defined in ECMAScript Language Specification, section 7.6.1 Reserved Words)

About Me

My Photo
Victoria, British Columbia, Canada

Followers

Blog Archive

Labels

bc (32) it (26) postgis (17) icm (11) enterprise IT (9) sprint (9) open source (8) osgeo (8) video (8) management (6) cio (5) enterprise (5) foippa (5) gis (5) spatial it (5) foi (4) mapserver (4) outsourcing (4) bcesis (3) foss4g (3) oracle (3) politics (3) COTS (2) architecture (2) boundless (2) esri (2) idm (2) natural resources (2) ogc (2) open data (2) opengeo (2) openstudent (2) postgresql (2) rant (2) technology (2) vendor (2) web (2) 1.4.0 (1) HR (1) access to information (1) accounting (1) agile (1) aspen (1) benchmark (1) buffer (1) build vs buy (1) business (1) business process (1) cathedral (1) cloud (1) code (1) common sense (1) consulting (1) contracting (1) core review (1) crm (1) custom (1) data warehouse (1) deloitte (1) design (1) digital (1) email (1) essentials (1) evil (1) exadata (1) fcuk (1) fgdb (1) fme (1) foocamp (1) foss4g2007 (1) ftp (1) gds (1) geocortex (1) geometry (1) geoserver (1) google (1) google earth (1) government (1) grass (1) hp (1) iaas (1) icio (1) industry (1) innovation (1) integrated case management (1) introversion (1) iso (1) isss (1) isvalid (1) javascript (1) jts (1) lawyers (1) mapping (1) mcfd (1) microsoft (1) mysql (1) new it (1) nosql (1) opengis (1) openlayers (1) oss (1) paas (1) pirates (1) policy (1) portal (1) proprietary software (1) qgis (1) rdbms (1) recursion (1) regression (1) rfc (1) right to information (1) saas (1) salesforce (1) sardonic (1) seibel (1) sermon (1) siebel (1) snark (1) spatial (1) standards (1) svr (1) tempest (1) texas (1) tired (1) transit (1) twitter (1) udig (1) uk (1) uk gds (1) verbal culture (1) victoria (1) waterfall (1) wfs (1) where (1) with recursive (1) wkb (1)