@sapphy/ghost
v0.2.1
Published
Function error replay system for debugging - capture errors with inputs and replay them later
Maintainers
Readme
@sapphy/ghost
Function error replay system for debugging - capture errors with inputs and replay them later
Installation
npm install @sapphy/ghost
# or
yarn add @sapphy/ghostQuick Start
import { withGhost, replay, listReplays } from '@sapphy/ghost'
// Wrap your function
const riskyFunction = withGhost('riskyFunction', (x: number, y: string) => {
if (x < 0) throw new Error('Negative number not allowed')
return `${y}: ${x}`
})
// Use it normally
try {
riskyFunction(-1, 'value')
} catch (error) {
console.log('Error captured!')
}
// Later, replay the error
const replays = listReplays()
if (replays.length > 0) {
const result = replay(replays[0].id)
console.log('Replayed error:', result.error?.message)
}API
withGhost(name, fn, options?)
Wraps a function to capture errors with their inputs for later replay.
name: Unique identifier for the functionfn: The function to wrapoptions: Optional configuration
replay(id)
Re-executes a captured error scenario.
listReplays()
Returns all captured error replays.
clearReplays()
Clears all stored replays.
setGhostStorage(storage)
Configures the storage backend.
Storage Options
- MemoryStorage (default): In-memory storage
- FileStorage: Persistent file-based storage
Documentation
Visit our documentation site for detailed guides and API reference.
License
MIT
