Skip to content

Commit

Permalink
Merge pull request #38 from euforic/errorHandling
Browse files Browse the repository at this point in the history
[TIMOB-14262] LiveView: Does not trigger code errors
  • Loading branch information
Christian Sullivan committed Jul 16, 2013
2 parents a4e0d6d + 18ed035 commit 88c1c9a
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

SRC = lib/platform/_head.js lib/platform/events.js lib/platform/socket.js lib/platform/process.js lib/platform/require.js lib/platform/_tail.js
SRC = lib/platform/_head.js lib/platform/process.js lib/platform/events.js lib/platform/socket.js lib/platform/require.js lib/platform/_tail.js
BASE_DIR = $(CURDIR)/bin/liveview
# TODO kill only process make started
#`ps -ef | grep 'fserver\|bin\/ti' | awk "{print $2}"` > /dev/null
Expand Down
75 changes: 38 additions & 37 deletions build/liveview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@
* liveview Titanium CommonJS require with some Node.js love and dirty hacks
* Copyright (c) 2013 Appcelerator
*/
(function(globalScope) {
/**
* Initialize a new `Process`.
*
* @api public
*/

function Process() {
if (!(this instanceof Process)) return new Process();
this.title = 'titanium';
this.version = '';
this.moduleLoadList = [];
this.versions = {};
this.arch = Ti.Platform.architecture;
this.platform = Ti.Platform.name;
this.hardware = Ti.Platform.model;
}

// inherit from EventEmitter

Process.prototype.__proto__ = Emitter.prototype;
/*!
* Event Emitters
*/
Expand Down Expand Up @@ -293,41 +313,12 @@ Socket.prototype.setKeepAlive = function(enable, initialDelay) {
},initialDelay || 300000);
};

/**
* Initialize a new `Process`.
*
* @api public
*/

function Process() {
if (!(this instanceof Process)){ return new Process(); }
this.title = 'titanium';
this.version = '';
this.moduleLoadList = [];
this.versions = {};
this.arch = Ti.Platform.architecture;
this.platform = Ti.Platform.name;
this.hardware = Ti.Platform.model;
}

// inherit from EventEmitter

Process.prototype.__proto__ = Emitter.prototype;
/**
* Initialize a new `Module`.
*
* @api public
*/

if (typeof module !== 'undefined') {
module.exports = Module;
}

/**
* [Module description]
* @param {[type]} id [description]
*/

function Module(id) {
this.filename = id + '.js';
this.id = id;
Expand Down Expand Up @@ -601,7 +592,7 @@ Module._wrap = function(source) {

Module._errWrapper = [
'try {',
'} catch (err) { process.emit("uncaughtException", {module: __filename, error: err})}'
'} catch (err) { lvGlobal.process.emit("uncaughtException", {module: __filename, error: err})}'
];

/**
Expand All @@ -618,8 +609,14 @@ Module.prototype._compile = function() {
return;
}
var source = Module._wrap(src);
var fn = Function('exports, require, module, __filename, __dirname',source);
fn(this.exports, Module.require, this, this.filename, this.__dirname);

try{
var fn = Function('exports, require, module, __filename, __dirname, lvGlobal',source);
fn(this.exports, Module.require, this, this.filename, this.__dirname, global);
} catch(err) {
process.emit("uncaughtException", {module: this.filename, error: err});
}

this.loaded = true;
};

Expand All @@ -640,11 +637,15 @@ Module.prototype.cache = function() {
* @return {[type]} [description]
*/

(function(globalCtx) {

Module.patch(globalCtx);
Module.global.process.on('uncaughtException', function (err) {
console.error('[LiveView]', err);
process.on('uncaughtException', function (err) {
console.log('[LiveView] Error Evaluating', err.module, '@ Line:', err.error.line);
console.error('' + err.error);
console.error('File:', err.module);
console.error('Line:', err.error.line);
console.error('SourceId:', err.error.sourceId);
console.error('Backtrace:\n', err.error.backtrace.replace(/'\n'/g, '\n'));
});

Module.patch(globalScope);

})(this);
2 changes: 1 addition & 1 deletion build/liveview.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/platform/_head.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
* liveview Titanium CommonJS require with some Node.js love and dirty hacks
* Copyright (c) 2013 Appcelerator
*/
(function(globalScope) {
14 changes: 9 additions & 5 deletions lib/platform/_tail.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
* @return {[type]} [description]
*/

(function(globalCtx) {

Module.patch(globalCtx);
Module.global.process.on('uncaughtException', function (err) {
console.error('[LiveView]', err);
process.on('uncaughtException', function (err) {
console.log('[LiveView] Error Evaluating', err.module, '@ Line:', err.error.line);
console.error('' + err.error);
console.error('File:', err.module);
console.error('Line:', err.error.line);
console.error('SourceId:', err.error.sourceId);
console.error('Backtrace:\n', err.error.backtrace.replace(/'\n'/g, '\n'));
});

Module.patch(globalScope);

})(this);
2 changes: 1 addition & 1 deletion lib/platform/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

function Process() {
if (!(this instanceof Process)){ return new Process(); }
if (!(this instanceof Process)) return new Process();
this.title = 'titanium';
this.version = '';
this.moduleLoadList = [];
Expand Down
21 changes: 9 additions & 12 deletions lib/platform/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@
* @api public
*/

if (typeof module !== 'undefined') {
module.exports = Module;
}

/**
* [Module description]
* @param {[type]} id [description]
*/

function Module(id) {
this.filename = id + '.js';
this.id = id;
Expand Down Expand Up @@ -287,7 +278,7 @@ Module._wrap = function(source) {

Module._errWrapper = [
'try {',
'} catch (err) { process.emit("uncaughtException", {module: __filename, error: err})}'
'} catch (err) { lvGlobal.process.emit("uncaughtException", {module: __filename, error: err})}'
];

/**
Expand All @@ -304,8 +295,14 @@ Module.prototype._compile = function() {
return;
}
var source = Module._wrap(src);
var fn = Function('exports, require, module, __filename, __dirname',source);
fn(this.exports, Module.require, this, this.filename, this.__dirname);

try{
var fn = Function('exports, require, module, __filename, __dirname, lvGlobal',source);
fn(this.exports, Module.require, this, this.filename, this.__dirname, global);
} catch(err) {
process.emit("uncaughtException", {module: this.filename, error: err});
}

this.loaded = true;
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "liveview",
"version": "0.1.27",
"version": "0.1.28",
"description": "Titanium Live Realtime App Development",
"main": "index.js",
"private": true,
Expand Down

0 comments on commit 88c1c9a

Please sign in to comment.