Both requests attempt to use the stack trace. But a stack trace is only
available after i called the message not before. So like in the topic header i
would need the methods file header without a stack trace; without calling
the method at first place.
On Friday, December 14, 2012 6:46:09 PM UTC+9, greelgorke wrote:
>
> taken from console.js in core:
>
> exports.trace = function(label) {
> // TODO probably can to do this better with V8's debug object once that
> is
> // exposed.
> var err = new Error;
> err.name = 'Trace';
> err.message = label || '';
> Error.captureStackTrace(err, arguments.callee);
> console.error(err.stack);
> };
>
> Am Freitag, 14. Dezember 2012 08:06:24 UTC+1 schrieb Jonathan Dickinson:
>>
>> It looks like you can only do it with errors:
>>
>> (new Error()).stack
>>
>> Taking require() as an example (if you were in control of it) you would
>> make require() add the stack trace to the module before any code in the
>> module executes. Now within the context of the B load you find out that it
>> is a cycle back to A, so your require() method would do something like:
>>
>> function require(arg) {
>> var stackInfo = getStackInfo(arg);
>> if (stackInfo) {
>> // We can do this because the 'prologue' of "A" would have populated
>> the stack trace in our internal modules set.
>> throw new CycleError(getStackInfo(arg) + " [" + arg + "] has a cyclic
>> dependency with [" + currentModule + "] " + (new Error()).stack;
>> }
>> }
>>
>> Alternatively you could require that your components advertise their
>> dependencies up-front (similar to package.json). You could then discover
>> cycles (and load order, by the way) before running anything using Tarjan's
>> Strong Connected Components Algorithm:
>> http://en.wikipedia.org/wiki/Tarjan's_strongly_connected_components_algorithm
>> .
>>
>> At the end of the day though getting source information for a function
>> could be an amazing addition for so many development cases, especially
>> providing useful debugging info.
>>
>> On Friday, 14 December 2012 06:23:16 UTC+2, Martin Heidegger wrote:
>>>
>>> Hello everybody,
>>>
>>> I am writing on a system that should detect and resolve dependencies of
>>> code before executing it. So method A references method B so method B needs
>>> to be called before A. So far that works fine, however when I throw a
>>> circular dependency error message all the error message says is "[function]
>>> has a circular dependency to [function]"... thats very few information for
>>> debugging. I want to improve on that by at least displaying the line-number
>>> of the methods. So far I haven't found a way to do that. It should be
>>> possible because the VM should know where a method has been written (else
>>> it could not tell me the location on a stacktrace).
>>>
>>> Have I missed something? Is this worth a feature request?
>>>
>>> yours
>>> Martin.
>>>
>>
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en