Skip to content

Build crashes on files a plugin adds to event.files after the prepare phase #1806

Description

@TwitchBronBron

Program.build() ends by undoing edits on every file it built:

for (const file of event.files) {
    file.editor.undoAll();
}

Editors are assigned during prepare(), so any file a plugin pushes onto event.files after that point has no editor, and the build throws TypeError: Cannot read properties of undefined (reading 'undoAll').

This is reachable from a supported hook. afterPrepareProgram receives event.files and is documented as mutable, but a file added there misses editor assignment and crashes the build it was added to.

Where I hit it: rooibos generates its code-coverage component from data collected during prepareFile, so it can't be registered any earlier than afterPrepareProgram. Working around it by assigning an editor ourselves:

const file = program.setFile(entry, contents);
file.editor ??= new Editor();

That works, but it depends on a build-internal detail that plugins shouldn't need to know about.

Suggested fix — either guard the cleanup loop:

file.editor?.undoAll();

or assign an editor in the same loop that serializes, so late additions are covered. The guard alone is enough to stop the crash.

Seen on 1.0.0-alpha.53; the cleanup loop is unguarded on master as well.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions