npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ti-longjohn

v0.0.5

Published

Longjohn rewrite for Titanium

Downloads

11

Readme

ti-longjohn Appcelerator Titanium

Long stack traces for Titanium with configurable call trace length.

This module is a port and partially rewrite of the Node.js longjohn for the Titanium platform.

In addition it has special support to patch async.js's queue.

Requirements

Supports

  • iOS simulator and device
  • Android is untested, probably will not work because Titanium's Android support is based on V8, not JavaScriptCore.

Installation

Download the latest release via git from github:

git clone https://github.com/sttts/ti-longjohn.git

or use gittio:

gittio install ti-longjohn

or use npm:

npm install ti-longjohn

Usage

To use ti-longjohn, require it in your code (probably in some initialization code). That's all!

if (Ti.App.deployType !== 'production') {
  var longjohn = require('longjohn')(global);
}

// ... your code

where global is the global namespace. If you require ti-longjohn from the app.js file, pass this as the global parameter.

Output

When an exception is thrown, ti-longjohn will try to construct a long stack trace which can consist of multiple usual stack traces which are seperated by asyncronous callbacks, e.g. by setTimeout.

The output looks like this:

"TypeError at node_modules/nedb/lib/model.js:31",
"#0 () at node_modules/nedb/lib/datastore.js:296",
"#1 () at node_modules/nedb/lib/datastore.js:528",
"#2 () at node_modules/nedb/lib/cursor.js:174",
"#3 () at node_modules/nedb/lib/datastore.js:530",
"#4 () at node_modules/nedb/node_modules/async/lib/async.js:582",
"#5 () at node_modules/nedb/node_modules/async/lib/async.js:498",
"#8 () at node_modules/process/index.js:14",
"-------- process.nextTick ---------",
"#2 () at node_modules/nedb/node_modules/async/lib/async.js:499",
"#3 () at node_modules/nedb/node_modules/async/lib/async.js:503",
"#4 () at node_modules/nedb/lib/datastore.js:564",
"#5 () at node_modules/nedb/lib/executor.js:40",
"#8 () at node_modules/nedb/node_modules/async/lib/async.js:731",
"#9 () at node_modules/nedb/node_modules/async/lib/async.js:728",
"#10 () at node_modules/nedb/node_modules/async/lib/async.js:24",
"#13 () at node_modules/process/index.js:14",
"-------- async.queue.push ---------",
"#1 () at node_modules/nedb/lib/executor.js:56",
"#2 () at node_modules/nedb/lib/datastore.js:568",
"#3 () at models/thread.js:1687",
"#4 () at lib/async.js:122"

To get a stack trace, ti-longjohn uses the err.backtrace property of an Error object thrown during an exception. It seems that JavaScriptCore in Titanium is not very verbose about function names (hence, the empty () in the stack traces).

Moreover, it cannot be guaranteed by ti-longjohn that the stack traces are always complete.

Use in production

During execution of JavaScript code, ti-longjohn will keep a linked list of error objects in memory, each keeping a stack trace up to an async callback.

Moreover, in order to get a stack trace, a try/catch block is used which is known to be bad for performance.

For these reason it is not recommended to have ti-longjohn activated in production.

Limit traced async calls

longjohn.async_trace_limit = 5;   // defaults to 10
longjohn.async_trace_limit = -1;  // unlimited

Patching async.js

The queue mechanism in async.js breaks the stack trace chain that ti-longjohn tries to build and which it prints on error.

There is special support to patch the async.js queue in such a way that proper long stack traces are created:

var longjohn = require('ti-longjohn')(global);
longjohn.patch_async(require('async'));

Then the code

var q = async.queue(function (x) {
    i.do.not.exist = x;
});
q.push(42, function done() {
    Ti.API.info('done');
});

will lead to a long stack trace:

"TypeError at app.js:19",
"#2 () at node_modules/async/lib/async.js:809",
"#5 () at node_modules/process/index.js:14",
"-------- async.queue.push ---------",
"#1 () at app.js:23"