From 433ed3d130befb6f11aa0a172684c98eb1921931 Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Tue, 12 May 2015 11:45:03 -0500 Subject: [PATCH] Added stack trace.js and node stack trace definitions --- node-stack-trace/node-stack-trace.d.ts | 20 ++++++++ node-stack-trace/node-stack-trace.ts | 8 ++++ stacktrace/stacktrace.d.ts | 64 ++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 node-stack-trace/node-stack-trace.d.ts create mode 100644 node-stack-trace/node-stack-trace.ts create mode 100644 stacktrace/stacktrace.d.ts diff --git a/node-stack-trace/node-stack-trace.d.ts b/node-stack-trace/node-stack-trace.d.ts new file mode 100644 index 000000000..c3684b3db --- /dev/null +++ b/node-stack-trace/node-stack-trace.d.ts @@ -0,0 +1,20 @@ +// Type definitions for node-stack-trace +// Project: https://github.com/felixge/node-stack-trace +// Definitions by: [Exceptionless] +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module 'stack-trace' { + export interface StackFrame { + getTypeName():string; + getFunctionName():string; + getMethodName():string; + getFileName():string; + getTypeName():string; + getLineNumber():number; + getColumnNumber():number; + isNative():boolean; + } + + export function get(belowFn:() => void): StackFrame[]; + export function parse(err:Error): StackFrame[]; +} diff --git a/node-stack-trace/node-stack-trace.ts b/node-stack-trace/node-stack-trace.ts new file mode 100644 index 000000000..a0b2f8d55 --- /dev/null +++ b/node-stack-trace/node-stack-trace.ts @@ -0,0 +1,8 @@ +import stackTrace = require('stack-trace'); + +var currentStackTrace = stackTrace.get(); + +var err = new Error('something went wrong'); +var trace = stackTrace.parse(err); + +var fileName = trace[0].getFileName(); diff --git a/stacktrace/stacktrace.d.ts b/stacktrace/stacktrace.d.ts new file mode 100644 index 000000000..a23216a95 --- /dev/null +++ b/stacktrace/stacktrace.d.ts @@ -0,0 +1,64 @@ +// Type definitions for stacktrace.js +// Project: https://github.com/stacktracejs/stacktrace.js +// Definitions by: [Exceptionless] +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module StackTrace { + export interface StackTraceOptions { + filter?: (stackFrame:StackFrame) => boolean; + sourceCache?: { URL:string }; + offline?: boolean; + } + + export interface StackFrame { + constructor(functionName:string, args:any, fileName:string, lineNumber:number, columnNumber:number); + + functionName?:string; + args?:any; + fileName?:string; + lineNumber?:number; + columnNumber?:number; + toString():string; + } + + /** + * Get a backtrace from invocation point. + * @param options Options Object + * @return Array[StackFrame] + */ + export function get(options: StackTraceOptions): Promise; + + /** + * Given an error object, parse it. + * @param error Error object + * @param options Object for options + * @return Array[StackFrame] + */ + export function fromError(error:Error, options?:StackTraceOptions): Promise; + + /** + * Use StackGenerator to generate a backtrace. + * @param options Object options + * @returns Array[StackFrame] + */ + export function generateArtificially(options: StackTraceOptions): Promise; + + /** + * Given a function, wrap it such that invocations trigger a callback that + * is called with a stack trace. + * + * @param {Function} fn to be instrumented + * @param {Function} callback function to call with a stack trace on invocation + * @param {Function} errorCallback optional function to call with error if unable to get stack trace. + * @param {Object} thisArg optional context object (e.g. window) + */ + export function instrument(fn:() => void, callback:(stackFrames:StackFrame[]) => void, errorCallback:() => void, thisArg:any): void; + + /** + * Given a function that has been instrumented, + * revert the function to it's original (non-instrumented) state. + * + * @param fn {Function} + */ + export function deinstrument(fn:() => void): void; +}