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

Fix semver compare when first version #94

Merged
merged 1 commit into from
Dec 6, 2015

Conversation

oney
Copy link
Contributor

@oney oney commented Dec 6, 2015

In first version(not install any update from CodePush), we will get [CodePush] An unknown error occurred. after calling CodePush.sync();.
In CodePush.js line 55

console.log('localPackage', localPackage); // -> { failedInstall: false, isFirstRun: false }

if (localPackage && semver.compare(localPackage.appVersion, config.appVersion) === 0) {
 queryPackage = localPackage;
}

Because localPackage.appVersion is undefined, semver.compare will throw an exception.

try {
  semver.compare(localPackage.appVersion, config.appVersion);
} catch (e) {
  console.log('This is an error', e);
}

Logs are

'This is an error', { [TypeError: Invalid Version: undefined]
  line: 57942,
  column: 20,
  sourceURL: 'http://localhost:8081/index.ios.bundle?platform=ios&dev=true' }

So, just check localPackage.appVersion first then compare them.

@lostintangent
Copy link
Member

LGTM! I obviously forgot to test this change in an app with no previous updates. Thanks for this contribution @oney!

lostintangent added a commit that referenced this pull request Dec 6, 2015
Fix semver compare when first version
@lostintangent lostintangent merged commit 5b6fbdb into microsoft:master Dec 6, 2015
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