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

lib: make safeRequire() return tuple #226

Closed
wants to merge 3 commits into from

Conversation

nechaido
Copy link
Member

As we discussed in #216 I add a PR that fixes #188 using different approach.
Refs:#216.
Closes: #188.

@nechaido nechaido added the lib label Jun 20, 2017
@@ -12,7 +12,7 @@ module.exports = jsrs;
// one of our priorities to optimize it.
const USE_NATIVE_SERIALIZER = false;

const jstpNative =
const [error, jstpNative] =
safeRequire('../build/Release/jstp') ||
Copy link
Member

Choose a reason for hiding this comment

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

This won't work.


test.equal(common.safeRequire(nonExistingModule), null,
test.equal(common.safeRequire(nonExistingModule)[1], null,
Copy link
Member

@aqrln aqrln Jun 20, 2017

Choose a reason for hiding this comment

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

[0]

disregard it

@@ -7,7 +7,7 @@ const common = require('../../lib/common');
const existingModule = 'fs';
const nonExistingModule = '__non_existing_module__';

test.ok(common.safeRequire(existingModule), 'must require existing module');
test.ok(common.safeRequire(existingModule), 'must require existing module'[1]);
Copy link
Member

Choose a reason for hiding this comment

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

I believe you didn't mean to compare an array with 'm' ;)

Copy link
Member

Choose a reason for hiding this comment

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

That's error message =). But yeah it was funny.

Copy link
Member

Choose a reason for hiding this comment

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

ah, it's not a comparison, but a test message

@@ -7,7 +7,7 @@ const common = require('../../lib/common');
const existingModule = 'fs';
const nonExistingModule = '__non_existing_module__';

test.ok(common.safeRequire(existingModule), 'must require existing module');
test.ok(common.safeRequire(existingModule), 'must require existing module'[1]);
Copy link
Member

Choose a reason for hiding this comment

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

I think [1] should be in a different place =).


test.equal(common.safeRequire(nonExistingModule), null,
test.equal(common.safeRequire(nonExistingModule)[1], null,
Copy link
Member

@lundibundi lundibundi Jun 20, 2017

Choose a reason for hiding this comment

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

Why don't we test this with notOk as the one above is tested with ok?
UPD: @nechaido ping.

let [error, jstpNative] = safeRequire('../build/Release/jstp');

if (error) {
[error, jstpNative] = safeRequire('../build/Debug/jstp');
Copy link
Member

Choose a reason for hiding this comment

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

error will be overwritten here, losing the original error.

Copy link
Member

@aqrln aqrln Jun 21, 2017

Choose a reason for hiding this comment

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

Yeah, I'd rather only show the error that occurred trying to load the release build when both failed if we opt for showing only one. Alternatively, we may show both, like we do now. I'm fine with it both ways, slightly leaning towards the former one.

@aqrln
Copy link
Member

aqrln commented Jun 21, 2017

Alternative PR: #216. Whichever wins the race will land on master.

nechaido added a commit that referenced this pull request Jun 22, 2017
Refs: #216
Closes: #188
PR-URL: #226
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
@nechaido
Copy link
Member Author

Landed in 35c6a8c.

@nechaido nechaido closed this Jun 22, 2017
@nechaido nechaido deleted the safe-require-return-tuple branch June 22, 2017 11:15
belochub pushed a commit that referenced this pull request Jan 22, 2018
Refs: #216
Closes: #188
PR-URL: #226
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
belochub pushed a commit that referenced this pull request Jan 22, 2018
Refs: #216
Closes: #188
PR-URL: #226
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
@belochub belochub mentioned this pull request Jan 22, 2018
belochub pushed a commit to metarhia/mdsf that referenced this pull request Jul 19, 2018
Refs: metarhia/jstp#216
Closes: metarhia/jstp#188
PR-URL: metarhia/jstp#226
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
belochub pushed a commit to metarhia/mdsf that referenced this pull request Jul 19, 2018
Refs: metarhia/jstp#216
Closes: metarhia/jstp#188
PR-URL: metarhia/jstp#226
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
belochub pushed a commit to metarhia/mdsf that referenced this pull request Jul 21, 2018
Refs: metarhia/jstp#216
Closes: metarhia/jstp#188
PR-URL: metarhia/jstp#226
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove unnecessary output from common.safeRequire()
4 participants