Ticket #3320 (closed task: fixed)

Opened 4 years ago

Last modified 3 years ago

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

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

Change History

Changed 3 years ago by fredj

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

Changed 3 years ago by fredj

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

Changed 3 years ago by fredj

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

Changed 3 years ago by fredj

Changed 3 years ago by fredj

sync with trunk

follow-up: ↓ 2   Changed 3 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

in reply to: ↑ 1   Changed 3 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 3 years ago by fredj

sync with trunk

  Changed 3 years ago by fredj

  • state changed from Needs Discussion to Review

attachment:3320.4.patch Download ready to review, thanks.

  Changed 3 years ago by erilem

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

  Changed 3 years ago by fredj

  • status changed from new to closed
  • state changed from Review to Complete
  • resolution set to fixed
Note: See TracTickets for help on using tickets.