Skip to content

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
ravi/intorg-716
Open

refactor(cms): convert page lifecycle and validators to errors-as-values [INTORG-716]#279
Infi-Knight wants to merge 1 commit intoravi/intorg-713from
ravi/intorg-716

Conversation

@Infi-Knight
Copy link
Copy Markdown
Contributor

@Infi-Knight Infi-Knight commented May 8, 2026

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:

  • pageLifecycle.ts:
    • fetchPublished returns PageData | null | Error. Distinguishes "no published version for this locale" (normal absence) from "Strapi document service threw" (real error). Callers in beforeUpdate and exportAllLocales narrow the three states explicitly.
    • 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, deleteMdxIfExists keep their try/catch fallback semantics with explanatory Why: comments. Their "errors" are legitimate "no request context" or "stale file" states, not failures the lifecycle hook should react to.
  • validateFrontmatter.ts: ValidationError is now a real class extending Error instead of an interface. validateFrontmatter returns MDXFile | ValidationError (was ValidationError | null). validateMdxFiles narrows with instanceof.
  • contentValidation.ts: 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. The try/catch around it is gone.
  • Tests for contentValidation and validateFrontmatter updated to assert returned values.

Related Issue

INTORG-716

Manual Test

Run the CMS sync test suite:

```
pnpm --dir cms test:sync-mdx
```

Checks

  • `pnpm run format`
  • `pnpm run lint`

PR Checklist

  • PR title follows Conventional Commits (e.g. `feat: ...`, `fix: ...`)
  • Linked issue included
  • Scope is focused (target ~10-20 files when possible)
  • Screenshots for UI changes (if applicable)

…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).
@Infi-Knight Infi-Knight self-assigned this May 8, 2026
@Infi-Knight Infi-Knight requested review from Anca2022 May 8, 2026 09:44
Copy link
Copy Markdown
Collaborator

@JonathanMatthey JonathanMatthey left a comment

Choose a reason for hiding this comment

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

nicely split - lgtm

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.

2 participants