1.0.2 • Published 7 years ago

gfs-auto-trycatch v1.0.2

Weekly downloads
5
License
Apache-2.0
Repository
github
Last release
7 years ago

gfs-auto-trycatch-base

Auto add try-catch wrap for function base util.

Options

  • sourceRoot: the code source root path
  • filename: in fact this option is file path
  • filenameRelative: file name
  • sourceMap: code source map file content, default is false
  • errorHandleFuncName : error handler function name, default is GFS_TRY_CATCH_ERROR_HANDLE, NOTE: this function name must be defined global.

Usage

$ npm install gfs-auto-trycatch --save-dev
const autoTryCatch = require('gfs-auto-trycatch');
const codeContent = `
class Demo {
  consturctor(){
    this.name = "demo"
  }
  action(){
    console.log('this name is: ', this.name)
  }
}
`
const newCtn = autoTryCatch(codeContent, {});

console.log(newCtn);
//  after add try catch
/*class Demo {
  consturctor() {
    try {
      this.name = "demo";
    } catch (_e) {
      window.GFS_TRY_CATCH_ERROR_HANDLE && window.GFS_TRY_CATCH_ERROR_HANDLE(_e, "", "consturctor", 3, 2);
      throw _e;
    }
  }
  action() {
    try {
      console.log('this name is: ', this.name);
    } catch (_e2) {
      window.GFS_TRY_CATCH_ERROR_HANDLE && window.GFS_TRY_CATCH_ERROR_HANDLE(_e2, "", "action", 6, 2);
      throw _e2;
    }
  }
}*/