fix(cli): guard mops check --fix against undefined moc stdout#567
Open
giorgiopiatti-caffeinated wants to merge 1 commit into
Open
Conversation
`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>
christoph-dfinity
approved these changes
Jun 10, 2026
christoph-dfinity
left a comment
There was a problem hiding this comment.
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.
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
mops check --fixcan crash the entire command with:autofixMotokospawnsmoc … --error-format=jsonvia execa and feedsresult.stdoutstraight intoparseDiagnostics, which callsstdout.split("\n"). Per execa's documented contract,result.stdoutcan resolve toundefined(not"") when output isn't buffered, soparseDiagnostics(undefined)throws. The throw is unhandled (the autofix call incheck.tsruns before, and outside of, the guardedmoc --checkblock), so it aborts the whole command — and any deploy pipeline invokingmops check --fix(e.g. viacaffeine check --fix) surfaces it asbackend check failed (exit 1).Fix
parseDiagnosticsnow returns[]for a missing/undefinedstdout instead of calling.spliton it. The autofix pass degrades gracefully (no fixes applied) and the authoritativemops checkstill runs and reports the real diagnostics.parseDiagnosticscoveringundefined, empty, and mixed JSON/non-JSON input.## Next.Test plan
npm run check(tsc) passes incli/npm test -- check-fix.test.ts -t parseDiagnostics— 3 new tests passMade with Cursor