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

Catch errors from git being absent and continue on as best possible #173

Merged
merged 7 commits into from
Oct 4, 2019

Conversation

ajaymathur
Copy link
Contributor

No description provided.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 1, 2019

🦋 Changeset is good to go

Latest commit: 74f553d

We got this.

Not sure what this means? Click here to learn what changesets are.

@ajaymathur ajaymathur changed the title For #130 Catch errors from git being absent and continue on as best possible Oct 1, 2019
Comment on lines 148 to 154
try {
const masterRef = await getMasterRef(cwd);
return getChangedPackagesSinceCommit(masterRef, cwd);
} catch {
// Do nothing when operation fails
}
return [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not able to get it tests in unit test properly. If you have encountered this type of condition please let me know the best way to test it.

Copy link
Member

Choose a reason for hiding this comment

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

Since it should theoretically never happen, let's not wrap it in a try catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't wrap this in try catch, then error will bubble up and it will return an empty array they way we want it to.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, sorry, I thought this function was calling out to the other one that includes a try catch, makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

wrt testing: using cwd = await copyFixtureIntoTempDir(__dirname, "with-git") in a test but without running git init should make it fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, I will add a test.

Comment on lines 148 to 154
try {
const masterRef = await getMasterRef(cwd);
return getChangedPackagesSinceCommit(masterRef, cwd);
} catch {
// Do nothing when operation fails
}
return [];
Copy link
Member

Choose a reason for hiding this comment

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

Since it should theoretically never happen, let's not wrap it in a try catch.

.filter(file => tester.test(file));
if (!fullPath) return files;
return files.map(file => path.resolve(cwd, file));
} catch {}
Copy link
Member

Choose a reason for hiding this comment

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

Could we make this specific to the git errors so we don't silently catch errors from actual potential bugs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good pattern is:

try {
  // some code at some time
} catch (e) {
  if (e.message.includes('this-specific-thing') {
    // handle the error
  } else {
    throw e
  }
}

message is one option, but there may be better things to interrogate.

Copy link
Member

Choose a reason for hiding this comment

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

One thing I like doing is this

class GitError extends Error {}


try {
  // some code at some time
  throw new GitError('the message')
} catch (e) {
  if (e instanceof GitError) {
    // handle the error
  } else {
    throw e
  }
}

@ajaymathur
Copy link
Contributor Author

@Noviny @mitchellhamilton Thanks for the review, PR is ready for review again 🙂

@ajaymathur
Copy link
Contributor Author

@mitchellhamilton Thanks for adding changeset and updating readme.

I actually added the package as @changesets/errors since in future there will more that one error type exported from the package. But yeah now I see having it as error is better. I can update it if you are not already doing it. 😉

@emmatown
Copy link
Member

emmatown commented Oct 4, 2019

I actually added the package as @changesets/errors since in future there will more that one error type exported from the package. But yeah now I see having it as error is better. I can update it if you are not already doing it. 😉

Totally agree with having @changesets/errors(including the name), that update to the readme was making it consistent with the name in the package.json

@ajaymathur
Copy link
Contributor Author

I read your commit in a wrong way. Thanks for correcting it, 🙂

Copy link
Collaborator

@Noviny Noviny left a comment

Choose a reason for hiding this comment

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

Fixed one last thing - I think this is good to merge

@Noviny Noviny merged commit 94de7c1 into master Oct 4, 2019
@Noviny Noviny deleted the catch-git-errors branch October 4, 2019 06:26
@github-actions github-actions bot mentioned this pull request Oct 4, 2019
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