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(core): more detailed error message when version cannot be found #3424

Merged
merged 3 commits into from Dec 6, 2022

Conversation

amorscher
Copy link
Contributor

When running a lerna command and no version is present in lerna.json configuration following error message is printed:

lerna ERR! ENOLERNA `lerna.json` does not exist, have you run `lerna init`?

As described in (#3311) this is not completely correct.

Description

Addtional check is added during command validation to prove a version is available in lerna.json file. In addition the check for having a lerna configuration (lerna.json) available is adapted to really check for existance of the config file. This is achieved by setting an additional flag configNotFound in the project object during lerna.json retrival.

Motivation and Context

Improve error messages for invalid lerna.json to support user finding configuration problems.
The issue is described here (#3311).

How Has This Been Tested?

Added a unit test.
Manually built a lerna version.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (change that has absolutely no effect on users)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

 - added separate error message if version cannot be found
 - distinguish btw. no lerna.json not availble and invalid lerna.json
@amorscher
Copy link
Contributor Author

@JamesHenry any chance that the fix will make it to main?

Thx for having a look!

@@ -66,6 +66,7 @@ class Project {
// No need to distinguish between missing and empty,
Copy link
Member

Choose a reason for hiding this comment

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

Obviously I can't speak to the intent behind this comment originally, but your change does make it seem a little nonsensical, given you are adding an isEmpty right below a comment saying "no need to distinguish between missing and empty".

We could probably just amend the this.configNotFound assignment to check for Object.keys(loaded.config ?? {}).length === 0?

Copy link
Contributor Author

@amorscher amorscher Dec 4, 2022

Choose a reason for hiding this comment

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

You are right that is a little bit weird. For this case i think I need to distinguish btw. emtpy and notFound because in case of empty the error message of no lerna version should appear.
The comment is related to the following line assigning an emtpy object to config. This make completly sense there because doing this avoids nasty if checks. I changed the flag from empty to noConfigFound and return it in the config. Hope this makes it a little bit less nonsensical and understandable. What do you think?

Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

.

@amorscher amorscher force-pushed the improve-error-messages branch 2 times, most recently from 7721f65 to 7b95b57 Compare December 4, 2022 21:04
@JamesHenry
Copy link
Member

Thanks @amorscher!

@JamesHenry JamesHenry merged commit b729b0c into lerna:main Dec 6, 2022
@JamesHenry JamesHenry changed the title fix(command): more detailed error message when version cannot be found fix(core): more detailed error message when version cannot be found Dec 6, 2022
@amorscher amorscher deleted the improve-error-messages branch March 29, 2023 13:58
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

2 participants