This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-common.git


The following commit(s) were added to refs/heads/master by this push:
     new 641be1e  refactor(CordovaError)!: remove unused features (#117)
641be1e is described below

commit 641be1e1c242837c0ff43bc540a15b7a7600439c
Author: Raphael von der GrĂ¼n <[email protected]>
AuthorDate: Thu Dec 12 22:43:49 2019 +0100

    refactor(CordovaError)!: remove unused features (#117)
    
    * Remove CordovaExternalToolErrorContext
    
    * Remove unused CordovaError.UNKNOWN_ERROR
    
    * Remove unused verbose mode
    
    * Remove unused getErrorCodeName
    
    * Remove unused support for error codes
    
    * Fix JavaDocs
---
 cordova-common.js                                  |  1 -
 spec/CordovaError/CordovaError.spec.js             | 14 +----
 src/CordovaError/CordovaError.js                   | 67 +++++-----------------
 .../CordovaExternalToolErrorContext.js             | 46 ---------------
 4 files changed, 16 insertions(+), 112 deletions(-)

diff --git a/cordova-common.js b/cordova-common.js
index 3fe53c9..b268e1e 100644
--- a/cordova-common.js
+++ b/cordova-common.js
@@ -25,7 +25,6 @@ module.exports = {
     get CordovaError () { return require('./src/CordovaError/CordovaError'); },
     get CordovaLogger () { return require('./src/CordovaLogger'); },
     get CordovaCheck () { return require('./src/CordovaCheck'); },
-    get CordovaExternalToolErrorContext () { return 
require('./src/CordovaError/CordovaExternalToolErrorContext'); },
     get PlatformJson () { return require('./src/PlatformJson'); },
     get ConfigParser () { return require('./src/ConfigParser/ConfigParser'); },
     get FileUpdater () { return require('./src/FileUpdater'); },
diff --git a/spec/CordovaError/CordovaError.spec.js 
b/spec/CordovaError/CordovaError.spec.js
index 590644d..bc1d6b0 100644
--- a/spec/CordovaError/CordovaError.spec.js
+++ b/spec/CordovaError/CordovaError.spec.js
@@ -24,18 +24,8 @@ describe('CordovaError class', function () {
         expect(new CordovaError('error')).toEqual(jasmine.any(CordovaError));
     });
 
-    it('Test 002 : getErrorCodeName works', function () {
-        var error002_1 = new CordovaError('error', 0);
-        expect(error002_1.getErrorCodeName()).toEqual('UNKNOWN_ERROR');
-        var error002_2 = new CordovaError('error', 1);
-        expect(error002_2.getErrorCodeName()).toEqual('EXTERNAL_TOOL_ERROR');
-    });
-
     it('Test 003 : toString works', function () {
-        var error003_1 = new CordovaError('error', 0);
-        expect(error003_1.toString(false)).toEqual('error');
-        expect(error003_1.toString(true)).toContain(error003_1.stack);
-        var error003_2 = new CordovaError('error', 1);
-        expect(error003_2.toString(false)).toEqual('External tool failed with 
an error: error');
+        var error003_1 = new CordovaError('error');
+        expect(error003_1.toString()).toEqual('error');
     });
 });
diff --git a/src/CordovaError/CordovaError.js b/src/CordovaError/CordovaError.js
index 05bb7ca..8aeda07 100644
--- a/src/CordovaError/CordovaError.js
+++ b/src/CordovaError/CordovaError.js
@@ -17,70 +17,31 @@
     under the License.
 */
 
-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
+ * A derived exception class
+ *
+ * Based on: https://stackoverflow.com/a/8460753/380229
  */
 class CordovaError extends Error {
-    constructor (message, code, context) {
+    /**
+     * Creates new CordovaError with given error message
+     *
+     * @param {String} message Error message
+     */
+    constructor (message) {
         super(message);
         Error.captureStackTrace(this, this.constructor);
         this.name = this.constructor.name;
-        this.code = code || CordovaError.UNKNOWN_ERROR;
-        this.context = context;
     }
 
     /**
-     * Translates instance's error code number into error code name, e.g. 0 -> 
UNKNOWN_ERROR
-     * @returns {string} Error code string name
+     * Converts this to its string representation
+     *
+     * @return {String} Stringified error representation
      */
-    getErrorCodeName () {
-        return Object.keys(CordovaError)
-            .find(key => CordovaError[key] === this.code);
-    }
-
-    /**
-     * 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
-     */
-    toString (isVerbose) {
-        var message = '';
-        var 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;
+    toString () {
+        return this.message;
     }
 }
 
-// TODO: Extend error codes according the projects specifics
-CordovaError.UNKNOWN_ERROR = 0;
-CordovaError.EXTERNAL_TOOL_ERROR = 1;
-
 module.exports = CordovaError;
diff --git a/src/CordovaError/CordovaExternalToolErrorContext.js 
b/src/CordovaError/CordovaExternalToolErrorContext.js
deleted file mode 100644
index 73d007e..0000000
--- a/src/CordovaError/CordovaExternalToolErrorContext.js
+++ /dev/null
@@ -1,46 +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.
- */
-
-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;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to