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.
github.com/batchatco/go-thrower
Package go-thrower implements a simple throw/catch exception wrapper around panic. It catches its own panics, but lets the others through.
RecoverError catches a thrown error. The pointer passed in can be nil
if you
don't care what the thrown error was.
Use it as follows:
func doSomething() (err error) {
// This will catch thrown errors and set the return value to the thrown error.
defer thrower.RecoverError(&err)
// Do some things that might call thrower.Throw() eventually.
// For example:
r := somethingThatCanReturnError()
thrower.ThrowIfError(r) // If not nil, 'r' becomes the function's return value
}
For functions that don't return an error, you can wrap the code in another function to retrieve the error and do something useful with it:
func returnsNoError() {
// This will catch thrown errors and set the return value to the thrown error.
getErr := func() (err error) {
defer thrower.RecoverError(&err)
// Do some things that might call thrower.Throw() eventually.
// For example:
r := somethingThatCanReturnError()
thrower.ThrowIfError(r) // If not nil, 'r' becomes the function's return value
return nil
}
err := getErr()
if err != nil {
fmt.Println("We got an error", err)
}
}
SetCatching sets whether or not thrown errors get caught and returns the previous value. Passing in DontCatch will prevent thrown errors from being caught. They will become just regular panics. Do not use this in production code; it is for debugging only. It is against Go style to let panics cross API boundaries. All thrown errors should be caught by RecoverError normally.
Throw throws the given error, which should be caught by RecoverError normally.
ThrowIfError throws an error only if err
is not nil
.
FAQs
Unknown package
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.