refactor(cms): convert page lifecycle and validators to errors-as-values [INTORG-716]#279
Open
Infi-Knight wants to merge 1 commit intoravi/intorg-713from
Open
refactor(cms): convert page lifecycle and validators to errors-as-values [INTORG-716]#279Infi-Knight wants to merge 1 commit intoravi/intorg-713from
Infi-Knight wants to merge 1 commit intoravi/intorg-713from
Conversation
…ues [INTORG-716] pageLifecycle.fetchPublished now returns PageData | null | Error, distinguishing "no published version for this locale" (a normal state) from "Strapi document service threw" (a real error). Callers in beforeUpdate and exportAllLocales narrow the three states explicitly. pageLifecycle.writeMDXFile returns string | Error instead of throwing. exportAllLocales narrows on the result and logs continue-on-error so a single locale failure doesn't abort the rest. shouldSkipMdxExport, getAdminAuthor, and deleteMdxIfExists keep their try/catch fallback semantics with explanatory `Why:` comments. Their "errors" are legitimate "no request context" or "stale file we couldn't remove" states, not failures the lifecycle hook should react to. validateFrontmatter.ValidationError is now a real class extending Error instead of an interface. validateFrontmatter returns MDXFile | ValidationError (was ValidationError | null), and validateMdxFiles narrows with instanceof. contentValidation.validateNoNestedJsx returns errors.ValidationError | undefined instead of throwing. The Strapi middleware in cms/src/index.ts narrows on the return and translates to a 400 response without try/catch. 251 cms tests pass. Stacked on ravi/intorg-713 (sub #1). Independent of sub #2 (INTORG-714).
JonathanMatthey
approved these changes
May 8, 2026
Collaborator
JonathanMatthey
left a comment
There was a problem hiding this comment.
nicely split - lgtm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sub #4 of INTORG-614. Converts the remaining CMS surfaces outside the sync pipeline (page lifecycle hooks and the two validators) to errors-as-values.
What's in the diff:
fetchPublishedreturnsPageData | null | Error. Distinguishes "no published version for this locale" (normal absence) from "Strapi document service threw" (real error). Callers inbeforeUpdateandexportAllLocalesnarrow the three states explicitly.writeMDXFilereturnsstring | Errorinstead of throwing.exportAllLocalesnarrows on the result and logs continue-on-error so a single locale failure doesn't abort the rest.shouldSkipMdxExport,getAdminAuthor,deleteMdxIfExistskeep their try/catch fallback semantics with explanatoryWhy:comments. Their "errors" are legitimate "no request context" or "stale file" states, not failures the lifecycle hook should react to.ValidationErroris now a real class extendingErrorinstead of an interface.validateFrontmatterreturnsMDXFile | ValidationError(wasValidationError | null).validateMdxFilesnarrows withinstanceof.validateNoNestedJsxreturnserrors.ValidationError | undefinedinstead of throwing. The Strapi middleware in cms/src/index.ts narrows on the return and translates to a 400 response. The try/catch around it is gone.contentValidationandvalidateFrontmatterupdated to assert returned values.Related Issue
INTORG-716
Manual Test
Run the CMS sync test suite:
```
pnpm --dir cms test:sync-mdx
```
Checks
PR Checklist