Skip to content
Browse files

Catch errors when loading code on demand, plus minor tweaks

  • Loading branch information...
1 parent 3cea26c commit c7841066c9844a024f0b10eb911c82d1e5607927 Owen Barnes committed Jul 30, 2012
View
2 doc/guide/en/client_side_code.md
@@ -19,7 +19,7 @@ While we try to keep the experience between browser and server as similar as pos
#### 'libs' - Legacy (non Common JS) Libraries
-Any file which lives in any directory called 'libs' will NOT be served as a module. Instead these files will be sent as-is without any modification. Typically you'll want to ensure jQuery and other libraries which use the `window` variable are always placed in a `/client/code` directory called 'libs'.
+Any file which lives in a directory called 'libs' will NOT be served as a module. Instead these files will be sent as-is without any modification. Typically you'll want to ensure jQuery and other libraries which use the `window` variable are always placed in a `/client/code` directory called 'libs'.
As load order is critically important for non Common JS libraries **either** name your files alphanumerically within the `libs` directory **or** list each file explicitly in your `ss.client.define()` command - your choice.
View
2 lib/cli/generate.js
@@ -86,7 +86,7 @@ exports.generate = function(program) {
clientFiles.css.push('libs/reset.css');
clientFiles.css.push('app.styl');
}
- appjs = "// My SocketStream 0.3 app\n\nvar http = require('http'),\n ss = require('socketstream');\n\n// Define a single-page client\nss.client.define('main', {\n view: 'app." + viewExtension + "',\n css: ['" + (clientFiles.css.join("', '")) + "'],\n code: ['" + (clientFiles.code.join("', '")) + "'],\n tmpl: '*'\n});\n\n// Serve this client on the root URL\nss.http.route('/', function(req, res){\n res.serveClient('main');\n});\n";
+ appjs = "// My SocketStream 0.3 app\n\nvar http = require('http'),\n ss = require('socketstream');\n\n// Define a single-page client called 'main'\nss.client.define('main', {\n view: 'app." + viewExtension + "',\n css: ['" + (clientFiles.css.join("', '")) + "'],\n code: ['" + (clientFiles.code.join("', '")) + "'],\n tmpl: '*'\n});\n\n// Serve this client on the root URL\nss.http.route('/', function(req, res){\n res.serveClient('main');\n});\n";
if (selectedFormatters.length > 0) {
appjs += "\n// Code Formatters\n";
}
View
26 lib/client/serve/ondemand.js
@@ -1,6 +1,8 @@
// Generated by CoffeeScript 1.3.3
var magicPath, pathlib, queryCache, utils;
+require('colors');
+
pathlib = require('path');
magicPath = require('../magic_path');
@@ -32,15 +34,21 @@ module.exports = function(ss, router, options) {
dir = pathlib.join(ss.root, options.dirs.code);
files = magicPath.files(dir, [path]);
return files.forEach(function(file) {
- return asset.js(file, {
- pathPrefix: path,
- compress: options.packAssets
- }, function(js) {
- output.push(js);
- if (output.length === files.length) {
- return cb(output.join("\n"));
- }
- });
+ var description;
+ try {
+ return asset.js(file, {
+ pathPrefix: path,
+ compress: options.packAssets
+ }, function(js) {
+ output.push(js);
+ if (output.length === files.length) {
+ return cb(output.join("\n"));
+ }
+ });
+ } catch (e) {
+ description = e.stack && e.stack.split("\n")[0] || 'Unknown Error';
+ return ss.log(("! Unable to load " + file + " on demand:").red, description);
+ }
});
};
worker = function(request, response, path, cb) {
View
2 src/cli/generate.coffee
@@ -94,7 +94,7 @@ exports.generate = (program) ->
var http = require('http'),
ss = require('socketstream');
-// Define a single-page client
+// Define a single-page client called 'main'
ss.client.define('main', {
view: 'app.#{viewExtension}',
css: ['#{clientFiles.css.join("', '")}'],
View
14 src/client/serve/ondemand.coffee
@@ -2,6 +2,7 @@
# ----------------------
# Serves assets to browsers on demand, caching responses in production mode
+require('colors')
pathlib = require('path')
magicPath = require('../magic_path')
utils = require('./utils')
@@ -30,10 +31,15 @@ module.exports = (ss, router, options) ->
dir = pathlib.join(ss.root, options.dirs.code)
files = magicPath.files(dir, [path])
files.forEach (file) ->
- asset.js file, {pathPrefix: path, compress: options.packAssets}, (js) ->
- output.push(js)
- if output.length == files.length # last file
- cb(output.join("\n"))
+ try
+ asset.js file, {pathPrefix: path, compress: options.packAssets}, (js) ->
+ output.push(js)
+ if output.length == files.length # last file
+ cb(output.join("\n"))
+ catch e
+ description = e.stack && e.stack.split("\n")[0] || 'Unknown Error'
+ ss.log("! Unable to load #{file} on demand:".red, description)
+
# Web Workers
worker = (request, response, path, cb) ->

0 comments on commit c784106

Please sign in to comment.
Something went wrong with that request. Please try again.