Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
capture-stack-trace
Advanced tools
The 'capture-stack-trace' npm package is a utility for capturing stack traces in Node.js. It is particularly useful for debugging and error handling, allowing developers to capture and manipulate stack traces programmatically.
Basic Stack Trace Capture
This feature allows you to capture the current stack trace and assign it to an object. The captured stack trace can then be logged or manipulated as needed.
const captureStackTrace = require('capture-stack-trace');
function myFunction() {
const obj = {};
captureStackTrace(obj);
console.log(obj.stack);
}
myFunction();
Custom Error Stack Trace
This feature allows you to capture a stack trace for a custom error class. By passing the custom error class as the second argument, you can ensure that the stack trace starts from the point where the error was instantiated.
const captureStackTrace = require('capture-stack-trace');
class CustomError extends Error {
constructor(message) {
super(message);
captureStackTrace(this, CustomError);
}
}
try {
throw new CustomError('Something went wrong!');
} catch (error) {
console.log(error.stack);
}
The 'stack-trace' package provides a more comprehensive API for working with stack traces in Node.js. It allows you to parse and manipulate stack traces, and offers more detailed information about each stack frame compared to 'capture-stack-trace'.
The 'error-stack-parser' package is designed to parse and extract information from error stack traces. It is particularly useful for front-end applications where you need to handle and display error information in a user-friendly manner. Unlike 'capture-stack-trace', it focuses on parsing existing stack traces rather than capturing them.
The 'traceback' package provides utilities for capturing and formatting stack traces in a more readable format. It offers additional features like filtering and formatting stack traces, making it a more feature-rich alternative to 'capture-stack-trace'.
This is useful for creating cross-platform code as Error#captureStackTrace
is only available in V8-based JavaScript environments like Node.js and Chrome.
npm install capture-stack-trace
import captureStackTrace from 'capture-stack-trace';
const object = {};
captureStackTrace(object);
object.stack; // Similar to `new Error().stack`
Creates a .stack
property on the given object
, which when accessed returns a string representing the location in the code at which captureStackTrace()
was called.
Note: This ponyfill does not support the second parameter of Error#captureStackTrace
.
FAQs
Error.captureStackTrace ponyfill
The npm package capture-stack-trace receives a total of 1,730,471 weekly downloads. As such, capture-stack-trace popularity was classified as popular.
We found that capture-stack-trace demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.