stacktracejs / stackframe Goto Github PK
View Code? Open in Web Editor NEWJS Object representation of a stack frame.
Home Page: https://www.stacktracejs.com/#!/docs/stackframe
License: MIT License
JS Object representation of a stack frame.
Home Page: https://www.stacktracejs.com/#!/docs/stackframe
License: MIT License
I am just wondering what might be the reason of choosing Unlicense, in favour for example of MIT?
MIT would be clearer in the lawyers eyes, and even if the license would need to be changed later in to something else, the versions published with MIT are still valid as MIT.
This would not seem to be the case with Unlicense.
Right now output from toString()
on a stackframe looks like this:
setTimeout(function()@http://localhost:3000/js/core.js:16:9
Which doesn't match normal output from err.stack
prop, e.g. https://github.com/nodejs/node/blob/6ce87c027dc2a16e1b8d85c753b52270ae0c6054/lib/internal/errors.js#L43 (has "at ...")
It would be nice to have a method where we can convert an Array of stackframes to match Node's err.stack
.
npm ERR! code ETARGET
npm ERR! notarget No matching version found for stackframe@^1.3.0
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'error-stack-parser'
npm ERR! notarget
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-06-06T02_19_46_421Z-debug.log
Build step 'Execute shell' marked build as failure
Finished: FAILURE
npm install fails with when trying to install cucumber js with is dependent on this package
npm ERR! code ETARGET
npm ERR! notarget No matching version found for stackframe@^1.1.1
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'stack-generator'
npm ERR! notarget
The toString()
method is documented as outputting funcName(args)@fileName:lineNo:colNo
. This should be the preferred format IMO.
Code and output use funcName (fileName:lineNo:colNo)
, and args
are not even used in the method.
Implement the method to match the documentation.
When passing a StackFrame from my client to my server I json stringify it.
So from the server I'll like to be able to recreate the StackFrame just by assigning the object received.
{
functionName: "WuiDom.eval",
fileName: "src/views/LoginScreen/index.js",
lineNumber: 233,
columnNumber: 17,
source: " at WuiDom.eval (src/views/LoginScreen/index.js:233:17)"
}
I install with bower install stacktrace-js
When running app. in the console I get
ReferenceError: exports is not defined source-map.js:6:1
Hello!
I started using stacktracejs on OpenProcessing, and realized that in cases where error is a simple error without error.stack (e.g. a syntax error), stacktracejs returns an empty trace array, although the exception itself actually includes the filename, linenumber, charnumber.
window.onerror = function (msg, url, lineNumber, columnNo, error) { //no error.trace, but stacktrace can use msg, url, lineNumber, columnNo to create a single element array. StackTrace.fromError(error) .then(function(stackArray){ //stackArray is empty }) .catch(function (err) { //doesnt come here either }); } }
proposed solution
if error.stack is not accessible, stacktrace can still return a single item array using msg, url, lineNumber, columnNo provided.
What do you think?
It is not a good practice to indicate a property type in it's name. If you want to specify it, JSDOC is much better place to do it.
I have been using stacktrace recently in conjunction with source-map from Mozilla and I had to remap stackframe objects to fit
{
line: 2,
column: 28
}
because that is a kind of object that they expect. I think it would make sense to unify the naming conventions in Mozilla's favour. What do you think @oliversalzburg ?
Can we have fromString like API which will be convert stackframe's string ex. Object.componentWillMount()@http://localhost:8080/design.bundle.js:3038:11 to Stackframe object.
I was trying to find stackframe
and error-stack-parser
on a CDN somewhere, I found stacktrace
on cdnjs
but not the others. Have I missed them somewhere?
Error log:
Building for production...
ERROR TypeError: StackFrame is not a constructor
TypeError: StackFrame is not a constructor
Version number: 1.3.4
Can we have few aliases? column
, line
(without Number
suffix) and filename
(lowercased N
)
Want a PR?
It would be useful for people to have the raw traceline in cases where the stack trace parser can't parse a line, or in cases that would be otherwise ambiguous (e.g. a line from "(native)" code vs something else that doesn't have a concrete location).
StackFrame constructor doesn't accept object with null prototype:
> const StackFrame = require('stackframe');
undefined
> new StackFrame({fileName:'lol'})
{ fileName: 'lol' }
> new StackFrame(Object.assign(Object.create(null),{fileName:'lol'}))
{}
> new StackFrame('lol'.match(/(?<fileName>\w+)/).groups)
{}
$ npm ls stackframe
├── [email protected]
└─┬ [email protected]
└── [email protected] deduped
npm error
StackFrame is not a constructor
We can check if we're outside strict-mode and try to get the arity of the arguments
to provide a backward-compatible constructor. This is spiked in 2654cdb
As you transitioned to using object as the single parameter upon creation, 'error-stack-parser' now always create empty 'StackFrame' objects. It happens because parser still passes all the parameters as arguments to the StackFrame constructor. Seems like event last versions of parser are vulnerable to this issue.
For now, I patched my local StackFrame constructor like that:
if (functionName instanceof Object) {
var obj = functionName;
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps)));
for (var i = 0; i < props.length; i++) {
if (obj.hasOwnProperty(props[i]) && obj[props[i]] !== undefined) {
this['set' + _capitalize(props[i])](obj[props[i]]);
}
}
} else {
if (functionName !== undefined) {
this.setFunctionName(functionName);
}
if (args !== undefined) {
this.setArgs(args);
}
if (fileName !== undefined) {
this.setFileName(fileName);
}
if (lineNumber !== undefined) {
this.setLineNumber(lineNumber);
}
if (columnNumber !== undefined) {
this.setColumnNumber(columnNumber);
}
if (source !== undefined) {
this.setSource(source);
}
}
It's a dirty hack, but it works. Please, fix all other parts as currently it is not functional.
npm version 5.6.0
npm ERR! code ETARGET
npm ERR! notarget No matching version found for stackframe@^1.3.0
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'error-stack-parser'
Given an error stack like this one:
ReferenceError: a is not defined
at $$.onStart (eval at <anonymous> (http://localhost:8080/hg/html/js/homegenie.webapp.js?version=r525:6851:25), <anonymous>:32:7)
at $$.RenderWidget (http://localhost:8080/hg/html/js/homegenie.webapp.js?version=r525:6770:36)
at $$.RenderView (http://localhost:8080/hg/html/js/homegenie.webapp.js?version=r525:6757:12)
at http://localhost:8080/hg/html/js/homegenie.webapp.js?version=r525:6879:24
at Object.$.ajax.success (http://localhost:8080/hg/html/js/homegenie.api.js?version=r525:724:21)
at l (http://localhost:8080/hg/html/js/jquery-2.0.2.min.js:3:24881)
at Object.c.fireWith [as resolveWith] (http://localhost:8080/hg/html/js/jquery-2.0.2.min.js:3:25702)
at k (http://localhost:8080/hg/html/js/jquery-2.0.2.min.js:5:4919)
at XMLHttpRequest.<anonymous> (http://localhost:8080/hg/html/js/jquery-2.0.2.min.js:5:8723)
stackframe will currently ignore the eval <anonymous>:32:7
at the end of the first stack element, which is the real source of the error at line 32, column 7.
It will indeed report stack[0] with line 6851 and column 25.
Could we modify toString
so that it closely matches https://v8.dev/docs/stack-trace-api#appendix%3A-stack-trace-format instead of current format?
Calling Error.prepareStackTrace(err, stackframes)
does not give proper output.
ERROR TypeError: StackFrame is not a constructor
TypeError: StackFrame is not a constructor
at Object. (/home/work/jenkins/workspace/FX-BE_fenxi-analysis-front/node_modules/error-stack-parser/error-stack-parser.js:76:24)
at Array.map ()
at Object.ErrorStackParser$$parseV8OrIE [as parseV8OrIE] (/home/work/jenkins/workspace/FX-BE_fenxi-analysis-front/node_modules/error-stack-parser/error-stack-parser.js:56:29)
at Object.ErrorStackParser$$parse [as parse] (/home/work/jenkins/workspace/FX-BE_fenxi-analysis-front/node_modules/error-stack-parser/error-stack-parser.js:31:29)
at getOriginalErrorStack (/home/work/jenkins/workspace/FX-BE_fenxi-analysis-front/node_modules/@soda/friendly-errors-webpack-plugin/src/core/extractWebpackError.js:31:29)
at extractError (/home/work/jenkins/workspace/FX-BE_fenxi-analysis-front/node_modules/@soda/friendly-errors-webpack-plugin/src/core/extractWebpackError.js:22:20)
at Array.map ()
at processErrors (/home/work/jenkins/workspace/FX-BE_fenxi-analysis-front/node_modules/@soda/friendly-errors-webpack-plugin/src/core/transformErrors.js:31:17)
at FriendlyErrorsWebpackPlugin.displayErrors (/home/work/jenkins/workspace/FX-BE_fenxi-analysis-front/node_modules/@soda/friendly-errors-webpack-plugin/src/friendly-errors-plugin.js:97:29)
at doneFn (/home/work/jenkins/workspace/FX-BE_fenxi-analysis-front/node_modules/@soda/friendly-errors-webpack-plugin/src/friendly-errors-plugin.js:57:14)
When using np to publish this package, you can't because dist
folder is not in the .gitignore
file.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: dist/stackframe.js
modified: dist/stackframe.min.js
modified: dist/stackframe.min.js.map
Hi! We are using this library as a dependency of redbox-react via error-stack-parser, and I noticed there’s a kind of Chome Error object that causes it to crash.
I started filing this in https://github.com/stacktracejs/stacktrace.js by mistake so here goes a nice template 😄 .
Given an error object with the following stack as reported by error.stack.toString()
:
ReferenceError: chilxdren is not defined
at new Layout (webpack:///./src/Layout.js?:25:5)
at eval (webpack:///../react-hot-loader/~/react-proxy/modules/createClassProxy.js?:90:24)
at instantiate (webpack:///../react-hot-loader/~/react-proxy/modules/createClassProxy.js?:98:9)
at Layout (eval at proxyClass (webpack:///../react-hot-loader/~/react-proxy/modules/createClassProxy.js?), <anonymous>:4:17)
at ReactCompositeComponentMixin.mountComponent (webpack:///./~/react/lib/ReactCompositeComponent.js?:170:18)
at wrapper [as mountComponent] (webpack:///./~/react/lib/ReactPerf.js?:66:21)
at Object.ReactReconciler.mountComponent (webpack:///./~/react/lib/ReactReconciler.js?:39:35)
at ReactCompositeComponentMixin.performInitialMount (webpack:///./~/react/lib/ReactCompositeComponent.js?:289:34)
at ReactCompositeComponentMixin.mountComponent (webpack:///./~/react/lib/ReactCompositeComponent.js?:237:21)
at wrapper [as mountComponent] (webpack:///./~/react/lib/ReactPerf.js?:66:21)
It should parse all lines correctly and should not crash.
It crashes with TypeError: Line Number must be a Number
while handling this particular line:
at Layout (eval at proxyClass (webpack:///../react-hot-loader/~/react-proxy/modules/createClassProxy.js?), <anonymous>:4:17)
As you can see, it has multiple entries separated by comma—presumably because the error was caught and rethrown, although I haven’t looked at why closely. The first item doesn’t have the line number info for some reason, but stacktrace.js
assumes that it is always there. This makes it parse the location info incorrectly and throw later:
This is a very tricky one because I’m debugging a dev version of the project which involves compiling several libraries. If you trust me I’m not making this up, you can parse the stack string I documented above to reproduce the issue. 😄
I noticed this working on React Hot Loader 3 that will rely on error boundaries in React to handle errors as you edit the code, fix them without reloading the app.
I noticed that in some cases the error box failed to appear, and tracked it down to this dependency.
Be more resilient to parsing errors and check the line number for being a number during parsing, use 0
otherwise.
This functionality isn't reflected on the website or the README. It needs to be added.
No need to anything fancy with arguments at this point.
Updates are very fast. ERROR TypeError: StackFrame is not a constructor
was reported two hours ago. The version is 1.3.1, now 1.3.4 is no problem, it took me a lot of time to troubleshoot errors
😂😂
TypeError: StackFrame is not a constructor
For the StackFrame object, I would expect a very simple way to get and set properties:
stackframe.filename
to read the propertystackframe.filename = "myfile.js"
That should be the API regardless of whether or not it is implemented as a getter/setter pair. If there is extra work to do for either, then a getter/setter pair should be used with a hidden property like stackframe._filename
, which the user should not be instructed to access directly.
The current API is confusing and does not make use of actual JS getters and setters. For example:
Furthermore, the typings for the set methods have zero parameters defined.
A StackFrame can actually have a file location and a location within an eval()
call.
For example, this stack:
Error: message string
at baz (eval at foo (eval at speak (http://localhost:8000/test/functional/testeval.html:26:22)), <anonymous>:1:30)
at foo (eval at speak (http://localhost:8000/test/functional/testeval.html:26:22), <anonymous>:2:96)
at eval (eval at speak (http://localhost:8000/test/functional/testeval.html:26:22), <anonymous>:4:18)
at Object.speak (http://localhost:8000/test/functional/testeval.html:26:17)
at http://localhost:8000/test/functional/testeval.html:33:13
Notice the locations within the eval'd code, represented by , <anonymous>:2:96)
. We may want to represent this using a parent/child relationship.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.