fix(parse): improve error messages for malformed changesets#1831
Conversation
Fixes changesets#175 This PR improves the error handling and messages when parsing malformed changeset files. The previous error messages were generic and didn't help users understand what went wrong. Changes: - Add validation for empty changeset files with helpful example - Improve error message when frontmatter is missing or invalid - Add specific error for invalid YAML in frontmatter, including the YAML error - Validate version types (major, minor, patch, none) with clear error message - Validate package names are non-empty strings - Include examples of correct format in error messages - Add tests for all new error scenarios The error messages now: - Explain what went wrong - Show what was received - Provide an example of the correct format Co-authored-by: Cursor <[email protected]>
🦋 Changeset detectedLatest commit: 5f1b473 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
This PR improves error handling and messages when parsing malformed changeset files, addressing issue #175. The changes make it easier for users to understand what went wrong and how to fix malformed changesets.
Changes:
- Added validation for empty files with helpful error messages
- Improved frontmatter validation with clearer error messages and examples
- Added validation for version types (must be major, minor, patch, or none)
- Added validation for package names (must be non-empty strings)
- Enhanced YAML error reporting with the underlying YAML parser error
- Updated tests to cover new error cases and validate improved error messages
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/parse/src/index.ts | Adds comprehensive validation and improved error messages for changeset parsing, including empty file detection, version type validation, and package name validation |
| packages/parse/src/index.test.ts | Updates existing tests for new error messages and adds new test cases for empty files, missing frontmatter, invalid version types, and empty package names |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| throw new Error( | ||
| `could not parse changeset - invalid version type "${release.type}" for package "${release.name}".\n` + | ||
| `Valid version types are: ${validVersionTypes.join(", ")}\n` + | ||
| `Changeset contents:\n${contents}` |
There was a problem hiding this comment.
The error message on line 26 includes the full changeset contents which could be very large. Consider truncating this similar to how line 52 truncates to 200 characters: Changeset contents:\n${contents.slice(0, 200)}${contents.length > 200 ? "..." : ""}
| `Changeset contents:\n${contents}` | |
| `Changeset contents:\n${contents.slice(0, 200)}${contents.length > 200 ? "..." : ""}` |
| if (!validVersionTypes.includes(release.type)) { | ||
| throw new Error( | ||
| `could not parse changeset - invalid version type "${release.type}" for package "${release.name}".\n` + | ||
| `Valid version types are: ${validVersionTypes.join(", ")}\n` + | ||
| `Changeset contents:\n${contents}` | ||
| ); | ||
| } |
There was a problem hiding this comment.
The validation only checks if the version type is in the valid list, but doesn't verify that release.type is a string. If the YAML contains a non-string value (e.g., an object, array, number, or boolean), it should be rejected with a clear error message. Consider adding a type check before the validVersionTypes check: if (typeof release.type !== "string") { throw new Error(...) }
Co-authored-by: Cursor <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1831 +/- ##
==========================================
+ Coverage 81.46% 81.55% +0.09%
==========================================
Files 55 55
Lines 2336 2353 +17
Branches 692 698 +6
==========================================
+ Hits 1903 1919 +16
- Misses 428 429 +1
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
* fix(parse): improve error messages for malformed changesets Fixes changesets#175 This PR improves the error handling and messages when parsing malformed changeset files. The previous error messages were generic and didn't help users understand what went wrong. Changes: - Add validation for empty changeset files with helpful example - Improve error message when frontmatter is missing or invalid - Add specific error for invalid YAML in frontmatter, including the YAML error - Validate version types (major, minor, patch, none) with clear error message - Validate package names are non-empty strings - Include examples of correct format in error messages - Add tests for all new error scenarios The error messages now: - Explain what went wrong - Show what was received - Provide an example of the correct format Co-authored-by: Cursor <[email protected]> * chore: add changeset file Co-authored-by: Cursor <[email protected]> * chore: address review feedback * chore: address copilot feedback * revert yarn.lock changes * tweak * tweak * tweak * tweak --------- Co-authored-by: Murat Aslan <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Mateusz Burzyński <[email protected]>
Summary
Fixes #175
This PR improves the error handling and messages when parsing malformed changeset files. The previous error messages were generic and didn't help users understand what went wrong.
Problem
As mentioned in #175, when changeset files are malformed (missing frontmatter, invalid YAML, typos in package names), the error messages were not explanatory enough:
Solution
Improved error messages that:
Example Error Messages
Empty file:
Invalid version type:
Test plan
Made with Cursor