From cf512dd06e79077ae6a018349b1abae8c436fe58 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Fri, 15 Dec 2017 17:21:06 +0800 Subject: [PATCH 1/3] remove error info from the engine release for fireball/issues/6721 --- DebugInfos.js | 92 +++++++++++++++++++ cocos2d/actions/CCAction.js | 4 +- cocos2d/actions/CCActionCatmullRom.js | 2 +- cocos2d/actions/CCActionEase.js | 2 +- cocos2d/actions/CCActionInterval.js | 12 +-- cocos2d/actions/CCActionManager.js | 4 +- cocos2d/animation/playable.js | 2 +- cocos2d/core/CCConfiguration.js | 2 +- cocos2d/core/CCDrawingPrimitivesCanvas.js | 4 +- cocos2d/core/CCDrawingPrimitivesWebGL.js | 2 +- cocos2d/core/CCGame.js | 2 +- cocos2d/core/components/CCRendererInSG.js | 2 +- cocos2d/core/event-manager/CCEventManager.js | 2 +- cocos2d/core/load-pipeline/asset-loader.js | 2 +- .../core/load-pipeline/audio-downloader.js | 4 +- cocos2d/core/load-pipeline/downloader.js | 6 +- cocos2d/core/load-pipeline/uuid-loader.js | 6 +- cocos2d/core/platform/CCSys.js | 2 +- cocos2d/core/platform/_CCClass.js | 2 +- cocos2d/kazmath/gl/matrix.js | 4 +- cocos2d/kazmath/quaternion.js | 2 +- cocos2d/particle/CCPNGReader.js | 4 +- cocos2d/particle/CCParticleSystem.js | 2 +- cocos2d/particle/CCTIFFReader.js | 22 ++--- cocos2d/render-texture/CCRenderTexture.js | 4 +- .../CCRenderTextureCanvasRenderCmd.js | 2 +- .../CCRenderTextureWebGLRenderCmd.js | 4 +- cocos2d/shaders/CCGLProgram.js | 10 +- cocos2d/tilemap/CCSGTMXLayer.js | 20 ++-- cocos2d/tilemap/CCSGTMXTiledMap.js | 4 +- cocos2d/tilemap/CCTiledLayer.js | 2 +- cocos2d/tilemap/editor/tiled-map.js | 2 +- 32 files changed, 164 insertions(+), 72 deletions(-) diff --git a/DebugInfos.js b/DebugInfos.js index f4272d6356..5d3b748a4f 100644 --- a/DebugInfos.js +++ b/DebugInfos.js @@ -24,9 +24,20 @@ if (CC_DEBUG) { "1018": "Grid size must be (1,1)", //ActionGrid3D.initWithSize "1019": "Failed to construct, Sequence construction needs two or more actions", //ActionInterval.sequence "1020": "Failed to construct, Spawn construction needs two or more actions", //ActionInterval.spawn + "1021": "cc.Speed.initWithAction(): action must be non nil", //cc.Speed.initWithAction + "1022": "cc.Follow.initWithAction(): followedNode must be non nil", //cc.Follow.initWithAction + "1023": "cc.ActionEase.initWithAction(): action must be non nil", //cc.ActionEase.initWithAction + "1024": "Invalid configuration. It must at least have one control point", //cc.CardinalSplineTo.initWithDuration + "1025": "cc.Sequence.initWithTwoActions(): arguments must all be non nil", //cc.Sequence.initWithTwoActions + "1026": "cc.RepeatForever.initWithAction(): action must be non null", //cc.RepeatForever.initWithAction + "1027": "cc.Spawn.initWithTwoActions(): arguments must all be non null", //cc.Spawn.initWithAction + "1028": "cc.ReverseTime.initWithAction(): action must be non null", //cc.ReverseTime.initWithAction + "1029": "cc.ReverseTime.initWithAction(): the action was already passed in.", //cc.ReverseTime.initWithAction + "1030": "cc.Animate.initWithAnimation(): animation must be non-NULL", //cc.Animate.initWithAction //configuration: 1100 "1100": "Expected 'data' dict, but not found. Config file: %s", //loadConfigFile "1101": "Please load the resource first : %s", //loadConfigFile_2 + "1102": "Please load the resource first : %s", // loadConfigFile //Director: 1200 "1200": "cocos2d: Director: Error in gettimeofday", //resume "1201": "cocos2d: Director: unrecognized projection", //setProjection @@ -103,6 +114,7 @@ if (CC_DEBUG) { "1633": "Internal error, should not remove unknown node from parent.", //parent "1634": "addChild: The child to add must be instance of cc.Node, not %s.", //addChild "1635": "reorderChild: this child is not in children list", // reorderChild + "1636": "Invalid sgNode. It must be an instance of _ccsg.Node", // RendererInSG //AtlasNode: 1700 "1700": "cc.AtlasNode.updateAtlasValues(): Shall be overridden in subclasses", //_updateAtlasValues "1701": "", //_initWithTileFile @@ -257,6 +269,7 @@ if (CC_DEBUG) { "3508": "If program goes here, there should be event in dispatch.", //_updateListeners "3509": "_inDispatch should be 1 here.", //_updateListeners_2 "3510": "%s's scene graph node not contains in the parent's children", //SceneGraphHelper._getChildrenOffset + "3511": "event is undefined", //Class: 3600 "3600": "cc.Class will automatically call super constructor of %s, you should not call it manually.", //Class.callSuperCtor "3601": "The editor property 'playOnFocus' should be used with 'executeInEditMode' in class '%s'", //playOnFocus @@ -346,6 +359,7 @@ if (CC_DEBUG) { " default: null,\n" + " type: cc.Texture2D // use 'type:' instead of 'url:'\n" + "}", + "3658": "browser does not support getters",//defineGetterSetter //Prefab: 3700 "3700": "internal error: _prefab is undefined", //_doInstantiate "3701": "Failed to load prefab asset for node '%s'", //syncWithPrefab @@ -370,6 +384,7 @@ if (CC_DEBUG) { "3817": "Sorry, the component of '%s' which with an index of %s is corrupted! It has been removed.", "3818": "Failed to read or parse project.json", //_loadConfig "3819": "Warning: target element is not a DIV or CANVAS", //_initRenderer + "3820": "The renderer doesn't support the renderMode %s", //_initRenderer //Animation: 3900 "3900": "Invalid clip to add", //addClip "3901": "Invalid clip to remove", //removeClip @@ -383,6 +398,7 @@ if (CC_DEBUG) { "3909": "[animate] keyFrames must be non-nil", //animate "3910": "[animate] ratio should >= 0!", //_doAnimate "3911": "[animate] ratio should in the order of smallest to largest!", //_doAnimate_2 + "3912": "already-playing", //playable play //Label: 4000 "4000": "Sorry, the cc.Font has been modified from Raw Asset to Asset. Please load the font asset before using.", //font "4001": "_ccsg.Label._initBMFontWithString(): Impossible to create font. Please check file", //_setBMFontFile @@ -437,6 +453,15 @@ if (CC_DEBUG) { "4920": "Sorry, you shouldn\'t use id as item identity any more, please use url or uuid instead, the current id is being set as url: (%s)", // load "4921": "Invalid pipe or invalid index provided!", //pipeline.insertPipe "4922": "The pipe to be inserted is already in the pipeline!", //pipeline.insertPipe + "4923": "Uuid Loader: Parse asset [ %s ] failed : %s", // uuid-loader + "4924": "JSON Loader: Input item doesn\\'t contain string content",// uuid-loader + "4925": "Uuid Loader: Deserialize asset [ %s ] failed : %s",// uuid-loader + "4926": "Audio Downloader: no web audio context.",// audio-downloader + "4927": "Audio Downloader: audio not supported on this browser!",// audio-downloader + "4928": "Load %s failed!",// downloadScript + "4929": "Load Webp ( %s ) failed",// downloadWebp + "4930": "Load image ( %s ) failed",// downloadImage + "4931": "Download Uuid: can not find type of raw asset[ %s ]: %s",//asset-loader //CCObject: 5000 "5000": "object already destroyed", //destroy "5001": "object not yet destroyed", //realDestroyInEditor @@ -445,6 +470,7 @@ if (CC_DEBUG) { //CCSys: 5200 "5200": "Warning: localStorage isn't enabled. Please confirm browser cookie or privacy option", //localStorage "5201": "browser don't support web audio", //audio + "5202": "This feature supports WebGL render mode only.", //_checkWebGLRenderMode //Deserialize: 5300 "5300": "Type of target to deserialize not matched with data: target is %s, data is %s", //_deserializeObject "5301": "Can not find script '%s'", //reportMissingClass @@ -509,6 +535,19 @@ if (CC_DEBUG) { "6014": "Can't change blending functions when the particle is being batched", //_updateBlendFunc "6015": "_ccsg.ParticleSystem.setDisplayFrame(): QuadParticle only supports SpriteFrames with no offsets", //setDisplayFrame "6016": "_ccsg.ParticleSystem._allocMemory(): Memory should not be allocated when not using batchNode", //WebGLRenderCmd._allocMemory + "6017": "Incomplete or corrupt PNG file", //CCPNGReader + "6018": "Invalid filter algorithm: %s",//CCPNGReader + "6019": "Invalid byte order value.", //CCTIFFReader checkLittleEndian + "6020": "You forgot your towel!", //CCTIFFReader hasTowel + "6021": "Unknown Field Tag: %s", //CCTIFFReader hasTowel + "6022": "Too many bits requested", //CCTIFFReader getBits + "6023": "No bits requested", //CCTIFFReader getBits + "6024": "Cannot recover from missing StripByteCounts", //CCTIFFReader parseTIFF + "6025": "Cannot handle sub-byte bits per sample", //CCTIFFReader parseTIFF + "6026": "Cannot handle sub-byte bits per pixel", //CCTIFFReader parseTIFF + "6027": "Palette image missing color map", //CCTIFFReader parseTIFF + "6028": "Unknown Photometric Interpretation: %s", //CCTIFFReader parseTIFF + "6029": "Unkown error", //CCParticleSystem _applyFile //Compatible: 6100 "6100": "Not supported file types, Please try use the ccs.load", //widgetFromJsonFile //CCFactory: 6200 @@ -530,6 +569,9 @@ if (CC_DEBUG) { "6700": "Can't init canvas '%s' because it conflicts with the existing '%s', the scene should only have one active canvas at the same time", //__preload "6701": "Should not add Canvas to a node which already contains a renderer component (%s).", //__preload_2 "6702": "Should not add Canvas to a node which size is already used by its other component.", //__preload_3 + "6703": "Can't initialise DrawingPrimitiveWebGL. context need is WebGLRenderingContext",//DrawingPrimitiveWebGL + "6704": "Polygon's point must greater than 2",//DrawingPrimitiveCanvas drawPoly + "6705": "Argument must be non-nil",//DrawingPrimitiveCanvas drawPoly //EventTarget: 6800 "6800": "Callback of event must be non-nil", //on "6801": "The message must be provided", //emit @@ -571,6 +613,23 @@ if (CC_DEBUG) { "7219": "cc.TMXMapInfo.parseXMLFile(): Only base64 and/or gzip/zlib maps are supported", //_parseLayer "7220": "cc.TMXMapInfo.parseXMLFile(): please load the xml resource first: %s", // parseXMLFile "7221": "cc.TMXMapInfo.parseXMLFile(): Texture '%s' not found.", + "7222": "Parse %s failed.",// tiled-map + "7223": "_ccsg.TMXLayer.setTileGID(): pos should be non-null",//CCTiledLayer setTileGID + "7224": "_ccsg.TMXTiledMap.getLayer(): layerName should be non-null or non-empty string.",//CCSGTMXTiledMap getLayer + "7225": "_ccsg.TMXTiledMap.getObjectGroup(): groupName should be non-null or non-empty string.",//CCSGTMXTiledMap getObjectGroup + "7226": "_ccsg.TMXLayer.getTileAt(): pos should be non-null",//CCSGTMXLayer getTileAt + "7227": "_ccsg.TMXLayer.getTileAt(): invalid position",//CCSGTMXLayer getTileAt + "7228": "_ccsg.TMXLayer.getTileGIDAt(): pos should be non-null",//CCSGTMXLayer getTileGIDAt + "7229": "_ccsg.TMXLayer.getTileGIDAt(): invalid position",//CCSGTMXLayer getTileGIDAt + "7230": "_ccsg.TMXLayer.setTileGID(): pos should be non-null",//CCSGTMXLayer setTileGID + "7231": "_ccsg.TMXLayer.setTileGID(): invalid position",//CCSGTMXLayer setTileGID + "7232": "_ccsg.TMXLayer.getTileFlagsAt(): pos should be non-null",//CCSGTMXLayer getTileFlagsAt + "7233": "_ccsg.TMXLayer.getTileFlagsAt(): invalid position",//CCSGTMXLayer getTileFlagsAt + "7234": "_ccsg.TMXLayer.removeTileAt(): pos should be non-null",//CCSGTMXLayer removeTileAt + "7235": "_ccsg.TMXLayer.removeTileAt(): invalid position",//CCSGTMXLayer removeTileAt + "7236": "_ccsg.TMXLayer.getTileAt(): pos should be non-null",//CCSGTMXLayer getTileAt + "7237": "_ccsg.TMXLayer.getTileAt(): pos should be non-null",//CCSGTMXLayer getTileAt + //Wrapper: 7300 "7300": "The new selected must be number", //CheckBox.selected "7301": "The new bake must be boolean", //layer @@ -592,6 +651,12 @@ if (CC_DEBUG) { "7510": "Spine: Animation not found: %s", //addAnimation //Render: 7600 "7600": "The context of RenderTexture is invalid.", //_renderingToCacheCanvas + "7601": "cc.RenderTexture._initWithWidthAndHeightForWebGL() : only RGB and RGBA formats are valid for a render texture;", //CCRenderTextureWebGLRenderCmd initWithWidthAndHeight + "7602": "Could not attach texture to the framebuffer",//CCRenderTextureWebGLRenderCmd initWithWidthAndHeight + "7603": "clearDepth isn't supported on Cocos2d-Html5",//CCRenderTextureWebGLRenderCmd clearDepth + "7604": "saveToFile isn't supported on Cocos2d-Html5",//CCRenderTexture saveToFile + "7605": "newCCImage isn't supported on Cocos2d-Html5",//CCRenderTexture newCCImage + //VideoPlayer: 7700 "7700": "On the web is always keep the aspect ratio", //setKeepAspectRatioEnabled "7701": "Can't know status", //isFullScreenEnabled @@ -612,6 +677,8 @@ if (CC_DEBUG) { "7905": "cc.math.mat4Assign(): pOut equals pIn", //mat4AssignSIMD "7906": "cc.mat.Matrix4.assignFrom(): mat4 equals current matrix", //assignFromSIMD "7907": "cc.math.Matrix4 equals: pMat1 and pMat2 are same object.", //equalsSIMD + "7908": "Invalid matrix mode specified", //glGetMatrix glMatrixMode + "7909": "current quaternion is an invalid value",// quaternion.js normalize //Reader: 8000 "8000": "Can't handle this field type or size", //TIFF.getFieldValues "8001": "No bytes requested", //TIFF.getBytes @@ -624,6 +691,10 @@ if (CC_DEBUG) { "8103": "cc.GLProgram.link(): Cannot link invalid program", //link "8104": "cocos2d: ERROR: Failed to link program: %s", //link "8105": "cocos2d: cc.shaderCache._loadDefaultShader, error shader type", //_loadDefaultShader + "8106": "Please load the resource firset : %s", //CCGLProgram initWithVertexShaderFilename + "8107": "cc.GLProgram.getUniformLocationForName(): uniform name should be non-null", //CCGLProgram getUniformLocationForName + "8108": "cc.GLProgram.getUniformLocationForName(): Invalid operation. Cannot get uniform location when program is not initialized", //CCGLProgram getUniformLocationForName + "8109": "modelView matrix is undefined.", //CCGLProgram _setUniformForMVPMatrixWithMat4 //Physics: 8200 "8200": "Please set node\'s active instead of rigidbody\'s enabled.", //cc.RigidBody.enabled //Camera: 8300 @@ -633,6 +704,27 @@ if (CC_DEBUG) { "8400": "Wrong type arguments, 'filePath' must be a String.", // cc.audioEngine.play }; cc._LogInfos = logs; + + var errorMapUrl = 'https://github.com/cocos-creator/engine/blob/master/EngineErrorMap.md'; + + cc._LogInfos.format = function (id) { + var type = 'error'; + if (arguments.length === 1) { + return CC_DEBUG ? cc._LogInfos[id] : type + ' ' + id + ', please go to ' + errorMapUrl + '#' + id + ' to see details.' + } + if (CC_DEBUG) { + let argsArr = cc.js.shiftArguments.apply(null, arguments); + return cc._LogInfos[id].concat(argsArr); + } else { + var msg = ''; + if (arguments.length === 2) { + msg = 'Arguments: ' + arguments[1]; + } else if (arguments.length > 2) { + msg = 'Arguments: ' + cc.js.shiftArguments.apply(null, arguments).join(', '); + } + return type + ' ' + id + ', please go to ' + errorMapUrl + '#' + id + ' to see details. ' + msg; + } + }; } // module.exports = false; diff --git a/cocos2d/actions/CCAction.js b/cocos2d/actions/CCAction.js index 5e362ef7fd..9d766d32a2 100644 --- a/cocos2d/actions/CCAction.js +++ b/cocos2d/actions/CCAction.js @@ -300,7 +300,7 @@ cc.Speed = cc.Action.extend({ */ initWithAction:function (action, speed) { if(!action) - throw new Error("cc.Speed.initWithAction(): action must be non nil"); + throw new Error(cc._LogInfos.format(1021)); this._innerAction = action; this._speed = speed; @@ -489,7 +489,7 @@ cc.Follow = cc.Action.extend({ */ initWithTarget:function (followedNode, rect) { if(!followedNode) - throw new Error("cc.Follow.initWithAction(): followedNode must be non nil"); + throw new Error(cc._LogInfos.format(1022)); var _this = this; rect = rect || cc.rect(0, 0, 0, 0); diff --git a/cocos2d/actions/CCActionCatmullRom.js b/cocos2d/actions/CCActionCatmullRom.js index 20e2d2a2b4..a065f8d5ae 100644 --- a/cocos2d/actions/CCActionCatmullRom.js +++ b/cocos2d/actions/CCActionCatmullRom.js @@ -129,7 +129,7 @@ cc.CardinalSplineTo = cc.ActionInterval.extend({ initWithDuration:function (duration, points, tension) { if(!points || points.length === 0) - throw new Error("Invalid configuration. It must at least have one control point"); + throw new Error(cc._LogInfos.format(1024)); if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { this.setPoints(points); diff --git a/cocos2d/actions/CCActionEase.js b/cocos2d/actions/CCActionEase.js index e33b3f6251..cead0e1139 100644 --- a/cocos2d/actions/CCActionEase.js +++ b/cocos2d/actions/CCActionEase.js @@ -51,7 +51,7 @@ cc.ActionEase = cc.ActionInterval.extend({ */ initWithAction:function (action) { if(!action) - throw new Error("cc.ActionEase.initWithAction(): action must be non nil"); + throw new Error(cc._LogInfos.format(1023)); if (this.initWithDuration(action.getDuration())) { this._inner = action; diff --git a/cocos2d/actions/CCActionInterval.js b/cocos2d/actions/CCActionInterval.js index f293913dfa..f724d0bb4b 100644 --- a/cocos2d/actions/CCActionInterval.js +++ b/cocos2d/actions/CCActionInterval.js @@ -341,7 +341,7 @@ cc.Sequence = cc.ActionInterval.extend({ */ initWithTwoActions:function (actionOne, actionTwo) { if(!actionOne || !actionTwo) - throw new Error("cc.Sequence.initWithTwoActions(): arguments must all be non nil"); + throw new Error(cc._LogInfos.format(1025)); var d = actionOne._duration + actionTwo._duration; this.initWithDuration(d); @@ -649,7 +649,7 @@ cc.RepeatForever = cc.ActionInterval.extend({ */ initWithAction:function (action) { if(!action) - throw new Error("cc.RepeatForever.initWithAction(): action must be non null"); + throw new Error(cc._LogInfos.format(1026)); this._innerAction = action; return true; @@ -767,7 +767,7 @@ cc.Spawn = cc.ActionInterval.extend({ */ initWithTwoActions:function (action1, action2) { if(!action1 || !action2) - throw new Error("cc.Spawn.initWithTwoActions(): arguments must all be non null"); + throw new Error(cc._LogInfos.format(1027)); var ret = false; @@ -2473,9 +2473,9 @@ cc.ReverseTime = cc.ActionInterval.extend({ */ initWithAction:function (action) { if(!action) - throw new Error("cc.ReverseTime.initWithAction(): action must be non null"); + throw new Error(cc._LogInfos.format(1028)); if(action === this._other) - throw new Error("cc.ReverseTime.initWithAction(): the action was already passed in."); + throw new Error(cc._LogInfos.format(1029)); if (cc.ActionInterval.prototype.initWithDuration.call(this, action._duration)) { // Don't leak if action is reused @@ -2580,7 +2580,7 @@ cc.Animate = cc.ActionInterval.extend({ */ initWithAnimation:function (animation) { if(!animation) - throw new Error("cc.Animate.initWithAnimation(): animation must be non-NULL"); + throw new Error(cc._LogInfos.format(1030)); var singleDuration = animation.getDuration(); if (this.initWithDuration(singleDuration * animation.getLoops())) { this._nextFrame = 0; diff --git a/cocos2d/actions/CCActionManager.js b/cocos2d/actions/CCActionManager.js index 55185d3fa3..d0e3e14582 100644 --- a/cocos2d/actions/CCActionManager.js +++ b/cocos2d/actions/CCActionManager.js @@ -114,9 +114,9 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ */ addAction:function (action, target, paused) { if(!action) - throw new Error("cc.ActionManager.addAction(): action must be non-null"); + throw new Error(cc._LogInfos.format(1000)); if(!target) - throw new Error("cc.ActionManager.addAction(): action must be non-null"); + throw new Error(cc._LogInfos.format(1000)); //check if the action target already exists var element = this._hashTargets[target.__instanceId]; diff --git a/cocos2d/animation/playable.js b/cocos2d/animation/playable.js index 648e8680a3..5ae9660ecf 100644 --- a/cocos2d/animation/playable.js +++ b/cocos2d/animation/playable.js @@ -80,7 +80,7 @@ prototype.play = function () { this.onResume(); } else { - this.onError('already-playing'); + this.onError(cc._LogInfos.format(3912)); } } else { diff --git a/cocos2d/core/CCConfiguration.js b/cocos2d/core/CCConfiguration.js index e87b9acdfb..d4334e0b91 100644 --- a/cocos2d/core/CCConfiguration.js +++ b/cocos2d/core/CCConfiguration.js @@ -267,7 +267,7 @@ cc.configuration = /** @lends cc.configuration# */{ if(!this._inited) this._init(); var dict = cc.loader.getRes(url); - if(!dict) throw new Error("Please load the resource first : " + url); + if(!dict) throw new Error(cc._LogInfos.format(1102, url)); cc.assertID(dict, 1101, url); var getDatas = dict["data"]; diff --git a/cocos2d/core/CCDrawingPrimitivesCanvas.js b/cocos2d/core/CCDrawingPrimitivesCanvas.js index a8470d38b4..d7c16e1001 100644 --- a/cocos2d/core/CCDrawingPrimitivesCanvas.js +++ b/cocos2d/core/CCDrawingPrimitivesCanvas.js @@ -143,7 +143,7 @@ var DrawingPrimitiveCanvas = cc._Class.extend({ return; if (vertices.length < 3) - throw new Error("Polygon's point must greater than 2"); + throw new Error(cc._LogInfos.format(6704)); var firstPoint = vertices[0], locContext = this._renderContext.getContext(); var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY(); @@ -319,7 +319,7 @@ var DrawingPrimitiveCanvas = cc._Class.extend({ destSize.width, destSize.height); break; default: - throw new Error("Argument must be non-nil"); + throw new Error(cc._LogInfos.format(6705)); break; } }, diff --git a/cocos2d/core/CCDrawingPrimitivesWebGL.js b/cocos2d/core/CCDrawingPrimitivesWebGL.js index 1c1c914c4d..3112d22af9 100644 --- a/cocos2d/core/CCDrawingPrimitivesWebGL.js +++ b/cocos2d/core/CCDrawingPrimitivesWebGL.js @@ -44,7 +44,7 @@ var DrawingPrimitiveWebGL = cc._Class.extend({ */ ctor:function (ctx) { if (cc.sys.platform !== cc.sys.WECHAT_GAME && !ctx instanceof WebGLRenderingContext) - throw new Error("Can't initialise DrawingPrimitiveWebGL. context need is WebGLRenderingContext"); + throw new Error(cc._LogInfos.format(6703)); this._renderContext = ctx; this._colorArray = new Float32Array([1.0, 1.0, 1.0, 1.0]); diff --git a/cocos2d/core/CCGame.js b/cocos2d/core/CCGame.js index 0d03ec477d..8ed336ec85 100644 --- a/cocos2d/core/CCGame.js +++ b/cocos2d/core/CCGame.js @@ -650,7 +650,7 @@ var game = { if (this._rendererInitialized) return; if (!cc._supportRender) { - throw new Error("The renderer doesn't support the renderMode " + this.config[this.CONFIG_KEY.renderMode]); + throw new Error(cc._LogInfos.format(3820, this.config[this.CONFIG_KEY.renderMode])); } var el = this.config[game.CONFIG_KEY.id], diff --git a/cocos2d/core/components/CCRendererInSG.js b/cocos2d/core/components/CCRendererInSG.js index 7adaed58e1..620679cfca 100644 --- a/cocos2d/core/components/CCRendererInSG.js +++ b/cocos2d/core/components/CCRendererInSG.js @@ -96,7 +96,7 @@ var RendererInSG = cc.Class({ _replaceSgNode: function (sgNode) { if (CC_EDITOR && !(sgNode instanceof _ccsg.Node)) { - throw new Error("Invalid sgNode. It must be an instance of _ccsg.Node"); + throw new Error(cc._LogInfos.format(1636)); } var node = this.node; diff --git a/cocos2d/core/event-manager/CCEventManager.js b/cocos2d/core/event-manager/CCEventManager.js index ee65db2fff..f03992bdd8 100644 --- a/cocos2d/core/event-manager/CCEventManager.js +++ b/cocos2d/core/event-manager/CCEventManager.js @@ -1053,7 +1053,7 @@ var eventManager = { this._updateDirtyFlagForSceneGraph(); this._inDispatch++; if(!event || !event.getType) - throw new Error("event is undefined"); + throw new Error(cc._LogInfos.format(3511)); if (event.getType().startsWith(cc.Event.TOUCH)) { this._dispatchTouchEvent(event); this._inDispatch--; diff --git a/cocos2d/core/load-pipeline/asset-loader.js b/cocos2d/core/load-pipeline/asset-loader.js index 266ec35d1b..af28842956 100644 --- a/cocos2d/core/load-pipeline/asset-loader.js +++ b/cocos2d/core/load-pipeline/asset-loader.js @@ -54,7 +54,7 @@ AssetLoader.prototype.handle = function (item, callback) { if (isRawAsset) { var ext = Path.extname(url).toLowerCase(); if (!ext) { - callback(new Error('Download Uuid: can not find type of raw asset[' + uuid + ']: ' + url)); + callback(new Error(cc._LogInfos.format(4931, uuid, url))); return; } ext = ext.substr(1); diff --git a/cocos2d/core/load-pipeline/audio-downloader.js b/cocos2d/core/load-pipeline/audio-downloader.js index 48ccf7abce..dc36f49c7c 100644 --- a/cocos2d/core/load-pipeline/audio-downloader.js +++ b/cocos2d/core/load-pipeline/audio-downloader.js @@ -73,7 +73,7 @@ function loadDomAudio (item, callback) { } function loadWebAudio (item, callback) { - if (!context) callback(new Error('Audio Downloader: no web audio context.')); + if (!context) callback(new Error(cc._LogInfos.format(4926))); var request = cc.loader.getXMLHttpRequest(); request.open("GET", item.url, true); @@ -100,7 +100,7 @@ function loadWebAudio (item, callback) { function downloadAudio (item, callback) { if (formatSupport.length === 0) { - return new Error('Audio Downloader: audio not supported on this browser!'); + return new Error(cc._LogInfos.format(4927)); } item.content = item.url; diff --git a/cocos2d/core/load-pipeline/downloader.js b/cocos2d/core/load-pipeline/downloader.js index 5cc438eeee..8be727d791 100644 --- a/cocos2d/core/load-pipeline/downloader.js +++ b/cocos2d/core/load-pipeline/downloader.js @@ -63,7 +63,7 @@ function downloadScript (item, callback, isAsync) { s.parentNode.removeChild(s); s.removeEventListener('load', loadHandler, false); s.removeEventListener('error', errorHandler, false); - callback(new Error('Load ' + url + ' failed!'), url); + callback(new Error(cc._LogInfos.format(4928, url))); } s.addEventListener('load', loadHandler, false); s.addEventListener('error', errorHandler, false); @@ -72,7 +72,7 @@ function downloadScript (item, callback, isAsync) { function downloadWebp (item, callback, isCrossOrigin, img) { if (!cc.sys.capabilities.webp) { - return new Error('Load Webp ( ' + item.url + ' ) failed'); + return new Error(cc._LogInfos.format(4929, item.url)); } return downloadImage(item, callback, isCrossOrigin, img); } @@ -111,7 +111,7 @@ function downloadImage (item, callback, isCrossOrigin, img) { downloadImage(item, callback, false, img); } else { - callback(new Error('Load image (' + url + ') failed')); + callback(new Error(cc._LogInfos.format(4930, url))); } } diff --git a/cocos2d/core/load-pipeline/uuid-loader.js b/cocos2d/core/load-pipeline/uuid-loader.js index 52f41ac67f..d0adb86533 100644 --- a/cocos2d/core/load-pipeline/uuid-loader.js +++ b/cocos2d/core/load-pipeline/uuid-loader.js @@ -207,14 +207,14 @@ function loadUuid (item, callback) { json = JSON.parse(item.content); } catch (e) { - return new Error('Uuid Loader: Parse asset [' + item.id + '] failed : ' + e.stack); + return new Error(cc._LogInfos.format(4923, item.id, e.stack)); } } else if (typeof item.content === 'object') { json = item.content; } else { - return new Error('JSON Loader: Input item doesn\'t contain string content'); + return new Error(cc._LogInfos.format(4924)); } var classFinder; @@ -259,7 +259,7 @@ function loadUuid (item, callback) { catch (e) { cc.deserialize.Details.pool.put(tdInfo); var err = CC_JSB ? (e + '\n' + e.stack) : e.stack; - return new Error('Uuid Loader: Deserialize asset [' + item.id + '] failed : ' + err); + return new Error(cc._LogInfos.format(4925, item.id, err)); } asset._uuid = item.uuid; diff --git a/cocos2d/core/platform/CCSys.js b/cocos2d/core/platform/CCSys.js index 46cc1bdbda..777ce45a0a 100644 --- a/cocos2d/core/platform/CCSys.js +++ b/cocos2d/core/platform/CCSys.js @@ -716,7 +716,7 @@ else { sys._checkWebGLRenderMode = function () { if (cc._renderType !== cc.game.RENDER_TYPE_WEBGL) - throw new Error("This feature supports WebGL render mode only."); + throw new Error(cc._LogInfos.format(5202)); }; var _tmpCanvas1 = document.createElement("canvas"), diff --git a/cocos2d/core/platform/_CCClass.js b/cocos2d/core/platform/_CCClass.js index d66de087d1..f27d141901 100644 --- a/cocos2d/core/platform/_CCClass.js +++ b/cocos2d/core/platform/_CCClass.js @@ -174,7 +174,7 @@ cc.defineGetterSetter = function (proto, prop, getter, setter, getterName, sette setter && (desc.set = setter); Object.defineProperty(proto, prop, desc); } else { - throw new Error("browser does not support getters"); + throw new Error(cc._LogInfos.format(3658)); } }; diff --git a/cocos2d/kazmath/gl/matrix.js b/cocos2d/kazmath/gl/matrix.js index 4182cb78c2..0f6647ed6e 100644 --- a/cocos2d/kazmath/gl/matrix.js +++ b/cocos2d/kazmath/gl/matrix.js @@ -106,7 +106,7 @@ math.glMatrixMode = function (mode) { cc.current_stack = math.texture_matrix_stack; break; default: - throw new Error("Invalid matrix mode specified"); //TODO: Proper error handling + throw new Error(cc._LogInfos.format(7908)); //TODO: Proper error handling break; } }; @@ -169,7 +169,7 @@ math.glGetMatrix = function (mode, pOut) { pOut.assignFrom(math.texture_matrix_stack.top); break; default: - throw new Error("Invalid matrix mode specified"); //TODO: Proper error handling + throw new Error(cc._LogInfos.format(7908)); //TODO: Proper error handling break; } }; diff --git a/cocos2d/kazmath/quaternion.js b/cocos2d/kazmath/quaternion.js index fcd9c98b75..18aa9284c5 100644 --- a/cocos2d/kazmath/quaternion.js +++ b/cocos2d/kazmath/quaternion.js @@ -153,7 +153,7 @@ proto.multiply = function(quaternion) { //cc.kmQuaternionMultiply proto.normalize = function(){ //=cc.kmQuaternionNormalize var length = this.length(); if (Math.abs(length) <= cc.math.EPSILON) - throw new Error("current quaternion is an invalid value"); + throw new Error(cc._LogInfos.format(7909)); this.scale(1.0 / length); return this; }; diff --git a/cocos2d/particle/CCPNGReader.js b/cocos2d/particle/CCPNGReader.js index 99da8de84a..1016730039 100644 --- a/cocos2d/particle/CCPNGReader.js +++ b/cocos2d/particle/CCPNGReader.js @@ -161,7 +161,7 @@ var PNGReader = cc._Class.extend({ } this.pos += 4; if (this.pos > this.data.length) { - throw new Error("Incomplete or corrupt PNG file"); + throw new Error(cc._LogInfos.format(6017)); } } }, @@ -262,7 +262,7 @@ var PNGReader = cc._Class.extend({ } break; default: - throw new Error("Invalid filter algorithm: " + data[pos - 1]); + throw new Error(cc._LogInfos.format(6018, data[pos - 1])); } row++; } diff --git a/cocos2d/particle/CCParticleSystem.js b/cocos2d/particle/CCParticleSystem.js index 6b7f2d3867..d7f2ee116f 100644 --- a/cocos2d/particle/CCParticleSystem.js +++ b/cocos2d/particle/CCParticleSystem.js @@ -914,7 +914,7 @@ var ParticleSystem = cc.Class({ var self = this; cc.loader.load(file, function (err, content) { if (err || !content) { - throw err || new Error('Unkown error'); + throw err || new Error(cc._LogInfos.format(6029)); } if (!self.isValid) { return; diff --git a/cocos2d/particle/CCTIFFReader.js b/cocos2d/particle/CCTIFFReader.js index 54c16f9420..5113e8e507 100644 --- a/cocos2d/particle/CCTIFFReader.js +++ b/cocos2d/particle/CCTIFFReader.js @@ -65,7 +65,7 @@ var tiffReader = /** @lends tiffReader# */{ this.littleEndian = false; } else { console.log(BOM); - throw TypeError("Invalid byte order value."); + throw TypeError(cc._LogInfos.format(6019)); } return this.littleEndian; @@ -74,7 +74,7 @@ var tiffReader = /** @lends tiffReader# */{ hasTowel: function () { // Check for towel. if (this.getUint16(2) !== 42) { - throw RangeError("You forgot your towel!"); + throw RangeError(cc._LogInfos.format(6020)); return false; } @@ -95,7 +95,7 @@ var tiffReader = /** @lends tiffReader# */{ if (fieldTag in tagNames) { return tagNames[fieldTag]; } else { - console.log("Unknown Field Tag:", fieldTag); + cc.logID(6021, fieldTag); return "Tag" + fieldTag; } }, @@ -175,7 +175,7 @@ var tiffReader = /** @lends tiffReader# */{ var shiftLeft,rawBits; if (totalBits <= 0) { - console.log("No bits requested"); + cc.logID(6023); } else if (totalBits <= 8) { shiftLeft = 24 + bitOffset; rawBits = this.getUint8(newByteOffset); @@ -186,7 +186,7 @@ var tiffReader = /** @lends tiffReader# */{ shiftLeft = bitOffset; rawBits = this.getUint32(newByteOffset); } else { - console.log( "Too many bits requested" ); + cc.logID(6022); } return { @@ -302,7 +302,7 @@ var tiffReader = /** @lends tiffReader# */{ if (numStripOffsetValues === 1) { var stripByteCountValues = [Math.ceil((imageWidth * imageLength * bitsPerPixel) / 8)]; } else { - throw Error("Cannot recover from missing StripByteCounts"); + throw Error(cc._LogInfos.format(6024)); } } @@ -332,7 +332,7 @@ var tiffReader = /** @lends tiffReader# */{ byteOffset = sampleInfo.byteOffset - stripOffset; bitOffset = sampleInfo.bitOffset; - throw RangeError("Cannot handle sub-byte bits per sample"); + throw RangeError(cc._LogInfos.format(6025)); } } @@ -342,7 +342,7 @@ var tiffReader = /** @lends tiffReader# */{ jIncrement = bytesPerPixel; } else { jIncrement = 0; - throw RangeError("Cannot handle sub-byte bits per pixel"); + throw RangeError(cc._LogInfos.format(6026)); } break; @@ -412,7 +412,7 @@ var tiffReader = /** @lends tiffReader# */{ sample++; } } else { - throw RangeError("Cannot handle sub-byte bits per sample"); + throw RangeError(cc._LogInfos.format(6025)); } // Is our pixel complete? @@ -535,7 +535,7 @@ var tiffReader = /** @lends tiffReader# */{ // RGB Color Palette case 3: if (colorMapValues === undefined) { - throw Error("Palette image missing color map"); + throw Error(cc._LogInfos.format(6027)); } var colorMapIndex = pixelSamples[0]; @@ -547,7 +547,7 @@ var tiffReader = /** @lends tiffReader# */{ // Unknown Photometric Interpretation default: - throw RangeError('Unknown Photometric Interpretation:', photometricInterpretation); + throw RangeError(cc._LogInfos.format(6028, photometricInterpretation)); break; } diff --git a/cocos2d/render-texture/CCRenderTexture.js b/cocos2d/render-texture/CCRenderTexture.js index 72f8b336bc..369aa1bd97 100644 --- a/cocos2d/render-texture/CCRenderTexture.js +++ b/cocos2d/render-texture/CCRenderTexture.js @@ -343,7 +343,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * @param {Number} format */ saveToFile: function (filePath, format) { - cc.log("saveToFile isn't supported on Cocos2d-Html5"); + cc.logID(7604); }, /** @@ -351,7 +351,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * @return {*} */ newCCImage: function (flipImage) { - cc.log("saveToFile isn't supported on cocos2d-html5"); + cc.logID(7605); return null; }, diff --git a/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js b/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js index 71e1262f75..3e635cd8e6 100644 --- a/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js +++ b/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js @@ -95,5 +95,5 @@ proto.clearRect = function(x, y, width, height){ }; proto.clearDepth = function(depthValue){ - cc.log("clearDepth isn't supported on Cocos2d-Html5"); + cc.logID(7603); }; diff --git a/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js b/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js index e2768b6a7d..28e04922e3 100644 --- a/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js +++ b/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js @@ -136,7 +136,7 @@ proto.updateClearColor = function(clearColor){ }; proto.initWithWidthAndHeight = function(width, height, format, depthStencilFormat){ var node = this._node; if(format === cc.Texture2D.PixelFormat.A8) - cc.log( "cc.RenderTexture._initWithWidthAndHeightForWebGL() : only RGB and RGBA formats are valid for a render texture;"); + cc.logID(7601); var gl = cc._renderContext; this._fullRect = new cc.Rect(0,0, width, height); @@ -206,7 +206,7 @@ proto.initWithWidthAndHeight = function(width, height, format, depthStencilForma // check if it worked (probably worth doing :) ) if(gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) - cc.log("Could not attach texture to the framebuffer"); + cc.logID(7602); locTexture.setAliasTexParameters(); diff --git a/cocos2d/shaders/CCGLProgram.js b/cocos2d/shaders/CCGLProgram.js index 004b1f23d7..75b95a18e1 100644 --- a/cocos2d/shaders/CCGLProgram.js +++ b/cocos2d/shaders/CCGLProgram.js @@ -194,9 +194,9 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ */ initWithVertexShaderFilename: function (vShaderFilename, fShaderFileName) { var vertexSource = cc.loader.getRes(vShaderFilename); - if (!vertexSource) throw new Error("Please load the resource firset : " + vShaderFilename); + if (!vertexSource) throw new Error(cc._LogInfos.format(8106, vShaderFilename)); var fragmentSource = cc.loader.getRes(fShaderFileName); - if (!fragmentSource) throw new Error("Please load the resource firset : " + fShaderFileName); + if (!fragmentSource) throw new Error(cc._LogInfos.format(8106, fShaderFileName)); return this.initWithVertexShaderByteArray(vertexSource, fragmentSource); }, @@ -296,9 +296,9 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ */ getUniformLocationForName: function (name) { if (!name) - throw new Error("cc.GLProgram.getUniformLocationForName(): uniform name should be non-null"); + throw new Error(cc._LogInfos.format(8107)); if (!this._programObj) - throw new Error("cc.GLProgram.getUniformLocationForName(): Invalid operation. Cannot get uniform location when program is not initialized"); + throw new Error(cc._LogInfos.format(8108)); var location = this._uniforms[name] || this._glContext.getUniformLocation(this._programObj, name); return location; @@ -682,7 +682,7 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ _setUniformForMVPMatrixWithMat4: function(modelViewMatrix){ if(!modelViewMatrix) - throw new Error("modelView matrix is undefined."); + throw new Error(cc._LogInfos.format(8109)); this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_MVMATRIX], false, modelViewMatrix.mat); this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_PMATRIX], false, math.projection_matrix_stack.top.mat); }, diff --git a/cocos2d/tilemap/CCSGTMXLayer.js b/cocos2d/tilemap/CCSGTMXLayer.js index 0afcb7eccf..29b44aaef8 100644 --- a/cocos2d/tilemap/CCSGTMXLayer.js +++ b/cocos2d/tilemap/CCSGTMXLayer.js @@ -473,7 +473,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ */ getTileAt: function (pos, y) { if (pos === undefined) { - throw new Error("_ccsg.TMXLayer.getTileAt(): pos should be non-null"); + throw new Error(cc._LogInfos.format(7226)); } var x = pos; if (y === undefined) { @@ -481,7 +481,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ y = pos.y; } if (x >= this._layerSize.width || y >= this._layerSize.height || x < 0 || y < 0) { - throw new Error("_ccsg.TMXLayer.getTileAt(): invalid position"); + throw new Error(cc._LogInfos.format(7227)); } if (!this.tiles) { cc.logID(7204); @@ -523,7 +523,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ */ getTileGIDAt:function (pos, y) { if (pos === undefined) { - throw new Error("_ccsg.TMXLayer.getTileGIDAt(): pos should be non-null"); + throw new Error(cc._LogInfos.format(7228)); } var x = pos; if (y === undefined) { @@ -531,7 +531,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ y = pos.y; } if (x >= this._layerSize.width || y >= this._layerSize.height || x < 0 || y < 0) { - throw new Error("_ccsg.TMXLayer.getTileGIDAt(): invalid position"); + throw new Error(cc._LogInfos.format(7229)); } if (!this.tiles) { cc.logID(7205); @@ -558,7 +558,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ */ setTileGID: function(gid, posOrX, flagsOrY, flags) { if (posOrX === undefined) { - throw new Error("_ccsg.TMXLayer.setTileGID(): pos should be non-null"); + throw new Error(cc._LogInfos.format(7230)); } var pos; if (flags !== undefined || !(posOrX instanceof cc.Vec2)) { @@ -572,7 +572,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ pos.x = Math.floor(pos.x); pos.y = Math.floor(pos.y); if(pos.x >= this._layerSize.width || pos.y >= this._layerSize.height || pos.x < 0 || pos.y < 0) { - throw new Error("_ccsg.TMXLayer.setTileGID(): invalid position"); + throw new Error(cc._LogInfos.format(7231)); } if (!this.tiles) { cc.logID(7206); @@ -638,11 +638,11 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ */ getTileFlagsAt:function (pos, y) { if(!pos) - throw new Error("_ccsg.TMXLayer.getTileFlagsAt(): pos should be non-null"); + throw new Error(cc._LogInfos.format(7232)); if(y !== undefined) pos = cc.p(pos, y); if(pos.x >= this._layerSize.width || pos.y >= this._layerSize.height || pos.x < 0 || pos.y < 0) - throw new Error("_ccsg.TMXLayer.getTileFlagsAt(): invalid position"); + throw new Error(cc._LogInfos.format(7233)); if(!this.tiles){ cc.logID(7208); return null; @@ -664,13 +664,13 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ */ removeTileAt:function (pos, y) { if (!pos) { - throw new Error("_ccsg.TMXLayer.removeTileAt(): pos should be non-null"); + throw new Error(cc._LogInfos.format(7234)); } if (y !== undefined) { pos = cc.p(pos, y); } if (pos.x >= this._layerSize.width || pos.y >= this._layerSize.height || pos.x < 0 || pos.y < 0) { - throw new Error("_ccsg.TMXLayer.removeTileAt(): invalid position"); + throw new Error(cc._LogInfos.format(7235)); } if (!this.tiles) { cc.logID(7209); diff --git a/cocos2d/tilemap/CCSGTMXTiledMap.js b/cocos2d/tilemap/CCSGTMXTiledMap.js index 532a84dd00..08f2e7a4e3 100644 --- a/cocos2d/tilemap/CCSGTMXTiledMap.js +++ b/cocos2d/tilemap/CCSGTMXTiledMap.js @@ -307,7 +307,7 @@ _ccsg.TMXTiledMap = _ccsg.Node.extend(/** @lends _ccsg.TMXTiledMap# */{ */ getLayer:function (layerName) { if(!layerName || layerName.length === 0) - throw new Error("_ccsg.TMXTiledMap.getLayer(): layerName should be non-null or non-empty string."); + throw new Error(cc._LogInfos.format(7224)); var locChildren = this._children; for (var i = 0; i < locChildren.length; i++) { var layer = locChildren[i]; @@ -325,7 +325,7 @@ _ccsg.TMXTiledMap = _ccsg.Node.extend(/** @lends _ccsg.TMXTiledMap# */{ */ getObjectGroup:function (groupName) { if(!groupName || groupName.length === 0) - throw new Error("_ccsg.TMXTiledMap.getObjectGroup(): groupName should be non-null or non-empty string."); + throw new Error(cc._LogInfos.format(7225)); var locChildren = this._children; for (var i = 0; i < locChildren.length; i++) { var group = locChildren[i]; diff --git a/cocos2d/tilemap/CCTiledLayer.js b/cocos2d/tilemap/CCTiledLayer.js index 39e256c1b6..7818ef55cd 100644 --- a/cocos2d/tilemap/CCTiledLayer.js +++ b/cocos2d/tilemap/CCTiledLayer.js @@ -201,7 +201,7 @@ var TiledLayer = cc.Class({ setTileGID: function(gid, posOrX, flagsOrY, flags) { if (this._sgNode) { if(posOrX === undefined) - throw new Error("_ccsg.TMXLayer.setTileGID(): pos should be non-null"); + throw new Error(cc._LogInfos.format(7223)); var pos; if (flags !== undefined || !(posOrX instanceof cc.Vec2)) { // four parameters or posOrX is not a Vec2 object diff --git a/cocos2d/tilemap/editor/tiled-map.js b/cocos2d/tilemap/editor/tiled-map.js index 43a9e16802..5cf4244ff0 100644 --- a/cocos2d/tilemap/editor/tiled-map.js +++ b/cocos2d/tilemap/editor/tiled-map.js @@ -12,7 +12,7 @@ const TMX_ENCODING = { encoding: 'utf-8' }; function searchDependFiles(tmxFile, tmxFileData, cb) { var doc = new DOMParser().parseFromString(tmxFileData); if (!doc) { - return cb(new Error(`Parse ${tmxFile} failed.`)); + return cb(new Error(cc._LogInfos.format(7222, tmxFile))); } var textures = []; From 2223dcd0c89b805d2a13caacf17bf959c993dc5a Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 18 Dec 2017 11:09:48 +0800 Subject: [PATCH 2/3] refine code --- CCDebugger.js | 22 ++++--------- DebugInfos.js | 33 +++++++++---------- cocos2d/actions/CCAction.js | 4 +-- cocos2d/actions/CCActionCatmullRom.js | 2 +- cocos2d/actions/CCActionEase.js | 2 +- cocos2d/actions/CCActionInterval.js | 12 +++---- cocos2d/actions/CCActionManager.js | 4 +-- cocos2d/animation/playable.js | 2 +- cocos2d/core/CCConfiguration.js | 2 +- cocos2d/core/CCDrawingPrimitivesCanvas.js | 4 +-- cocos2d/core/CCDrawingPrimitivesWebGL.js | 2 +- cocos2d/core/CCGame.js | 2 +- cocos2d/core/components/CCRendererInSG.js | 2 +- cocos2d/core/event-manager/CCEventManager.js | 2 +- cocos2d/core/load-pipeline/asset-loader.js | 2 +- .../core/load-pipeline/audio-downloader.js | 4 +-- cocos2d/core/load-pipeline/downloader.js | 6 ++-- cocos2d/core/load-pipeline/uuid-loader.js | 6 ++-- cocos2d/core/platform/CCSys.js | 2 +- cocos2d/core/platform/_CCClass.js | 2 +- cocos2d/kazmath/gl/matrix.js | 4 +-- cocos2d/kazmath/quaternion.js | 2 +- cocos2d/particle/CCPNGReader.js | 4 +-- cocos2d/particle/CCParticleSystem.js | 2 +- cocos2d/particle/CCTIFFReader.js | 16 ++++----- cocos2d/shaders/CCGLProgram.js | 10 +++--- cocos2d/tilemap/CCSGTMXLayer.js | 20 +++++------ cocos2d/tilemap/CCSGTMXTiledMap.js | 4 +-- cocos2d/tilemap/CCTiledLayer.js | 2 +- cocos2d/tilemap/editor/tiled-map.js | 2 +- 30 files changed, 86 insertions(+), 97 deletions(-) diff --git a/CCDebugger.js b/CCDebugger.js index b7e4ef1a0e..7e8598e559 100644 --- a/CCDebugger.js +++ b/CCDebugger.js @@ -329,26 +329,18 @@ cc._throw = CC_EDITOR ? Editor.error : function (error) { } }; -var errorMapUrl = 'https://github.com/cocos-creator/engine/blob/master/EngineErrorMap.md'; - function genLogFunc(func, type) { return function (id) { 'use strict'; + var msg = cc._LogInfos.raw(id, type); if (arguments.length === 1) { - CC_DEBUG ? func(cc._LogInfos[id]) : func(type + ' ' + id + ', please go to ' + errorMapUrl + '#' + id + ' to see details.'); - return; + func(msg); } - if (CC_DEBUG) { - let argsArr = cc.js.shiftArguments.apply(null, arguments); - func.apply(cc, [cc._LogInfos[id]].concat(argsArr)); - } else { - var msg = ''; - if (arguments.length === 2) { - msg = 'Arguments: ' + arguments[1]; - } else if (arguments.length > 2) { - msg = 'Arguments: ' + cc.js.shiftArguments.apply(null, arguments).join(', '); - } - func(type + ' ' + id + ', please go to ' + errorMapUrl + '#' + id + ' to see details. ' + msg); + else if (arguments.length === 2) { + func(CC_DEBUG ? cc.js.formatStr(msg, arguments[1]) : msg + ' Arguments: ' + arguments[1]); + } + else { + func(cc._LogInfos.e(msg, cc.js.shiftArguments.apply(null, arguments))); } }; } diff --git a/DebugInfos.js b/DebugInfos.js index 5d3b748a4f..960c57b5ed 100644 --- a/DebugInfos.js +++ b/DebugInfos.js @@ -37,7 +37,6 @@ if (CC_DEBUG) { //configuration: 1100 "1100": "Expected 'data' dict, but not found. Config file: %s", //loadConfigFile "1101": "Please load the resource first : %s", //loadConfigFile_2 - "1102": "Please load the resource first : %s", // loadConfigFile //Director: 1200 "1200": "cocos2d: Director: Error in gettimeofday", //resume "1201": "cocos2d: Director: unrecognized projection", //setProjection @@ -627,9 +626,6 @@ if (CC_DEBUG) { "7233": "_ccsg.TMXLayer.getTileFlagsAt(): invalid position",//CCSGTMXLayer getTileFlagsAt "7234": "_ccsg.TMXLayer.removeTileAt(): pos should be non-null",//CCSGTMXLayer removeTileAt "7235": "_ccsg.TMXLayer.removeTileAt(): invalid position",//CCSGTMXLayer removeTileAt - "7236": "_ccsg.TMXLayer.getTileAt(): pos should be non-null",//CCSGTMXLayer getTileAt - "7237": "_ccsg.TMXLayer.getTileAt(): pos should be non-null",//CCSGTMXLayer getTileAt - //Wrapper: 7300 "7300": "The new selected must be number", //CheckBox.selected "7301": "The new bake must be boolean", //layer @@ -707,24 +703,25 @@ if (CC_DEBUG) { var errorMapUrl = 'https://github.com/cocos-creator/engine/blob/master/EngineErrorMap.md'; - cc._LogInfos.format = function (id) { - var type = 'error'; + function raw (id, type) { + return CC_DEBUG ? cc._LogInfos[id] : `${type} ${id}, please go to ${errorMapUrl}#${id} to see details.`; + } + + function format (msg, argsArray) { + return CC_DEBUG ? cc.js.formatStr.apply(null, [msg].concat(argsArray)) : msg + ' Arguments: ' + argsArray.join(', '); + } + + cc._LogInfos.e = function () { + var msg = raw(arguments[0], 'ERROR'); if (arguments.length === 1) { - return CC_DEBUG ? cc._LogInfos[id] : type + ' ' + id + ', please go to ' + errorMapUrl + '#' + id + ' to see details.' + return msg; } - if (CC_DEBUG) { - let argsArr = cc.js.shiftArguments.apply(null, arguments); - return cc._LogInfos[id].concat(argsArr); - } else { - var msg = ''; - if (arguments.length === 2) { - msg = 'Arguments: ' + arguments[1]; - } else if (arguments.length > 2) { - msg = 'Arguments: ' + cc.js.shiftArguments.apply(null, arguments).join(', '); - } - return type + ' ' + id + ', please go to ' + errorMapUrl + '#' + id + ' to see details. ' + msg; + else { + return format(msg, cc.js.shiftArguments.apply(null, arguments)); } }; + cc._LogInfos.raw = raw; + cc._LogInfos.format = format; } // module.exports = false; diff --git a/cocos2d/actions/CCAction.js b/cocos2d/actions/CCAction.js index 9d766d32a2..5f4c168970 100644 --- a/cocos2d/actions/CCAction.js +++ b/cocos2d/actions/CCAction.js @@ -300,7 +300,7 @@ cc.Speed = cc.Action.extend({ */ initWithAction:function (action, speed) { if(!action) - throw new Error(cc._LogInfos.format(1021)); + throw new Error(cc._LogInfos.e(1021)); this._innerAction = action; this._speed = speed; @@ -489,7 +489,7 @@ cc.Follow = cc.Action.extend({ */ initWithTarget:function (followedNode, rect) { if(!followedNode) - throw new Error(cc._LogInfos.format(1022)); + throw new Error(cc._LogInfos.e(1022)); var _this = this; rect = rect || cc.rect(0, 0, 0, 0); diff --git a/cocos2d/actions/CCActionCatmullRom.js b/cocos2d/actions/CCActionCatmullRom.js index a065f8d5ae..22c2cdb6c0 100644 --- a/cocos2d/actions/CCActionCatmullRom.js +++ b/cocos2d/actions/CCActionCatmullRom.js @@ -129,7 +129,7 @@ cc.CardinalSplineTo = cc.ActionInterval.extend({ initWithDuration:function (duration, points, tension) { if(!points || points.length === 0) - throw new Error(cc._LogInfos.format(1024)); + throw new Error(cc._LogInfos.e(1024)); if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { this.setPoints(points); diff --git a/cocos2d/actions/CCActionEase.js b/cocos2d/actions/CCActionEase.js index cead0e1139..86ef3a55ee 100644 --- a/cocos2d/actions/CCActionEase.js +++ b/cocos2d/actions/CCActionEase.js @@ -51,7 +51,7 @@ cc.ActionEase = cc.ActionInterval.extend({ */ initWithAction:function (action) { if(!action) - throw new Error(cc._LogInfos.format(1023)); + throw new Error(cc._LogInfos.e(1023)); if (this.initWithDuration(action.getDuration())) { this._inner = action; diff --git a/cocos2d/actions/CCActionInterval.js b/cocos2d/actions/CCActionInterval.js index f724d0bb4b..8b11190582 100644 --- a/cocos2d/actions/CCActionInterval.js +++ b/cocos2d/actions/CCActionInterval.js @@ -341,7 +341,7 @@ cc.Sequence = cc.ActionInterval.extend({ */ initWithTwoActions:function (actionOne, actionTwo) { if(!actionOne || !actionTwo) - throw new Error(cc._LogInfos.format(1025)); + throw new Error(cc._LogInfos.e(1025)); var d = actionOne._duration + actionTwo._duration; this.initWithDuration(d); @@ -649,7 +649,7 @@ cc.RepeatForever = cc.ActionInterval.extend({ */ initWithAction:function (action) { if(!action) - throw new Error(cc._LogInfos.format(1026)); + throw new Error(cc._LogInfos.e(1026)); this._innerAction = action; return true; @@ -767,7 +767,7 @@ cc.Spawn = cc.ActionInterval.extend({ */ initWithTwoActions:function (action1, action2) { if(!action1 || !action2) - throw new Error(cc._LogInfos.format(1027)); + throw new Error(cc._LogInfos.e(1027)); var ret = false; @@ -2473,9 +2473,9 @@ cc.ReverseTime = cc.ActionInterval.extend({ */ initWithAction:function (action) { if(!action) - throw new Error(cc._LogInfos.format(1028)); + throw new Error(cc._LogInfos.e(1028)); if(action === this._other) - throw new Error(cc._LogInfos.format(1029)); + throw new Error(cc._LogInfos.e(1029)); if (cc.ActionInterval.prototype.initWithDuration.call(this, action._duration)) { // Don't leak if action is reused @@ -2580,7 +2580,7 @@ cc.Animate = cc.ActionInterval.extend({ */ initWithAnimation:function (animation) { if(!animation) - throw new Error(cc._LogInfos.format(1030)); + throw new Error(cc._LogInfos.e(1030)); var singleDuration = animation.getDuration(); if (this.initWithDuration(singleDuration * animation.getLoops())) { this._nextFrame = 0; diff --git a/cocos2d/actions/CCActionManager.js b/cocos2d/actions/CCActionManager.js index d0e3e14582..ad5ead35f5 100644 --- a/cocos2d/actions/CCActionManager.js +++ b/cocos2d/actions/CCActionManager.js @@ -114,9 +114,9 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ */ addAction:function (action, target, paused) { if(!action) - throw new Error(cc._LogInfos.format(1000)); + throw new Error(cc._LogInfos.e(1000)); if(!target) - throw new Error(cc._LogInfos.format(1000)); + throw new Error(cc._LogInfos.e(1000)); //check if the action target already exists var element = this._hashTargets[target.__instanceId]; diff --git a/cocos2d/animation/playable.js b/cocos2d/animation/playable.js index 5ae9660ecf..3a3240e1a4 100644 --- a/cocos2d/animation/playable.js +++ b/cocos2d/animation/playable.js @@ -80,7 +80,7 @@ prototype.play = function () { this.onResume(); } else { - this.onError(cc._LogInfos.format(3912)); + this.onError(cc._LogInfos.e(3912)); } } else { diff --git a/cocos2d/core/CCConfiguration.js b/cocos2d/core/CCConfiguration.js index d4334e0b91..63979b6ca9 100644 --- a/cocos2d/core/CCConfiguration.js +++ b/cocos2d/core/CCConfiguration.js @@ -267,7 +267,7 @@ cc.configuration = /** @lends cc.configuration# */{ if(!this._inited) this._init(); var dict = cc.loader.getRes(url); - if(!dict) throw new Error(cc._LogInfos.format(1102, url)); + if(!dict) throw new Error(cc._LogInfos.e(1102, url)); cc.assertID(dict, 1101, url); var getDatas = dict["data"]; diff --git a/cocos2d/core/CCDrawingPrimitivesCanvas.js b/cocos2d/core/CCDrawingPrimitivesCanvas.js index d7c16e1001..ed0de2ab15 100644 --- a/cocos2d/core/CCDrawingPrimitivesCanvas.js +++ b/cocos2d/core/CCDrawingPrimitivesCanvas.js @@ -143,7 +143,7 @@ var DrawingPrimitiveCanvas = cc._Class.extend({ return; if (vertices.length < 3) - throw new Error(cc._LogInfos.format(6704)); + throw new Error(cc._LogInfos.e(6704)); var firstPoint = vertices[0], locContext = this._renderContext.getContext(); var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY(); @@ -319,7 +319,7 @@ var DrawingPrimitiveCanvas = cc._Class.extend({ destSize.width, destSize.height); break; default: - throw new Error(cc._LogInfos.format(6705)); + throw new Error(cc._LogInfos.e(6705)); break; } }, diff --git a/cocos2d/core/CCDrawingPrimitivesWebGL.js b/cocos2d/core/CCDrawingPrimitivesWebGL.js index 3112d22af9..2f8ccf6a6d 100644 --- a/cocos2d/core/CCDrawingPrimitivesWebGL.js +++ b/cocos2d/core/CCDrawingPrimitivesWebGL.js @@ -44,7 +44,7 @@ var DrawingPrimitiveWebGL = cc._Class.extend({ */ ctor:function (ctx) { if (cc.sys.platform !== cc.sys.WECHAT_GAME && !ctx instanceof WebGLRenderingContext) - throw new Error(cc._LogInfos.format(6703)); + throw new Error(cc._LogInfos.e(6703)); this._renderContext = ctx; this._colorArray = new Float32Array([1.0, 1.0, 1.0, 1.0]); diff --git a/cocos2d/core/CCGame.js b/cocos2d/core/CCGame.js index 8ed336ec85..bc1b88e0c3 100644 --- a/cocos2d/core/CCGame.js +++ b/cocos2d/core/CCGame.js @@ -650,7 +650,7 @@ var game = { if (this._rendererInitialized) return; if (!cc._supportRender) { - throw new Error(cc._LogInfos.format(3820, this.config[this.CONFIG_KEY.renderMode])); + throw new Error(cc._LogInfos.e(3820, this.config[this.CONFIG_KEY.renderMode])); } var el = this.config[game.CONFIG_KEY.id], diff --git a/cocos2d/core/components/CCRendererInSG.js b/cocos2d/core/components/CCRendererInSG.js index 620679cfca..81d9fe5156 100644 --- a/cocos2d/core/components/CCRendererInSG.js +++ b/cocos2d/core/components/CCRendererInSG.js @@ -96,7 +96,7 @@ var RendererInSG = cc.Class({ _replaceSgNode: function (sgNode) { if (CC_EDITOR && !(sgNode instanceof _ccsg.Node)) { - throw new Error(cc._LogInfos.format(1636)); + throw new Error(cc._LogInfos.e(1636)); } var node = this.node; diff --git a/cocos2d/core/event-manager/CCEventManager.js b/cocos2d/core/event-manager/CCEventManager.js index f03992bdd8..346ba3291b 100644 --- a/cocos2d/core/event-manager/CCEventManager.js +++ b/cocos2d/core/event-manager/CCEventManager.js @@ -1053,7 +1053,7 @@ var eventManager = { this._updateDirtyFlagForSceneGraph(); this._inDispatch++; if(!event || !event.getType) - throw new Error(cc._LogInfos.format(3511)); + throw new Error(cc._LogInfos.e(3511)); if (event.getType().startsWith(cc.Event.TOUCH)) { this._dispatchTouchEvent(event); this._inDispatch--; diff --git a/cocos2d/core/load-pipeline/asset-loader.js b/cocos2d/core/load-pipeline/asset-loader.js index af28842956..1e0f65550b 100644 --- a/cocos2d/core/load-pipeline/asset-loader.js +++ b/cocos2d/core/load-pipeline/asset-loader.js @@ -54,7 +54,7 @@ AssetLoader.prototype.handle = function (item, callback) { if (isRawAsset) { var ext = Path.extname(url).toLowerCase(); if (!ext) { - callback(new Error(cc._LogInfos.format(4931, uuid, url))); + callback(new Error(cc._LogInfos.e(4931, uuid, url))); return; } ext = ext.substr(1); diff --git a/cocos2d/core/load-pipeline/audio-downloader.js b/cocos2d/core/load-pipeline/audio-downloader.js index dc36f49c7c..822587cfe5 100644 --- a/cocos2d/core/load-pipeline/audio-downloader.js +++ b/cocos2d/core/load-pipeline/audio-downloader.js @@ -73,7 +73,7 @@ function loadDomAudio (item, callback) { } function loadWebAudio (item, callback) { - if (!context) callback(new Error(cc._LogInfos.format(4926))); + if (!context) callback(new Error(cc._LogInfos.e(4926))); var request = cc.loader.getXMLHttpRequest(); request.open("GET", item.url, true); @@ -100,7 +100,7 @@ function loadWebAudio (item, callback) { function downloadAudio (item, callback) { if (formatSupport.length === 0) { - return new Error(cc._LogInfos.format(4927)); + return new Error(cc._LogInfos.e(4927)); } item.content = item.url; diff --git a/cocos2d/core/load-pipeline/downloader.js b/cocos2d/core/load-pipeline/downloader.js index 8be727d791..1cb0d9b120 100644 --- a/cocos2d/core/load-pipeline/downloader.js +++ b/cocos2d/core/load-pipeline/downloader.js @@ -63,7 +63,7 @@ function downloadScript (item, callback, isAsync) { s.parentNode.removeChild(s); s.removeEventListener('load', loadHandler, false); s.removeEventListener('error', errorHandler, false); - callback(new Error(cc._LogInfos.format(4928, url))); + callback(new Error(cc._LogInfos.e(4928, url))); } s.addEventListener('load', loadHandler, false); s.addEventListener('error', errorHandler, false); @@ -72,7 +72,7 @@ function downloadScript (item, callback, isAsync) { function downloadWebp (item, callback, isCrossOrigin, img) { if (!cc.sys.capabilities.webp) { - return new Error(cc._LogInfos.format(4929, item.url)); + return new Error(cc._LogInfos.e(4929, item.url)); } return downloadImage(item, callback, isCrossOrigin, img); } @@ -111,7 +111,7 @@ function downloadImage (item, callback, isCrossOrigin, img) { downloadImage(item, callback, false, img); } else { - callback(new Error(cc._LogInfos.format(4930, url))); + callback(new Error(cc._LogInfos.e(4930, url))); } } diff --git a/cocos2d/core/load-pipeline/uuid-loader.js b/cocos2d/core/load-pipeline/uuid-loader.js index d0adb86533..0718d61759 100644 --- a/cocos2d/core/load-pipeline/uuid-loader.js +++ b/cocos2d/core/load-pipeline/uuid-loader.js @@ -207,14 +207,14 @@ function loadUuid (item, callback) { json = JSON.parse(item.content); } catch (e) { - return new Error(cc._LogInfos.format(4923, item.id, e.stack)); + return new Error(cc._LogInfos.e(4923, item.id, e.stack)); } } else if (typeof item.content === 'object') { json = item.content; } else { - return new Error(cc._LogInfos.format(4924)); + return new Error(cc._LogInfos.e(4924)); } var classFinder; @@ -259,7 +259,7 @@ function loadUuid (item, callback) { catch (e) { cc.deserialize.Details.pool.put(tdInfo); var err = CC_JSB ? (e + '\n' + e.stack) : e.stack; - return new Error(cc._LogInfos.format(4925, item.id, err)); + return new Error(cc._LogInfos.e(4925, item.id, err)); } asset._uuid = item.uuid; diff --git a/cocos2d/core/platform/CCSys.js b/cocos2d/core/platform/CCSys.js index 777ce45a0a..e2a1ecb5ac 100644 --- a/cocos2d/core/platform/CCSys.js +++ b/cocos2d/core/platform/CCSys.js @@ -716,7 +716,7 @@ else { sys._checkWebGLRenderMode = function () { if (cc._renderType !== cc.game.RENDER_TYPE_WEBGL) - throw new Error(cc._LogInfos.format(5202)); + throw new Error(cc._LogInfos.e(5202)); }; var _tmpCanvas1 = document.createElement("canvas"), diff --git a/cocos2d/core/platform/_CCClass.js b/cocos2d/core/platform/_CCClass.js index f27d141901..6ae66ef933 100644 --- a/cocos2d/core/platform/_CCClass.js +++ b/cocos2d/core/platform/_CCClass.js @@ -174,7 +174,7 @@ cc.defineGetterSetter = function (proto, prop, getter, setter, getterName, sette setter && (desc.set = setter); Object.defineProperty(proto, prop, desc); } else { - throw new Error(cc._LogInfos.format(3658)); + throw new Error(cc._LogInfos.e(3658)); } }; diff --git a/cocos2d/kazmath/gl/matrix.js b/cocos2d/kazmath/gl/matrix.js index 0f6647ed6e..0d0a4b50ab 100644 --- a/cocos2d/kazmath/gl/matrix.js +++ b/cocos2d/kazmath/gl/matrix.js @@ -106,7 +106,7 @@ math.glMatrixMode = function (mode) { cc.current_stack = math.texture_matrix_stack; break; default: - throw new Error(cc._LogInfos.format(7908)); //TODO: Proper error handling + throw new Error(cc._LogInfos.e(7908)); //TODO: Proper error handling break; } }; @@ -169,7 +169,7 @@ math.glGetMatrix = function (mode, pOut) { pOut.assignFrom(math.texture_matrix_stack.top); break; default: - throw new Error(cc._LogInfos.format(7908)); //TODO: Proper error handling + throw new Error(cc._LogInfos.e(7908)); //TODO: Proper error handling break; } }; diff --git a/cocos2d/kazmath/quaternion.js b/cocos2d/kazmath/quaternion.js index 18aa9284c5..4d8ce63cb6 100644 --- a/cocos2d/kazmath/quaternion.js +++ b/cocos2d/kazmath/quaternion.js @@ -153,7 +153,7 @@ proto.multiply = function(quaternion) { //cc.kmQuaternionMultiply proto.normalize = function(){ //=cc.kmQuaternionNormalize var length = this.length(); if (Math.abs(length) <= cc.math.EPSILON) - throw new Error(cc._LogInfos.format(7909)); + throw new Error(cc._LogInfos.e(7909)); this.scale(1.0 / length); return this; }; diff --git a/cocos2d/particle/CCPNGReader.js b/cocos2d/particle/CCPNGReader.js index 1016730039..6a9a8a0e8b 100644 --- a/cocos2d/particle/CCPNGReader.js +++ b/cocos2d/particle/CCPNGReader.js @@ -161,7 +161,7 @@ var PNGReader = cc._Class.extend({ } this.pos += 4; if (this.pos > this.data.length) { - throw new Error(cc._LogInfos.format(6017)); + throw new Error(cc._LogInfos.e(6017)); } } }, @@ -262,7 +262,7 @@ var PNGReader = cc._Class.extend({ } break; default: - throw new Error(cc._LogInfos.format(6018, data[pos - 1])); + throw new Error(cc._LogInfos.e(6018, data[pos - 1])); } row++; } diff --git a/cocos2d/particle/CCParticleSystem.js b/cocos2d/particle/CCParticleSystem.js index d7f2ee116f..66eaf411ca 100644 --- a/cocos2d/particle/CCParticleSystem.js +++ b/cocos2d/particle/CCParticleSystem.js @@ -914,7 +914,7 @@ var ParticleSystem = cc.Class({ var self = this; cc.loader.load(file, function (err, content) { if (err || !content) { - throw err || new Error(cc._LogInfos.format(6029)); + throw err || new Error(cc._LogInfos.e(6029)); } if (!self.isValid) { return; diff --git a/cocos2d/particle/CCTIFFReader.js b/cocos2d/particle/CCTIFFReader.js index 5113e8e507..7a53999419 100644 --- a/cocos2d/particle/CCTIFFReader.js +++ b/cocos2d/particle/CCTIFFReader.js @@ -65,7 +65,7 @@ var tiffReader = /** @lends tiffReader# */{ this.littleEndian = false; } else { console.log(BOM); - throw TypeError(cc._LogInfos.format(6019)); + throw TypeError(cc._LogInfos.e(6019)); } return this.littleEndian; @@ -74,7 +74,7 @@ var tiffReader = /** @lends tiffReader# */{ hasTowel: function () { // Check for towel. if (this.getUint16(2) !== 42) { - throw RangeError(cc._LogInfos.format(6020)); + throw RangeError(cc._LogInfos.e(6020)); return false; } @@ -302,7 +302,7 @@ var tiffReader = /** @lends tiffReader# */{ if (numStripOffsetValues === 1) { var stripByteCountValues = [Math.ceil((imageWidth * imageLength * bitsPerPixel) / 8)]; } else { - throw Error(cc._LogInfos.format(6024)); + throw Error(cc._LogInfos.e(6024)); } } @@ -332,7 +332,7 @@ var tiffReader = /** @lends tiffReader# */{ byteOffset = sampleInfo.byteOffset - stripOffset; bitOffset = sampleInfo.bitOffset; - throw RangeError(cc._LogInfos.format(6025)); + throw RangeError(cc._LogInfos.e(6025)); } } @@ -342,7 +342,7 @@ var tiffReader = /** @lends tiffReader# */{ jIncrement = bytesPerPixel; } else { jIncrement = 0; - throw RangeError(cc._LogInfos.format(6026)); + throw RangeError(cc._LogInfos.e(6026)); } break; @@ -412,7 +412,7 @@ var tiffReader = /** @lends tiffReader# */{ sample++; } } else { - throw RangeError(cc._LogInfos.format(6025)); + throw RangeError(cc._LogInfos.e(6025)); } // Is our pixel complete? @@ -535,7 +535,7 @@ var tiffReader = /** @lends tiffReader# */{ // RGB Color Palette case 3: if (colorMapValues === undefined) { - throw Error(cc._LogInfos.format(6027)); + throw Error(cc._LogInfos.e(6027)); } var colorMapIndex = pixelSamples[0]; @@ -547,7 +547,7 @@ var tiffReader = /** @lends tiffReader# */{ // Unknown Photometric Interpretation default: - throw RangeError(cc._LogInfos.format(6028, photometricInterpretation)); + throw RangeError(cc._LogInfos.e(6028, photometricInterpretation)); break; } diff --git a/cocos2d/shaders/CCGLProgram.js b/cocos2d/shaders/CCGLProgram.js index 75b95a18e1..4e5161b359 100644 --- a/cocos2d/shaders/CCGLProgram.js +++ b/cocos2d/shaders/CCGLProgram.js @@ -194,9 +194,9 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ */ initWithVertexShaderFilename: function (vShaderFilename, fShaderFileName) { var vertexSource = cc.loader.getRes(vShaderFilename); - if (!vertexSource) throw new Error(cc._LogInfos.format(8106, vShaderFilename)); + if (!vertexSource) throw new Error(cc._LogInfos.e(8106, vShaderFilename)); var fragmentSource = cc.loader.getRes(fShaderFileName); - if (!fragmentSource) throw new Error(cc._LogInfos.format(8106, fShaderFileName)); + if (!fragmentSource) throw new Error(cc._LogInfos.e(8106, fShaderFileName)); return this.initWithVertexShaderByteArray(vertexSource, fragmentSource); }, @@ -296,9 +296,9 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ */ getUniformLocationForName: function (name) { if (!name) - throw new Error(cc._LogInfos.format(8107)); + throw new Error(cc._LogInfos.e(8107)); if (!this._programObj) - throw new Error(cc._LogInfos.format(8108)); + throw new Error(cc._LogInfos.e(8108)); var location = this._uniforms[name] || this._glContext.getUniformLocation(this._programObj, name); return location; @@ -682,7 +682,7 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ _setUniformForMVPMatrixWithMat4: function(modelViewMatrix){ if(!modelViewMatrix) - throw new Error(cc._LogInfos.format(8109)); + throw new Error(cc._LogInfos.e(8109)); this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_MVMATRIX], false, modelViewMatrix.mat); this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_PMATRIX], false, math.projection_matrix_stack.top.mat); }, diff --git a/cocos2d/tilemap/CCSGTMXLayer.js b/cocos2d/tilemap/CCSGTMXLayer.js index 29b44aaef8..0ba37797b9 100644 --- a/cocos2d/tilemap/CCSGTMXLayer.js +++ b/cocos2d/tilemap/CCSGTMXLayer.js @@ -473,7 +473,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ */ getTileAt: function (pos, y) { if (pos === undefined) { - throw new Error(cc._LogInfos.format(7226)); + throw new Error(cc._LogInfos.e(7226)); } var x = pos; if (y === undefined) { @@ -481,7 +481,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ y = pos.y; } if (x >= this._layerSize.width || y >= this._layerSize.height || x < 0 || y < 0) { - throw new Error(cc._LogInfos.format(7227)); + throw new Error(cc._LogInfos.e(7227)); } if (!this.tiles) { cc.logID(7204); @@ -523,7 +523,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ */ getTileGIDAt:function (pos, y) { if (pos === undefined) { - throw new Error(cc._LogInfos.format(7228)); + throw new Error(cc._LogInfos.e(7228)); } var x = pos; if (y === undefined) { @@ -531,7 +531,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ y = pos.y; } if (x >= this._layerSize.width || y >= this._layerSize.height || x < 0 || y < 0) { - throw new Error(cc._LogInfos.format(7229)); + throw new Error(cc._LogInfos.e(7229)); } if (!this.tiles) { cc.logID(7205); @@ -558,7 +558,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ */ setTileGID: function(gid, posOrX, flagsOrY, flags) { if (posOrX === undefined) { - throw new Error(cc._LogInfos.format(7230)); + throw new Error(cc._LogInfos.e(7230)); } var pos; if (flags !== undefined || !(posOrX instanceof cc.Vec2)) { @@ -572,7 +572,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ pos.x = Math.floor(pos.x); pos.y = Math.floor(pos.y); if(pos.x >= this._layerSize.width || pos.y >= this._layerSize.height || pos.x < 0 || pos.y < 0) { - throw new Error(cc._LogInfos.format(7231)); + throw new Error(cc._LogInfos.e(7231)); } if (!this.tiles) { cc.logID(7206); @@ -638,11 +638,11 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ */ getTileFlagsAt:function (pos, y) { if(!pos) - throw new Error(cc._LogInfos.format(7232)); + throw new Error(cc._LogInfos.e(7232)); if(y !== undefined) pos = cc.p(pos, y); if(pos.x >= this._layerSize.width || pos.y >= this._layerSize.height || pos.x < 0 || pos.y < 0) - throw new Error(cc._LogInfos.format(7233)); + throw new Error(cc._LogInfos.e(7233)); if(!this.tiles){ cc.logID(7208); return null; @@ -664,13 +664,13 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ */ removeTileAt:function (pos, y) { if (!pos) { - throw new Error(cc._LogInfos.format(7234)); + throw new Error(cc._LogInfos.e(7234)); } if (y !== undefined) { pos = cc.p(pos, y); } if (pos.x >= this._layerSize.width || pos.y >= this._layerSize.height || pos.x < 0 || pos.y < 0) { - throw new Error(cc._LogInfos.format(7235)); + throw new Error(cc._LogInfos.e(7235)); } if (!this.tiles) { cc.logID(7209); diff --git a/cocos2d/tilemap/CCSGTMXTiledMap.js b/cocos2d/tilemap/CCSGTMXTiledMap.js index 08f2e7a4e3..4dffc2f9c1 100644 --- a/cocos2d/tilemap/CCSGTMXTiledMap.js +++ b/cocos2d/tilemap/CCSGTMXTiledMap.js @@ -307,7 +307,7 @@ _ccsg.TMXTiledMap = _ccsg.Node.extend(/** @lends _ccsg.TMXTiledMap# */{ */ getLayer:function (layerName) { if(!layerName || layerName.length === 0) - throw new Error(cc._LogInfos.format(7224)); + throw new Error(cc._LogInfos.e(7224)); var locChildren = this._children; for (var i = 0; i < locChildren.length; i++) { var layer = locChildren[i]; @@ -325,7 +325,7 @@ _ccsg.TMXTiledMap = _ccsg.Node.extend(/** @lends _ccsg.TMXTiledMap# */{ */ getObjectGroup:function (groupName) { if(!groupName || groupName.length === 0) - throw new Error(cc._LogInfos.format(7225)); + throw new Error(cc._LogInfos.e(7225)); var locChildren = this._children; for (var i = 0; i < locChildren.length; i++) { var group = locChildren[i]; diff --git a/cocos2d/tilemap/CCTiledLayer.js b/cocos2d/tilemap/CCTiledLayer.js index 7818ef55cd..46a38d3e8e 100644 --- a/cocos2d/tilemap/CCTiledLayer.js +++ b/cocos2d/tilemap/CCTiledLayer.js @@ -201,7 +201,7 @@ var TiledLayer = cc.Class({ setTileGID: function(gid, posOrX, flagsOrY, flags) { if (this._sgNode) { if(posOrX === undefined) - throw new Error(cc._LogInfos.format(7223)); + throw new Error(cc._LogInfos.e(7223)); var pos; if (flags !== undefined || !(posOrX instanceof cc.Vec2)) { // four parameters or posOrX is not a Vec2 object diff --git a/cocos2d/tilemap/editor/tiled-map.js b/cocos2d/tilemap/editor/tiled-map.js index 5cf4244ff0..cf0f513cc1 100644 --- a/cocos2d/tilemap/editor/tiled-map.js +++ b/cocos2d/tilemap/editor/tiled-map.js @@ -12,7 +12,7 @@ const TMX_ENCODING = { encoding: 'utf-8' }; function searchDependFiles(tmxFile, tmxFileData, cb) { var doc = new DOMParser().parseFromString(tmxFileData); if (!doc) { - return cb(new Error(cc._LogInfos.format(7222, tmxFile))); + return cb(new Error(cc._LogInfos.e(7222, tmxFile))); } var textures = []; From 5843fdcb6940e7e20bb5f10a5c2aaa7f439663dd Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 18 Dec 2017 11:18:48 +0800 Subject: [PATCH 3/3] refine code --- DebugInfos.js | 1 - cocos2d/core/components/CCRendererInSG.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/DebugInfos.js b/DebugInfos.js index 960c57b5ed..3b51bd2f74 100644 --- a/DebugInfos.js +++ b/DebugInfos.js @@ -113,7 +113,6 @@ if (CC_DEBUG) { "1633": "Internal error, should not remove unknown node from parent.", //parent "1634": "addChild: The child to add must be instance of cc.Node, not %s.", //addChild "1635": "reorderChild: this child is not in children list", // reorderChild - "1636": "Invalid sgNode. It must be an instance of _ccsg.Node", // RendererInSG //AtlasNode: 1700 "1700": "cc.AtlasNode.updateAtlasValues(): Shall be overridden in subclasses", //_updateAtlasValues "1701": "", //_initWithTileFile diff --git a/cocos2d/core/components/CCRendererInSG.js b/cocos2d/core/components/CCRendererInSG.js index 81d9fe5156..7adaed58e1 100644 --- a/cocos2d/core/components/CCRendererInSG.js +++ b/cocos2d/core/components/CCRendererInSG.js @@ -96,7 +96,7 @@ var RendererInSG = cc.Class({ _replaceSgNode: function (sgNode) { if (CC_EDITOR && !(sgNode instanceof _ccsg.Node)) { - throw new Error(cc._LogInfos.e(1636)); + throw new Error("Invalid sgNode. It must be an instance of _ccsg.Node"); } var node = this.node;