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

Improve error messages for spago publish #1121

Merged
merged 10 commits into from
Nov 29, 2023
Merged

Conversation

JordanMartinez
Copy link
Contributor

@JordanMartinez JordanMartinez commented Nov 17, 2023

Description of the change

Fixes #1108.

These changes may still cause someone to run spago publish a few times before they fix every error, but it should prevent unpublishable git tags. The idea is:

  • show all errors, but put the git-tag-related ones at the bottom with a note saying to resolve all other errors and to not push any created git tags
  • move the Git.pushTags call, which requires login credentials to a step before the actual publish
  • I added another check for when the current publish config refers to an existing tag, but we don't have it checked out.

Checklist:

  • Added the change to the "Unreleased" section of the changelog
  • Added some example of the new feature to the README
  • Added a test for the contribution (if applicable)

P.S.: the above checks are not compulsory to get a change merged, so you may skip them. However, taking care of them will result in less work for the maintainers and will be much appreciated 😊

Comment on lines 15 to 16
Command failed with exit code 128: git status --porcelain
Copy link
Member

Choose a reason for hiding this comment

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

This error is considerably worse than the one we were giving out before - can we improve it?

Copy link
Contributor Author

@JordanMartinez JordanMartinez Nov 24, 2023

Choose a reason for hiding this comment

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

Should I also update the Git.listTags to use message rather than shortMessage?

Copy link
Member

@f-f f-f Nov 24, 2023

Choose a reason for hiding this comment

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

I don't think shortMessage vs message is going to matter here - the previous error message for the same test case was pretty informative:

❌ The git tree is not clean, or you haven't checked out the tag you want to publish.
Command failed with exit code 128: git status --porcelain
Please commit or stash your changes, and checkout the tag you want to publish.
fatal: not a git repository (or any of the parent directories): .git
To create the tag, you can run:
  git tag v0.0.1

The current one (even with message) much less so:

❌ Could not run `git status`. Error:
Command failed with exit code 128: git status --porcelain
fatal: not a git repository (or any of the parent directories): .git

I'd be pretty confused myself if I got this error.
It looks like we should catch the error where we have the context to give a good explanation, rather than just throwing the error that comes from git.

(to clarify - the old error message was not perfect either. We are still reporting the message that comes from git, but I think that's still confusing. The informative part of this is probably the only one we should show, and print the rest with debug logging: The git tree is not clean, or you haven't checked out the tag you want to publish.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Three things.
First, it's not clear to me why this test originally reported the above error. The "The git tree is not clean, or you haven't checked out the tag you want to publish.)" message is only reported when git status succeeds. If git status failed, it would just die there. So, what changes did I make that caused that to change?

Second, while I can mention the "git tree is not clean" part, checking out the tag shouldn't be done until the other issues are resolved first.

Third, printing the git status error as a debug message (as I'm understanding your last sentence) seems erroneous, too. If git status fails, there's a larger issue at hand (like the fact that no git repo exists) that should be reported to the user. Saying the 'git tree is not clean' misses the point. So, I updated the message to clarify why we were running git status.

Copy link
Member

Choose a reason for hiding this comment

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

This is all good, but I still think this warrants further investigation to improve error messages - I mean, we have a test that consistently reproduces a situation where a user gets a bad error message. We don't need to report that the user needs to make a tag at that point, but it should be clearly actionable, which it's not at the moment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Meaning... we should tell the user to run git init in this case?

Copy link
Member

Choose a reason for hiding this comment

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

git status will return an exit code 128 in various situations (no git repository available, or it's there but it's owned by another user, etc), but the most common reason is by far "there's no git repo".
So we should figure out that a 128 was returned and tell the user "Spago could not run git status because there's no git repo. Please run git init and commit your source files to move forward" (or something like that). We don't need to report the error message coming from git, we are pretty sure of what's going on.

@JordanMartinez JordanMartinez merged commit 478e379 into master Nov 29, 2023
3 checks passed
@JordanMartinez JordanMartinez deleted the jam/1108-publish-errors branch November 29, 2023 19:57
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.

Check package boundaries before git tree
2 participants