You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sg...@apache.org on 2015/09/20 14:18:08 UTC

[09/10] cordova-lib git commit: Picking CordovaError changes from apache@a3b1fca

Picking CordovaError changes from apache@a3b1fca


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/4909fac1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/4909fac1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/4909fac1

Branch: refs/heads/master
Commit: 4909fac13452617bf285f76e5ed151eb6292a1f9
Parents: 59042ba
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Fri Sep 18 14:13:34 2015 +0300
Committer: sgrebnov <v-...@microsoft.com>
Committed: Sun Sep 20 15:14:54 2015 +0300

----------------------------------------------------------------------
 cordova-common/cordova-common.js                |  3 +-
 cordova-common/src/CordovaError.js              | 32 -------
 cordova-common/src/CordovaError/CordovaError.js | 91 ++++++++++++++++++++
 .../CordovaExternalToolErrorContext.js          | 48 +++++++++++
 cordova-common/src/PluginInfo/PluginInfo.js     |  2 +-
 cordova-common/src/configparser/ConfigParser.js |  2 +-
 6 files changed, 143 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4909fac1/cordova-common/cordova-common.js
----------------------------------------------------------------------
diff --git a/cordova-common/cordova-common.js b/cordova-common/cordova-common.js
index 5873aa7..59b52fc 100644
--- a/cordova-common/cordova-common.js
+++ b/cordova-common/cordova-common.js
@@ -25,7 +25,8 @@ exports = module.exports = {
     superspawn: require('./src/superspawn'),
 
     ActionStack: require('./src/ActionStack'),
-    CordovaError: require('./src/CordovaError'),
+    CordovaError: require('./src/CordovaError/CordovaError'),
+    CordovaExternalToolErrorContext: require('./src/CordovaError/CordovaExternalToolErrorContext'),
     PlatformJson: require('./src/PlatformJson'),
     ConfigParser: require('./src/ConfigParser/ConfigParser.js'),
 

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4909fac1/cordova-common/src/CordovaError.js
----------------------------------------------------------------------
diff --git a/cordova-common/src/CordovaError.js b/cordova-common/src/CordovaError.js
deleted file mode 100644
index d9989c4..0000000
--- a/cordova-common/src/CordovaError.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied.  See the License for the
-    specific language governing permissions and limitations
-    under the License.
-*/
-
-/* jshint proto:true */
-
-// A derived exception class. See usage example in cli.js
-// Based on:
-// stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript/8460753#8460753
-function CordovaError(message) {
-    Error.captureStackTrace(this, this.constructor);
-    this.name = this.constructor.name;
-    this.message = message;
-}
-CordovaError.prototype.__proto__ = Error.prototype;
-
-module.exports = CordovaError;

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4909fac1/cordova-common/src/CordovaError/CordovaError.js
----------------------------------------------------------------------
diff --git a/cordova-common/src/CordovaError/CordovaError.js b/cordova-common/src/CordovaError/CordovaError.js
new file mode 100644
index 0000000..7262448
--- /dev/null
+++ b/cordova-common/src/CordovaError/CordovaError.js
@@ -0,0 +1,91 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+
+/* jshint proto:true */
+
+var EOL = require('os').EOL;
+
+/**
+ * A derived exception class. See usage example in cli.js
+ * Based on:
+ * stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript/8460753#8460753
+ * @param {String} message Error message
+ * @param {Number} [code=0] Error code
+ * @param {CordovaExternalToolErrorContext} [context] External tool error context object
+ * @constructor
+ */
+function CordovaError(message, code, context) {
+    Error.captureStackTrace(this, this.constructor);
+    this.name = this.constructor.name;
+    this.message = message;
+    this.code = code || CordovaError.UNKNOWN_ERROR;
+    this.context = context;
+}
+CordovaError.prototype.__proto__ = Error.prototype;
+
+// TODO: Extend error codes according the projects specifics
+CordovaError.UNKNOWN_ERROR = 0;
+CordovaError.EXTERNAL_TOOL_ERROR = 1;
+
+/**
+ * Translates instance's error code number into error code name, e.g. 0 -> UNKNOWN_ERROR
+ * @returns {string} Error code string name
+ */
+CordovaError.prototype.getErrorCodeName = function() {
+    for(var key in CordovaError) {
+        if(CordovaError.hasOwnProperty(key)) {
+            if(CordovaError[key] === this.code) {
+                return key;
+            }
+        }
+    }
+};
+
+/**
+ * Converts CordovaError instance to string representation
+ * @param   {Boolean}  [isVerbose]  Set up verbose mode. Used to provide more
+ *   details including information about error code name and context
+ * @return  {String}              Stringified error representation
+ */
+CordovaError.prototype.toString = function(isVerbose) {
+    var message = '', codePrefix = '';
+
+    if(this.code !== CordovaError.UNKNOWN_ERROR) {
+        codePrefix = 'code: ' + this.code + (isVerbose ? (' (' + this.getErrorCodeName() + ')') : '') + ' ';
+    }
+
+    if(this.code === CordovaError.EXTERNAL_TOOL_ERROR) {
+        if(typeof this.context !== 'undefined') {
+            if(isVerbose) {
+                message = codePrefix + EOL + this.context.toString(isVerbose) + '\n failed with an error: ' +
+                    this.message + EOL + 'Stack trace: ' + this.stack;
+            } else {
+                message = codePrefix + '\'' + this.context.toString(isVerbose) + '\' ' + this.message;
+            }
+        } else {
+            message = 'External tool failed with an error: ' + this.message;
+        }
+    } else {
+        message = isVerbose ? codePrefix + this.stack : codePrefix + this.message;
+    }
+
+    return message;
+};
+
+module.exports = CordovaError;

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4909fac1/cordova-common/src/CordovaError/CordovaExternalToolErrorContext.js
----------------------------------------------------------------------
diff --git a/cordova-common/src/CordovaError/CordovaExternalToolErrorContext.js b/cordova-common/src/CordovaError/CordovaExternalToolErrorContext.js
new file mode 100644
index 0000000..ca9a4aa
--- /dev/null
+++ b/cordova-common/src/CordovaError/CordovaExternalToolErrorContext.js
@@ -0,0 +1,48 @@
+/**
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+/* jshint proto:true */
+
+var path = require('path');
+
+/**
+ * @param {String} cmd Command full path
+ * @param {String[]} args Command args
+ * @param {String} [cwd] Command working directory
+ * @constructor
+ */
+function CordovaExternalToolErrorContext(cmd, args, cwd) {
+    this.cmd = cmd;
+    // Helper field for readability
+    this.cmdShortName = path.basename(cmd);
+    this.args = args;
+    this.cwd = cwd;
+}
+
+CordovaExternalToolErrorContext.prototype.toString = function(isVerbose) {
+    if(isVerbose) {
+        return 'External tool \'' + this.cmdShortName + '\'' +
+            '\nCommand full path: ' + this.cmd + '\nCommand args: ' + this.args +
+            (typeof this.cwd !== 'undefined' ? '\nCommand cwd: ' + this.cwd : '');
+    }
+
+    return this.cmdShortName;
+};
+
+module.exports = CordovaExternalToolErrorContext;

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4909fac1/cordova-common/src/PluginInfo/PluginInfo.js
----------------------------------------------------------------------
diff --git a/cordova-common/src/PluginInfo/PluginInfo.js b/cordova-common/src/PluginInfo/PluginInfo.js
index 10cfdf0..073f3f9 100644
--- a/cordova-common/src/PluginInfo/PluginInfo.js
+++ b/cordova-common/src/PluginInfo/PluginInfo.js
@@ -31,7 +31,7 @@ TODO (kamrik): refactor this to not use sync functions and return promises.
 var path = require('path')
   , fs = require('fs')
   , xml_helpers = require('../util/xml-helpers')
-  , CordovaError = require('../CordovaError')
+  , CordovaError = require('../CordovaError/CordovaError')
   ;
 
 function PluginInfo(dirname) {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4909fac1/cordova-common/src/configparser/ConfigParser.js
----------------------------------------------------------------------
diff --git a/cordova-common/src/configparser/ConfigParser.js b/cordova-common/src/configparser/ConfigParser.js
index 9dcccb5..5006a4d 100644
--- a/cordova-common/src/configparser/ConfigParser.js
+++ b/cordova-common/src/configparser/ConfigParser.js
@@ -21,7 +21,7 @@
 
 var et = require('elementtree'),
     xml= require('../util/xml-helpers'),
-    CordovaError = require('../CordovaError'),
+    CordovaError = require('../CordovaError/CordovaError'),
     fs = require('fs'),
     events = require('../events');
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org