mystor / meteor-routecore

Client and server side rendering/routing powered by React
84 stars 6 forks source link

Improve error message for no context on server #13

Closed MrEfrem closed 7 years ago

MrEfrem commented 9 years ago
console.log(RouteCore.context());

in main.jsx

/home/efrem/.meteor/packages/meteor-tool/.1.0.40.1ef5dzv++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:173
W20150207-11:39:13.913(4)? (STDERR)                         throw(ex);
W20150207-11:39:13.913(4)? (STDERR)                               ^
W20150207-11:39:14.000(4)? (STDERR) TypeError: Cannot read property 'context' of undefined
W20150207-11:39:14.000(4)? (STDERR)     at Object.context (packages/mystor:routecore/context-server.js:89:1)
W20150207-11:39:14.000(4)? (STDERR)     at app/main.jsx.js:3:23
W20150207-11:39:14.000(4)? (STDERR)     at app/main.jsx.js:7:3
W20150207-11:39:14.000(4)? (STDERR)     at /home/efrem/WebstormProjects/test_meteor/.meteor/local/build/programs/server/boot.js:205:10
W20150207-11:39:14.001(4)? (STDERR)     at Array.forEach (native)
W20150207-11:39:14.001(4)? (STDERR)     at Function._.each._.forEach (/home/efrem/.meteor/packages/meteor-tool/.1.0.40.1ef5dzv++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20150207-11:39:14.001(4)? (STDERR)     at /home/efrem/WebstormProjects/test_meteor/.meteor/local/build/programs/server/boot.js:116:5
mystor commented 9 years ago

On the server, a context is only available if you are in a request handler (for example, while rendering a page). In other situations (such as in arbitrary server code), there is no particular client context, so it doesn't make sense to have a context available. The error message could certainly be better though.

MrEfrem commented 9 years ago

Thanks, I understood.