Skip to content

fix(parse): improve error messages for malformed changesets#1831

Merged
Andarist merged 11 commits into
changesets:mainfrom
murataslan1:fix/improve-parse-error-messages
Feb 23, 2026
Merged

fix(parse): improve error messages for malformed changesets#1831
Andarist merged 11 commits into
changesets:mainfrom
murataslan1:fix/improve-parse-error-messages

Conversation

@murataslan1
Copy link
Copy Markdown
Contributor

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:

  • "could not parse changeset - invalid frontmatter" doesn't explain what's wrong
  • No guidance on the correct format

Solution

Improved error messages that:

  • Explain what went wrong - e.g., "file is empty", "missing or invalid frontmatter", "invalid YAML"
  • Show what was received - truncated content for context
  • Provide examples of the correct format
  • Validate version types - must be one of: major, minor, patch, none
  • Validate package names - must be non-empty strings

Example Error Messages

Empty file:

could not parse changeset - file is empty.
Changesets must have frontmatter with package names and version types.
Example:
---
"package-name": patch
---

Your changeset summary here.

Invalid version type:

could not parse changeset - invalid version type "typo" for package "my-package".
Valid version types are: major, minor, patch, none

Test plan

  • Added tests for empty file handling
  • Added tests for missing frontmatter
  • Added tests for invalid version types
  • Added tests for empty package names
  • Updated existing tests for new error message format

Made with Cursor

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]>
Copilot AI review requested due to automatic review settings February 2, 2026 12:55
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 2, 2026

🦋 Changeset detected

Latest commit: 5f1b473

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@changesets/parse Patch
@changesets/cli Patch
@changesets/read Patch
@changesets/get-release-plan Patch
@changesets/release-utils Patch

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread packages/parse/src/index.ts Outdated
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}`
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

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 ? "..." : ""}

Suggested change
`Changeset contents:\n${contents}`
`Changeset contents:\n${contents.slice(0, 200)}${contents.length > 200 ? "..." : ""}`

Copilot uses AI. Check for mistakes.
Comment thread packages/parse/src/index.ts Outdated
Comment on lines +22 to +28
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}`
);
}
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

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(...) }

Copilot uses AI. Check for mistakes.
Comment thread packages/parse/src/index.test.ts
Comment thread package-lock.json Outdated
Comment thread packages/parse/src/index.test.ts
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.55%. Comparing base (73b1809) to head (5f1b473).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/parse/src/index.ts 91.66% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Andarist Andarist merged commit 1f91879 into changesets:main Feb 23, 2026
6 checks passed
@github-actions github-actions Bot mentioned this pull request Feb 23, 2026
nnecec pushed a commit to nnecec/changesets-docs that referenced this pull request Apr 16, 2026
* 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]>
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.

Harden behavior on failed changeset read

3 participants