Opened 4 years ago

Closed 4 years ago

#3320 closed task (fixed)

remove Lang.js and Console.js @requires directives

Reported by: erilem Owned by:
Priority: major Milestone: 2.12 Release
Component: general Version: SVN
Keywords: Cc:
State: Complete

Description

We have a number of files that @require Lang.js and Console.js just to output (translated) error messages when the application developer doesn't correctly use the API.

For example LonLat.js includes Lang.js and Console.js to display an error message when null values are passed to the add method:

    add:function(lon, lat) {
        if ( (lon == null) || (lat == null) ) {
            var msg = OpenLayers.i18n("lonlatAddError");
            OpenLayers.Console.error(msg);
            return null;
        }
        ...
    },

Instead of requiring Lang.js and Console.js I think we'd be better of throwing an exception:

    add:function(lon, lat) {
        if ( (lon == null) || (lat == null) ) {
            throw new Error('LonLat.add cannot receive null values');
        }
        ...
    },

I personally find it silly to translate error messages targeted to the developer.

By throwing exceptions with untranslated messages we can create builds without Console.js, and without Lang.js if no visual control is needed in the application.

Attachments (6)

3320.0.patch (34.0 KB) - added by fredj 4 years ago.
replace translated console message to exceptions (LonLat.add, Pixel.add and Bounds.add)
3320.1.patch (42.4 KB) - added by fredj 4 years ago.
replace translated console message to exceptions in Layer.PointTrack and Filter.Spatial
3320.2.patch (46.4 KB) - added by fredj 4 years ago.
Tween.js, Format/GML.js, Format/KML.js, Comparison.js. not finished yet
3320.3.patch (47.7 KB) - added by fredj 4 years ago.
replace Error with TypeError (https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/TypeError)
3320.3.2.patch (98.9 KB) - added by fredj 4 years ago.
sync with trunk
3320.4.patch (101.0 KB) - added by fredj 4 years ago.
sync with trunk

Download all attachments as: .zip

Change History (11)

Changed 4 years ago by fredj

replace translated console message to exceptions (LonLat.add, Pixel.add and Bounds.add)

Changed 4 years ago by fredj

replace translated console message to exceptions in Layer.PointTrack and Filter.Spatial

Changed 4 years ago by fredj

Tween.js, Format/GML.js, Format/KML.js, Comparison.js. not finished yet

Changed 4 years ago by fredj

sync with trunk

comment:1 follow-up: Changed 4 years ago by fredj

erilem (and others): what's you're opinion about the 'deprecated' warning messages? should we not simply remove the OpenLayers.Console.warn and document the deprecation in a comment and in the release notes?

I fully agree with eric's comment in http://trac.osgeo.org/openlayers/ticket/3443#comment:7 to stop bloating the code with these messages

comment:2 in reply to: ↑ 1 Changed 4 years ago by erilem

Replying to fredj:

erilem (and others): what's you're opinion about the 'deprecated' warning messages? should we not simply remove the OpenLayers.Console.warn and document the deprecation in a comment and in the release notes?

I'm in favor of that yes. I also hope that we can eventually rely on the Google Closure compiler, or similar, and display deprecation messages at compilation time. Being able to create debug builds, with runtime-level debug messages, could also make sense.

Changed 4 years ago by fredj

sync with trunk

comment:3 Changed 4 years ago by fredj

  • State changed from Needs Discussion to Review

attachment:3320.4.patch ready to review, thanks.

comment:4 Changed 4 years ago by erilem

I fully support this patch, but I'd like to have others' opinions about it before it gets committed.

comment:5 Changed 4 years ago by fredj

  • Resolution set to fixed
  • State changed from Review to Complete
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.