Skip to content

fix(cli): guard mops check --fix against undefined moc stdout#567

Open
giorgiopiatti-caffeinated wants to merge 1 commit into
caffeinelabs:mainfrom
giorgiopiatti-caffeinated:fix/autofix-undefined-stdout
Open

fix(cli): guard mops check --fix against undefined moc stdout#567
giorgiopiatti-caffeinated wants to merge 1 commit into
caffeinelabs:mainfrom
giorgiopiatti-caffeinated:fix/autofix-undefined-stdout

Conversation

@giorgiopiatti-caffeinated

Copy link
Copy Markdown
Contributor

Summary

mops check --fix can crash the entire command with:

TypeError: Cannot read properties of undefined (reading 'split')
    at parseDiagnostics (.../dist/helpers/autofix-motoko.js:7:10)
    at autofixMotoko (.../dist/helpers/autofix-motoko.js:111:33)

autofixMotoko spawns moc … --error-format=json via execa and feeds result.stdout straight into parseDiagnostics, which calls stdout.split("\n"). Per execa's documented contract, result.stdout can resolve to undefined (not "") when output isn't buffered, so parseDiagnostics(undefined) throws. The throw is unhandled (the autofix call in check.ts runs before, and outside of, the guarded moc --check block), so it aborts the whole command — and any deploy pipeline invoking mops check --fix (e.g. via caffeine check --fix) surfaces it as backend check failed (exit 1).

Fix

  • parseDiagnostics now returns [] for a missing/undefined stdout instead of calling .split on it. The autofix pass degrades gracefully (no fixes applied) and the authoritative mops check still runs and reports the real diagnostics.
  • Added unit tests for parseDiagnostics covering undefined, empty, and mixed JSON/non-JSON input.
  • Changelog entry under ## Next.

Test plan

  • npm run check (tsc) passes in cli/
  • npm test -- check-fix.test.ts -t parseDiagnostics — 3 new tests pass
  • CI green

Made with Cursor

`autofixMotoko` spawns `moc --error-format=json` via execa and passed
`result.stdout` straight into `parseDiagnostics`, which calls `.split`.
execa can resolve with `result.stdout === undefined` (per its documented
contract when output isn't buffered), so the autofix pass threw
`TypeError: Cannot read properties of undefined (reading 'split')`. The
throw is unhandled and aborts the whole command, which breaks any deploy
pipeline running `mops check --fix`.

Treat a missing/`undefined` stdout as "no diagnostics" so the autofix
pass degrades gracefully and the authoritative `mops check` still runs.

Co-authored-by: Cursor <cursoragent@cursor.com>
@giorgiopiatti-caffeinated giorgiopiatti-caffeinated requested a review from a team as a code owner June 9, 2026 19:40

@christoph-dfinity christoph-dfinity left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approving to move things along. @Kamirus maybe take a look when you get back, I personally would want to move the check out of the parse function.

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