{"id":13453892,"url":"https://github.com/watson/stackman","last_synced_at":"2025-05-16T12:09:08.081Z","repository":{"id":19161785,"uuid":"22393506","full_name":"watson/stackman","owner":"watson","description":"He is like Batman, but for Node.js stack traces","archived":false,"fork":false,"pushed_at":"2023-12-03T14:05:27.000Z","size":149,"stargazers_count":252,"open_issues_count":13,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-05T19:06:31.520Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/watson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2014-07-29T19:59:48.000Z","updated_at":"2025-03-06T17:31:35.000Z","dependencies_parsed_at":"2023-12-03T15:22:23.040Z","dependency_job_id":"a964651c-2eb6-41a5-8f20-e3938875476b","html_url":"https://github.com/watson/stackman","commit_stats":{"total_commits":152,"total_committers":2,"mean_commits":76.0,"dds":0.006578947368421018,"last_synced_commit":"8d0381086b2524bb31e7d4145fac1ef5f5e40a73"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson%2Fstackman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson%2Fstackman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson%2Fstackman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson%2Fstackman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/watson","download_url":"https://codeload.github.com/watson/stackman/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527087,"owners_count":22085918,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:00:48.944Z","updated_at":"2025-05-16T12:09:08.047Z","avatar_url":"https://github.com/watson.png","language":"JavaScript","readme":"# Stackman\n\nGive Stackman an error and he will give an array of stack frames with\nextremely detailed information for each frame in the stack trace.\n\nWith Stackman you get access to the actual source code and surrounding\nlines for where the error occurred, you get to know if it happened\ninside a 3rd party module, in Node.js or in your own code. For a full\nlist of information, check out the API below.\n\n[![npm](https://img.shields.io/npm/v/stackman.svg)](https://www.npmjs.com/package/stackman)\n[![Build status](https://travis-ci.org/watson/stackman.svg?branch=master)](https://travis-ci.org/watson/stackman)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)\n[![sponsor](https://img.shields.io/badge/sponsored%20by-Elastic-3360A3.svg)](https://www.elastic.co)\n\n## Install\n\n```\nnpm install stackman\n```\n\n## Basic usage\n\n```javascript\nvar stackman = require('stackman')()\n\nvar err = new Error('Oops!')\n\nstackman.callsites(err, function (err, callsites) {\n  if (err) throw err\n\n  callsites.forEach(function (callsite) {\n    console.log('Error occured in at %s line %d',\n      callsite.getFileName(),\n      callsite.getLineNumber())\n  })\n})\n```\n\n## Gotchas\n\n### `error.stack`\n\nThis module works because V8 (the JavaScript engine behind Node.js)\nallows us to hook into the stack trace generator function before that\nstack trace is generated. It's triggered by accessing the `.stack`\nproperty on the Error object, so please don't do that before parsing the\nerror to stackman, else this will not work!\n\nIf you want to output the regular stack trace, just do so after parsing\nthe callsites:\n\n```javascript\n// first call stackman.callsites with the error\nstackman.callsites(err, function () {...})\n\n// then you can print out the stack trace\nconsole.log(err.stack)\n```\n\n## Stackman API\n\n### `var stackman = Stackman([options])`\n\nThis module exposes a single function which you must call to get a\n`stackman` object.\n\nThe function takes an optional options object as its only argument.\nThese are the available options:\n\n- `fileCacheMax` - When source files are read from disk, they are kept\n  in memory in an LRU cache to speed up processing of future errors. You\n  can change the max number of files kept in the LRU cache using this\n  property (default: 500)\n- `sourceMapCacheMax` - When source maps are read from disk, the\n  processed source maps are kept in memory in an LRU cache to speed up\n  processing of future errors. You can change the max number of source\n  maps kept in the LRU cache using this property (default: 100)\n\n### `stackman.callsites(err[, options], callback)`\n\nGiven an error object, this function will call the `callback` with an\noptional error as the first argument and an array of\n[CallSite](#callsite-api) objects as the 2nd (a call site is a frame in\nthe stack trace).\n\nNote that any error related to loading or parsing source maps will be\nsuppressed. If a source map related error occurs, Stackman behaves as if\nthe `sourcemap` option is `false`.\n\nOptions:\n\n- `sourcemap` - A boolean specifying if Stackman should look for and\n  process source maps (default: `true`)\n\n### `var properties = stackman.properties(err)`\n\nGiven an error object, this function will return an object containing\nall the custom properties from the original error object (beside date\nobjects, properties of type `object` and `function` are not included in\nthis object).\n\n### `stackman.sourceContexts(callsites[, options], callback)`\n\nConvenience function to get the source context for all call sites in the\n`callsites` argument in one go (instead of iterating over the call sites\nand calling\n[`callsite.sourceContext()`](#callsitesourcecontextoptions-callback) for\neach of them).\n\nCalls the `callback` with an optional error object as the first argument\nand an array of [source context objects](#source-context) as the 2nd.\nEach element in the context array matches a call site in the `callsites`\narray.\n\nOptions:\n\n- `lines` - Total number of lines of soruce context to be loaded with\n  the call site line in the center (default: `5`)\n- `inAppLines` - Total number of lines of soruce context to be loaded\n  with the call site line in the center if `callsite.isApp()` is `true`.\n  Overwrites `lines` (default: `5`)\n- `libraryLines` - Number of lines of soruce context to be loaded with\n  the call site line in the center if `callsite.isApp()` is `false`.\n  Overwrites `lines` (default: `5`)\n\nAll node core call sites and call sites where no lines were collected\ndue to the above options being `0`, will have the context value `null`.\n\n## CallSite API\n\nA CallSite object is an object provided by the [V8 stack trace\nAPI](https://github.com/v8/v8/wiki/Stack-Trace-API) representing a frame\nin the stack trace. Stackman will decorate each CallSite object with\ncustom functions and behavior.\n\n### `callsite.sourcemap`\n\nIf source map support is enabled and a source map have been found for\nthe CallSite, this property will be a reference to a\n[`SourceMapConsumer`](https://github.com/mozilla/source-map#sourcemapconsumer)\nobject representing the given CallSite.\n\nIf set, all functions on the CallSite object will be source map aware.\nI.e. their return values will be related to the original source code and\nnot the transpiled source code.\n\n### `var val = callsite.getThis()`\n\n_Inherited from V8_\n\nReturns the value of `this`.\n\nTo maintain restrictions imposed on strict mode functions, frames that\nhave a strict mode function and all frames below (its caller etc.) are\nnot allow to access their receiver and function objects. For those\nframes, `getThis()` will return `undefined`.\n\n### `var str = callsite.getTypeName()`\n\n_Inherited from V8_\n\nReturns the type of `this` as a string. This is the name of the function\nstored in the constructor field of `this`, if available, otherwise the\nobject's `[[Class]]` internal property.\n\n### `var str = callsite.getTypeNameSafely()`\n\nA safer version of\n[`callsite.getTypeName()`](#var-str--callsitegettypename) that safely\nhandles an exception that sometimes is thrown when using `\"use strict\"`\nin which case `null` is returned.\n\n### `var fn = callsite.getFunction()`\n\n_Inherited from V8_\n\nReturns the current function.\n\nTo maintain restrictions imposed on strict mode functions, frames that\nhave a strict mode function and all frames below (its caller etc.) are\nnot allow to access their receiver and function objects. For those\nframes, `getFunction()` will return `undefined`.\n\n### `var str = callsite.getFunctionName()`\n\n_Inherited from V8_\n\nReturns the name of the current function, typically its name property.\nIf a name property is not available an attempt will be made to try to\ninfer a name from the function's context.\n\n### `var str = callsite.getFunctionNameSanitized()`\n\nGuaranteed to always return the most meaningful function name. If none\ncan be determined, the string `\u003canonymous\u003e` will be returned.\n\n### `var str = callsite.getMethodName()`\n\n_Inherited from V8_\n\nReturns the name of the property of this or one of its prototypes that\nholds the current function.\n\n### `var str = callsite.getFileName()`\n\n_Inherited from V8 if `callsite.sourcemap` is `undefined`_\n\nIf this function was defined in a script returns the name of the script.\n\n### `var str = callsite.getRelativeFileName()`\n\nReturns a filename realtive to `process.cwd()`.\n\n### `var num = callsite.getLineNumber()`\n\n_Inherited from V8 if `callsite.sourcemap` is `undefined`_\n\nIf this function was defined in a script returns the current line\nnumber.\n\n### `var num = callsite.getColumnNumber()`\n\n_Inherited from V8 if `callsite.sourcemap` is `undefined`_\n\nIf this function was defined in a script returns the current column\nnumber.\n\n### `var str = callsite.getEvalOrigin()`\n\n_Inherited from V8_\n\nIf this function was created using a call to eval returns a CallSite\nobject representing the location where eval was called.\n\nNote that since Node.js v12.11.0, this function returns `undefined`\nunless `eval` was used.\n\n### `var str = callsite.getModuleName()`\n\nReturns the name of the module if `isModule()` is `true`. Otherwise\nreturns `null`.\n\n### `var bool = callsite.isToplevel()`\n\n_Inherited from V8_\n\nIs this a toplevel invocation, that is, is this the global object?\n\n### `var bool = callsite.isEval()`\n\n_Inherited from V8_\n\nDoes this call take place in code defined by a call to eval?\n\n### `var bool = callsite.isNative()`\n\n_Inherited from V8_\n\nIs this call in native V8 code?\n\n### `var bool = callsite.isConstructor()`\n\n_Inherited from V8_\n\nIs this a constructor call?\n\n### `var bool = callsite.isApp()`\n\nIs this inside the app? (i.e. not native, not node code and not a module\ninside the `node_modules` directory)\n\n### `var bool = callsite.isModule()`\n\nIs this inside the `node_modules` directory?\n\n### `var bool = callsite.isNode()`\n\nIs this inside node core?\n\n### `callsite.sourceContext([lines, ]callback)`\n\nGet the source code surrounding the call site line.\n\nIf the `callsite` is a node core call site, the `callback` will be\ncalled with an error.\n\nArguments:\n\n- `lines` - Total number of lines of soruce context to be loaded with\n  the call site line in the center (default: `5`)\n- `callback` - called when the source context have been loaded with an\n  optional error object as the first argument and a [source context\n  object](#source-context) as the 2nd\n\n## Source Context\n\nThe source context objects provided by\n[`callsite.sourceContext`](#callsitesourcecontextoptions-callback)\ncontains the following properties:\n\n- `pre` - The lines before the main callsite line\n- `line` - The main callsite line\n- `post` - The lines after the main callsite line\n\n## Troubleshooting\n\nTo enable debug mode, set the environment variable `DEBUG=stackman`.\n\n## Acknowledgements\n\nThis project was kindly sponsored by [Elastic](https://www.elastic.co).\n\n## License\n\n[MIT](LICENSE)\n","funding_links":[],"categories":["Packages","Repository","包","目录","Debugging / Profiling","JavaScript"],"sub_categories":["Debugging / Profiling","Debugging","调试 / 分析","调试/分析","调试"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatson%2Fstackman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwatson%2Fstackman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatson%2Fstackman/lists"}