How to use the stacktrace-js.fromError function in stacktrace-js

To help you get started, we’ve selected a few stacktrace-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github siegrainwong / ancorazor / Ancorazor.API / ClientApp / src / app / shared / services / global-error-handler.ts View on Github external
handleError(error: Error) {
    const loggingService = this._injector.get(LoggingService);
    const location = this._injector.get(LocationStrategy);
    const message = error.message ? error.message : error.toString();
    const url = location instanceof PathLocationStrategy ? location.path() : "";
    /**
     * TODO: 想一下怎么做一个简单的APM
     * 最好都用elk技术栈配合skywalking前后一条龙
     * 1. 记录首屏加载,文档加载(DOMContentLoaded),页面加载(load),脚本错误,慢路由
     * 2. 跟踪业务流程
     * 3. 离线存储和在线存储
     * 4. 生成Source-map,webpack打包后的代码报错你是trace不到的
     * 5. 错误预警,统计报表
     */
    // get the stack trace, lets grab the last 10 stacks only
    StackTrace.fromError(error).then(stackframes => {
      const stackString = stackframes
        .splice(0, 20)
        .map(function(sf) {
          return sf.toString();
        })
        .join("\n");
      // log on the server
      loggingService.error({ message, url, stack: stackString });
    });
    throw error;
  }
}
github GoogleCloudPlatform / stackdriver-errors-js / stackdriver-errors.js View on Github external
function resolveError(err, firstFrameIndex) {
  // This will use sourcemaps and normalize the stack frames
  return StackTrace.fromError(err).then(function(stack) {
    var lines = [err.toString()];
    // Reconstruct to a JS stackframe as expected by Error Reporting parsers.
    for (var s = firstFrameIndex; s < stack.length; s++) {
      // Cannot use stack[s].source as it is not populated from source maps.
      lines.push([
        '    at ',
        // If a function name is not available '' will be used.
        stack[s].getFunctionName() || '', ' (',
        stack[s].getFileName(), ':',
        stack[s].getLineNumber(), ':',
        stack[s].getColumnNumber(), ')',
      ].join(''));
    }
    return lines.join('\n');
  }, function(reason) {
    // Failure to extract stacktrace
github textileio / photos / App / Services / ErrorHandler.ts View on Github external
const e = new Error()
  if (typeof error === 'string') {
    e.name = error
    e.message = error
  } else if (typeof error === 'number') {
    e.name = error.toString()
    e.message = error.toString()
  } else if (error instanceof Error) {
    e.name = error.name
    e.message = error.message
    e.stack = error.stack
  } else {
    e.name = 'unknown'
    e.message = 'unknown'
  }
  StackTrace.fromError(e, { offline: true }).then(frames => {
    // Crashlytics.recordCustomExceptionName(e.message, e.message, frames)
    const updatedFrames = frames.map(row => ({
      lineNumber: row.lineNumber,
      columnNumber: row.columnNumber,
      functionName: row.functionName,
      fileName: `${row.fileName}:${row.lineNumber || 0}:${row.columnNumber ||
        0}`
    }))
    Firebase.crashlytics().recordError(0, e.message)
    // Crashlytics.recordCustomExceptionName(e.message, e.message, updatedFrames)
  })
  if (originalHandler) {
    if (Platform.OS === 'ios') {
      originalHandler(error, isFatal)
    } else {
      // On Android, throwing the original exception immediately results in the
github born2net / studio-lite / src / services / global-error-handler.ts View on Github external
handleError(error) {
        if (Lib.DevMode()){
            throw error;
        }          

        // const loggingService = this.injector.get(LoggingService);
        // const location = this.injector.get(LocationStrategy);
        // const url = location instanceof PathLocationStrategy   ? location.path() : '';
        var message = error.message ? error.message : error.toString();
        var url = 'https://secure.digitalsignage.com/stacktrace/';

        // get the stack trace, lets grab the last 10 stacks only
        StackTrace.fromError(error).then(stackframes => {
            const stackString = stackframes
                .splice(0, 20)
                .map(function (sf) {
                    return sf.toString();
                }).join('\n');
            var date = moment().format('YYYY-MM-DD h:mm:ss');
            message = `error :: business :: ${window['business_id']} :: studiolite :: ${date} :: ${message}`
            StackTrace.report(stackString, url, message);
        });
        throw error;
    }
github ladjs / lad / template / assets / js / uncaught.js View on Github external
uncaught.addListener(err => {
  // this will transform the error's `stack` property
  // to be consistently similar to Gecko and V8 stackframes
  StackTrace.fromError(err)
    .then(stackframes => {
      err.stack = prepareStackTrace(err, stackframes);
      logger.error(err);
    })
    .catch(err_ => {
      logger.error(err);
      logger.error(err_);
    });
});
github mreuvers / typescript-logging / src / logging / utils / MessageUtils.ts View on Github external
return new Promise((resolve: any) => {

      // This one has a promise too
      ST.fromError(error, {offline: true}).then((frames: ST.StackFrame[]) => {
        const stackStr = (frames.map((frame: ST.StackFrame) => {
          return frame.toString();
        }) ).join("\n  ");

        result += "\n" + stackStr;

        // This resolves our returned promise
        resolve(result);
      }).catch(() => {
        result = "Unexpected error object was passed in. ";
        try {
          result += "Could not resolve it, stringified object: " + JSON.stringify(error);
        }
        catch (e) {
          // Cannot stringify can only tell something was wrong.
          result += "Could not resolve it or stringify it.";
github MeasureOSS / Measure / makedash.js View on Github external
.catch(e => {
        try {
            if (db) db.close();
            if (e.isNiceError) {
                console.error("Problem message:")
                console.error(e.message);
            } else {
                require("stacktrace-js").fromError(e)
                    .then(function(frames) {
                        var lineno = 0, sourcefile = "(an unknown file)";
                        if (frames.length) {
                            lineno = frames[0].lineNumber + ":" + frames[0].columnNumber;
                            sourcefile = path.relative(__dirname, frames[0].fileName);
                        }
                        console.error("\nAn internal error has occurred: " + e.message + ".\n" +
                            "Internal errors are by definition a bug in Measure, and should be reported.\n" +
                            "The error was detected at line " + lineno + " of '" + sourcefile + "'.\n" + 
                            "This should never happen, and I am halting in abject failure.");
                    })
                    .catch(function(ste) {
                        console.error("\nAn internal error has occurred: " + e.message + ".\n" +
                            "Internal errors are by definition a bug in Measure, and should be reported.\n" +
                            "Additionally, while handling that error another error occurred: " + 
                                ste.message + ".\n" +
github invertase / react-native-firebase / packages / crashlytics / lib / index.js View on Github external
recordError(error) {
    if (isError(error)) {
      StackTrace.fromError(error, { offline: true }).then(stackFrames => {
        this.native.recordError(createNativeErrorObj(error, stackFrames, false));
      });
    } else {
      console.warn(
        'firebase.crashlytics().recordError(*) expects an instance of Error. Non Errors will be ignored.',
      );
    }
  }
github TimvanScherpenzeel / spars / components / installRemoteErrorHandler.ts View on Github external
window.addEventListener('error', ({ message, filename, lineno, colno, error }) => {
    StackTrace.fromError(error)
      .then(stacktrace => {
        socket.log('error', message, {
          colno,
          filename,
          lineno,
          stacktrace,
        });
      })
      .catch(() => {
        socket.log('error', message, {
          colno,
          filename,
          lineno,
        });
      });
  });
github sensu / sensu-go / dashboard / src / lib / component / ErrorRoot.js View on Github external
componentDidMount() {
    StackTrace.fromError(this.state).then(frames => {
      this.setState({
        frames: frames
          .map((frame, i) => ({
            ...frame,
            functionName: this.state.frames[i].functionName,
            fileName: frame.fileName.replace(window.location.origin, ""),
          }))
          .map(formatFrame),
      });
    });
  }

stacktrace-js

Framework-agnostic, micro-library for getting stack traces in all environments

MIT
Latest version published 4 years ago

Package Health Score

79 / 100
Full package analysis