Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yunong/3.0 #4

Merged
merged 17 commits into from
Oct 24, 2016
Merged

Yunong/3.0 #4

merged 17 commits into from
Oct 24, 2016

Conversation

yunong
Copy link
Member

@yunong yunong commented Oct 21, 2016

@DonutEspresso @rajatkumar PTAL
Cleanup and rewrite of enroute.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 35149a8 on yunong/2.0 into * on master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 051e74a on yunong/2.0 into * on master*.

@coveralls
Copy link

coveralls commented Oct 21, 2016

Coverage Status

Changes Unknown when pulling 051e74a on yunong/2.0 into * on master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 5eca780 on yunong/2.0 into * on master*.

1 similar comment
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 5eca780 on yunong/2.0 into * on master*.

Copy link
Member

@DonutEspresso DonutEspresso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally errbacks could use more context. Given that these errors will be customer facing, being explicit about bad file locations or bad file contents would be good.

* `opts`: The options object containing
* `opts.server` The restify server to install the routes on to.
* `opts.config` The POJO of the enroute config.
* `opts.configPath` The path to the enroute config on disk.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are config and configPath mutually exclusive?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, they are - would recommend documenting that here (and also add [] to indicate optionalness as you have in the JSDocs).

* @param {function} cb The callback.
* @returns {undefined}
*/
function install(opts, cb) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've started this convention where the function level cb is always callback, and use cb, cb2 for nested async ops. It's nice because you see right away where you exit the top level fn.

/* eslint-enable no-eval */
};
} catch (e) {
return _cb(e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to use VError or something to wrap some more contextual info? Like the file name and location, etc.

} else {
fs.readFile(opts.configPath, 'utf8', function (err, config) {
if (err) {
_cb(new verror.VError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the info property and attach the file path, more context ftw.

it.config = JSON.parse(config);
_cb();
} catch (e) {
_cb(e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also probably want a VError here.

var errors = _.map(validate.errors, function (fakeErr) {
return new verror.VError({
name: 'EnrouteConfigCompileError',
info: fakeErr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ajv doesn't return real error objects?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. :(

if (cb) {
return cb(err);
} else {
throw err;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what scenario is this called without a callback?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, some vestigial code here -- i can clean up.

"source": "./routes/getAcceptCookies.js"
}
"schemaVersion": 1,
"foo": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If routes are top level, thoughts on If we add more metadata in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, fair point, presumably we'd move to V2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the PR -- added 'routes' as a top level property.

},
function validateInput(it, _cb) {
_validateInput(it.schema, it.config, function (err, res) {
result = res;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This result/res dance is kind of confusing. Would recommend renaming res since that's commonly used for response objects.

Why not just have the final errback at L:99 return the result of the last operation instead of using a closure variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming is confusing. result is actually the parsed config, and not the vasync result object. I'll rename it.

@@ -60,9 +59,7 @@ lint: node_modules $(ESLINT) $(SRCS)
# make nsp always pass - run this as separate travis task for "reporting"
.PHONY: nsp
nsp: node_modules $(NSP)
$(NPM) shrinkwrap --dev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove the shrinkwrap it won't check for issues with transitive module (which is typically where most security issues occur, at lower level modules). Any reason why we don't want to have that visibility?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orrrr... is this covered by yarn now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realize it was needed by nsp, i can revert.

@coveralls
Copy link

coveralls commented Oct 24, 2016

Coverage Status

Changes Unknown when pulling 72fd7f5 on yunong/2.0 into * on master*.

@coveralls
Copy link

coveralls commented Oct 24, 2016

Coverage Status

Changes Unknown when pulling c40558e on yunong/2.0 into * on master*.

@coveralls
Copy link

coveralls commented Oct 24, 2016

Coverage Status

Changes Unknown when pulling 58b2bb3 on yunong/2.0 into * on master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 79cd761 on yunong/2.0 into * on master*.

1 similar comment
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 79cd761 on yunong/2.0 into * on master*.

@coveralls
Copy link

coveralls commented Oct 24, 2016

Coverage Status

Changes Unknown when pulling 47b6cfb on yunong/2.0 into * on master*.

@yunong
Copy link
Member Author

yunong commented Oct 24, 2016

@DonutEspresso addressed PR concerns -- please take a look as I want to merge and publish.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 30dd69e on yunong/2.0 into * on master*.

1 similar comment
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 30dd69e on yunong/2.0 into * on master*.

@yunong
Copy link
Member Author

yunong commented Oct 24, 2016

@DonutEspresso going to merge for now -- feel free to fire off additional comments.

@yunong yunong dismissed DonutEspresso’s stale review October 24, 2016 20:30

Addressed CR comments, Alex is on vacation, he's free to add additional comments when he returns.

@yunong yunong merged commit d85ada6 into master Oct 24, 2016
@wesleytodd wesleytodd deleted the yunong/2.0 branch November 3, 2022 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants