backtrace-node
Advanced tools
Comparing version 1.0.3 to 1.0.4
# Backtrace Node Release Notes | ||
## Version 1.0.4 26.08.2019 | ||
* Added attachments checks, | ||
* Added callback funciton to third parameter of send method, | ||
* Removed Backtrace stack frames from message error, | ||
## Version 1.0.3 06.06.2019 | ||
@@ -4,0 +9,0 @@ * Added new events to event emitter: `new-report`, `unhandledRejection`, `uncaughtException`. `uncaughtException` and `unhandledRejection` events will be emited by library when library catch unhandled exception or unhandler promise rejection. `new-report` event will be emited when library create new `backtraceReport` object. |
@@ -114,3 +114,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var formData, json; | ||
var formData, json, attachments; | ||
return __generator(this, function (_a) { | ||
@@ -120,10 +120,13 @@ formData = new form_data_1.default(); | ||
formData.append('upload_file', json, 'upload_file.json'); | ||
report.getAttachments().forEach(function (filePath) { | ||
var result = fs.existsSync(filePath); | ||
if (!result) { | ||
return; | ||
} | ||
var name = path.basename(filePath); | ||
formData.append("attachment_" + name, fs.createReadStream(filePath), name); | ||
}); | ||
attachments = report.getAttachments(); | ||
if (attachments instanceof Array) { | ||
attachments.forEach(function (filePath) { | ||
var result = fs.existsSync(filePath); | ||
if (!result) { | ||
return; | ||
} | ||
var name = path.basename(filePath); | ||
formData.append("attachment_" + name, fs.createReadStream(filePath), name); | ||
}); | ||
} | ||
return [2 /*return*/, formData]; | ||
@@ -130,0 +133,0 @@ }); |
@@ -25,3 +25,3 @@ import { BacktraceClient } from './backtraceClient'; | ||
*/ | ||
export declare function report(arg: () => void | Error | string | object, arg2?: object | undefined, arg3?: string[]): Promise<BacktraceResult>; | ||
export declare function report(arg: () => void | Error | string | object, arg2?: object | undefined, arg3?: string[] | ((data?: Error) => void), arg4?: string[]): Promise<BacktraceResult>; | ||
/** | ||
@@ -28,0 +28,0 @@ * Send report synchronosuly to Backtrace |
@@ -83,7 +83,10 @@ "use strict"; | ||
*/ | ||
function report(arg, arg2, arg3) { | ||
function report(arg, arg2, | ||
// tslint:disable-next-line: ban-types | ||
arg3, arg4) { | ||
if (arg2 === void 0) { arg2 = {}; } | ||
if (arg3 === void 0) { arg3 = []; } | ||
if (arg4 === void 0) { arg4 = []; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var data, result; | ||
var data, attachments, callback, result; | ||
return __generator(this, function (_a) { | ||
@@ -102,7 +105,9 @@ switch (_a.label) { | ||
} | ||
return [4 /*yield*/, backtraceClient.reportAsync(data, arg2, arg3)]; | ||
attachments = arg3 instanceof Function ? arg4 : arg3; | ||
callback = arg instanceof Function ? arg : arg3; | ||
return [4 /*yield*/, backtraceClient.reportAsync(data, arg2, attachments)]; | ||
case 1: | ||
result = _a.sent(); | ||
if (arg instanceof Function) { | ||
arg(); | ||
if (callback && callback instanceof Function) { | ||
callback(result.Error); | ||
} | ||
@@ -109,0 +114,0 @@ return [2 /*return*/, result]; |
@@ -7,3 +7,3 @@ import { IBacktraceData } from './backtraceData'; | ||
export declare class BacktraceReport { | ||
private err; | ||
private data; | ||
private clientAttributes; | ||
@@ -25,3 +25,3 @@ private attachments; | ||
*/ | ||
send: (callback: (err?: Error) => void) => void | undefined; | ||
send?: (callback: (err?: Error) => void) => void; | ||
/** | ||
@@ -33,3 +33,3 @@ * @deprecated | ||
*/ | ||
sendSync: (callback: (err?: Error) => void) => void | undefined; | ||
sendSync?: (callback: (err?: Error) => void) => void; | ||
/** | ||
@@ -54,2 +54,3 @@ * Thread information about current application | ||
private contextLineCount; | ||
private err; | ||
/** | ||
@@ -67,3 +68,3 @@ * Create new BacktraceReport - report information that will collect information | ||
*/ | ||
constructor(err?: Error | string, clientAttributes?: { | ||
constructor(data?: Error | string, clientAttributes?: { | ||
[index: string]: any; | ||
@@ -70,0 +71,0 @@ }, attachments?: string[]); |
@@ -80,7 +80,7 @@ "use strict"; | ||
*/ | ||
function BacktraceReport(err, clientAttributes, attachments) { | ||
if (err === void 0) { err = ''; } | ||
function BacktraceReport(data, clientAttributes, attachments) { | ||
if (data === void 0) { data = ''; } | ||
if (clientAttributes === void 0) { clientAttributes = {}; } | ||
if (attachments === void 0) { attachments = []; } | ||
this.err = err; | ||
this.data = data; | ||
this.clientAttributes = clientAttributes; | ||
@@ -120,3 +120,3 @@ this.attachments = attachments; | ||
} | ||
this.setError(err); | ||
this.setError(data); | ||
} | ||
@@ -127,6 +127,6 @@ /** | ||
BacktraceReport.prototype.isExceptionTypeReport = function () { | ||
return this.detectReportType(this.err); | ||
return this.detectReportType(this.data); | ||
}; | ||
BacktraceReport.prototype.getPayload = function () { | ||
return this.err; | ||
return this.data; | ||
}; | ||
@@ -138,4 +138,11 @@ /** | ||
BacktraceReport.prototype.setError = function (err) { | ||
this.err = err; | ||
this.classifiers = this.detectReportType(err) ? [err.name] : []; | ||
this.data = err; | ||
if (this.detectReportType(err)) { | ||
this.err = err; | ||
this.classifiers = [err.name]; | ||
} | ||
else { | ||
this.err = new Error(err); | ||
this.classifiers = []; | ||
} | ||
}; | ||
@@ -142,0 +149,0 @@ /** |
@@ -17,2 +17,3 @@ import { ISourceCode } from './sourceCode'; | ||
export declare class BacktraceStackTrace { | ||
private readonly error; | ||
readonly fault: boolean; | ||
@@ -29,4 +30,3 @@ readonly name = "main"; | ||
private contextLineCount; | ||
private error; | ||
constructor(err: Error | string); | ||
constructor(error: Error); | ||
setSourceCodeOptions(tabWidth: number, contextLineCount: number): void; | ||
@@ -33,0 +33,0 @@ /** |
@@ -46,2 +46,3 @@ "use strict"; | ||
var fs = __importStar(require("fs")); | ||
var path_1 = require("path"); | ||
var source_scan_1 = require("source-scan"); | ||
@@ -53,3 +54,4 @@ /** | ||
var BacktraceStackTrace = /** @class */ (function () { | ||
function BacktraceStackTrace(err) { | ||
function BacktraceStackTrace(error) { | ||
this.error = error; | ||
this.fault = true; | ||
@@ -64,7 +66,2 @@ this.name = 'main'; | ||
this.contextLineCount = 200; | ||
// handle reports with message | ||
if (!(err instanceof Error)) { | ||
err = new Error(); | ||
} | ||
this.error = err; | ||
} | ||
@@ -109,3 +106,3 @@ BacktraceStackTrace.prototype.setSourceCodeOptions = function (tabWidth, contextLineCount) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var stackTrace, lines; | ||
var stackTrace, lines, backtracePath; | ||
var _this = this; | ||
@@ -120,2 +117,3 @@ return __generator(this, function (_a) { | ||
lines = stackTrace.split('\n').slice(1); | ||
backtracePath = path_1.join('node_modules', 'backtrace-node'); | ||
lines.forEach(function (line) { | ||
@@ -126,3 +124,3 @@ var match = line.match(_this.stackLineRe); | ||
} | ||
var backtraceLibStackFrame = match[2].indexOf('node_modules/backtrace-node') !== -1; | ||
var backtraceLibStackFrame = match[2].indexOf(backtracePath) !== -1; | ||
if (backtraceLibStackFrame) { | ||
@@ -129,0 +127,0 @@ return; |
{ | ||
"name": "backtrace-node", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Backtrace error reporting tool", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -0,0 +0,0 @@ # backtrace-node |
@@ -41,14 +41,15 @@ import axios from 'axios'; | ||
formData.append('upload_file', json, 'upload_file.json'); | ||
report.getAttachments().forEach((filePath) => { | ||
const result = fs.existsSync(filePath); | ||
if (!result) { | ||
return; | ||
} | ||
const name = path.basename(filePath); | ||
formData.append(`attachment_${name}`, fs.createReadStream(filePath), name); | ||
}); | ||
const attachments = report.getAttachments(); | ||
if (attachments instanceof Array) { | ||
attachments.forEach((filePath) => { | ||
const result = fs.existsSync(filePath); | ||
if (!result) { | ||
return; | ||
} | ||
const name = path.basename(filePath); | ||
formData.append(`attachment_${name}`, fs.createReadStream(filePath), name); | ||
}); | ||
} | ||
return formData; | ||
} | ||
} |
@@ -0,0 +0,0 @@ import { ClientRateLimit } from './clientRateLimit'; |
@@ -0,0 +0,0 @@ import { BacktraceReport } from './model/backtraceReport'; |
@@ -0,0 +0,0 @@ import * as fs from 'fs'; |
@@ -0,0 +0,0 @@ import * as fs from 'fs'; |
@@ -40,3 +40,5 @@ import { BacktraceClient } from './backtraceClient'; | ||
arg2: object | undefined = {}, | ||
arg3: string[] = [], | ||
// tslint:disable-next-line: ban-types | ||
arg3: string[] | ((data?: Error) => void) = [], | ||
arg4: string[] = [], | ||
): Promise<BacktraceResult> { | ||
@@ -53,5 +55,7 @@ if (!backtraceClient) { | ||
} | ||
const result = await backtraceClient.reportAsync(data, arg2, arg3); | ||
if (arg instanceof Function) { | ||
arg(); | ||
const attachments = arg3 instanceof Function ? arg4 : arg3; | ||
const callback = arg instanceof Function ? arg : arg3; | ||
const result = await backtraceClient.reportAsync(data, arg2, attachments); | ||
if (callback && callback instanceof Function) { | ||
callback(result.Error); | ||
} | ||
@@ -93,3 +97,3 @@ return result; | ||
const backtraceReport = backtraceClient.createReport(''); | ||
backtraceReport.send = (callback: (err?: Error) => void) => { | ||
backtraceReport.send = (callback: (err?: Error) => void) => { | ||
backtraceClient.sendReport(backtraceReport, callback); | ||
@@ -96,0 +100,0 @@ }; |
@@ -0,0 +0,0 @@ export class BacktraceClientOptions implements IBacktraceClientOptions { |
@@ -0,0 +0,0 @@ import { ISourceCode } from './sourceCode'; |
@@ -9,3 +9,2 @@ // tslint:disable-next-line: no-var-requires | ||
import { IBacktraceData } from './backtraceData'; | ||
import { BacktraceResult } from './backtraceResult'; | ||
import { BacktraceStackTrace } from './backtraceStackTrace'; | ||
@@ -40,3 +39,3 @@ | ||
*/ | ||
public send!: (callback: (err?: Error) => void) => void | undefined; | ||
public send?: (callback: (err?: Error) => void) => void; | ||
@@ -49,3 +48,3 @@ /** | ||
*/ | ||
public sendSync!: (callback: (err?: Error) => void) => void | undefined; | ||
public sendSync?: (callback: (err?: Error) => void) => void; | ||
@@ -77,2 +76,3 @@ /** | ||
private err!: Error; | ||
/** | ||
@@ -91,3 +91,3 @@ * Create new BacktraceReport - report information that will collect information | ||
constructor( | ||
private err: Error | string = '', | ||
private data: Error | string = '', | ||
private clientAttributes: { [index: string]: any } = {}, | ||
@@ -103,3 +103,3 @@ private attachments: string[] = [], | ||
} | ||
this.setError(err); | ||
this.setError(data); | ||
} | ||
@@ -110,7 +110,7 @@ /** | ||
public isExceptionTypeReport(): boolean { | ||
return this.detectReportType(this.err); | ||
return this.detectReportType(this.data); | ||
} | ||
public getPayload(): Error | string { | ||
return this.err; | ||
return this.data; | ||
} | ||
@@ -122,4 +122,10 @@ /** | ||
public setError(err: Error | string): void { | ||
this.err = err; | ||
this.classifiers = this.detectReportType(err) ? [err.name] : []; | ||
this.data = err; | ||
if (this.detectReportType(err)) { | ||
this.err = err; | ||
this.classifiers = [err.name]; | ||
} else { | ||
this.err = new Error(err); | ||
this.classifiers = []; | ||
} | ||
} | ||
@@ -196,3 +202,3 @@ | ||
// get stack trace to retrieve calling module information | ||
this.stackTrace = new BacktraceStackTrace(this.err); | ||
this.stackTrace = new BacktraceStackTrace(this.err as Error); | ||
this.stackTrace.setSourceCodeOptions(this.tabWidth, this.contextLineCount); | ||
@@ -199,0 +205,0 @@ await this.stackTrace.parseStackFrames(); |
@@ -0,0 +0,0 @@ import { BacktraceReport } from './backtraceReport'; |
import * as fs from 'fs'; | ||
import { join } from 'path'; | ||
import { scanFile } from 'source-scan'; | ||
@@ -33,10 +34,3 @@ import { ISourceCode, ISourceLocation, ISourceScan } from './sourceCode'; | ||
private error: Error; | ||
constructor(err: Error | string) { | ||
// handle reports with message | ||
if (!(err instanceof Error)) { | ||
err = new Error(); | ||
} | ||
this.error = err; | ||
} | ||
constructor(private readonly error: Error) {} | ||
@@ -90,2 +84,3 @@ public setSourceCodeOptions(tabWidth: number, contextLineCount: number) { | ||
const lines = stackTrace.split('\n').slice(1); | ||
const backtracePath = join('node_modules', 'backtrace-node'); | ||
lines.forEach((line) => { | ||
@@ -96,3 +91,3 @@ const match = line.match(this.stackLineRe); | ||
} | ||
const backtraceLibStackFrame = match[2].indexOf('node_modules/backtrace-node') !== -1; | ||
const backtraceLibStackFrame = match[2].indexOf(backtracePath) !== -1; | ||
if (backtraceLibStackFrame) { | ||
@@ -99,0 +94,0 @@ return; |
@@ -0,0 +0,0 @@ export interface ISourceCode { |
@@ -0,0 +0,0 @@ declare module 'source-scan' { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164969
56
3087
9