Skip to content

If an error occurs mid-installation, that error should be sent to the window #127

@phenaproxima

Description

@phenaproxima

So, this seems to vary between systems, which is troubling. But, on my machine, if the installation fails midway through, I do not get to see Composer's output. It's logged, obviously, and that's helpful, but it makes error reporting harder if all you can see is that a process failed, but you don't have a clear error.

The root of this trouble, I think, is in installer.ts, specifically this passage:

    for (const command of installCommands) {
        await new ComposerCommand(...command)
            .inDirectory(projectRoot)
            .run({}, (line: string, type: OutputType): void => {
                if (type === OutputType.Error) {
                    win?.send(Events.Output, line);
                }
            });
    }

The problem with this is a complete lack of error handling. If any of these commands fail, the install will stop -- which is good -- but the raw exception that stopped the process will just bubble up to main.ts and be caught by the catch (e) on line 50 of that file.

What would be better is if we captured the actual output of the command that failed, and then threw an error with that as its text.

So how to do that? My best guess is that we need to create a new mutable string outside of the loop (let output: string = '') and, as we run each Composer command, empty the contents of the string and then append to it, line by line, in the output callback passed to run() -- something like:

else if (type === OutputType.Out) {
  output += `${line}\n`;
}

Then we need to take advantage of the .catch() method of the promise returned by run(). We'll probably want to do something like:

.catch(() => {
  throw new Error(output);
});

That should, I'm hoping, cause the actual Composer output to be in the thrown error, which will then bubble up to the window.

We'll want to test this by changing the existing 'clean up directory on failed install' test so that, instead of waiting for the .error element to be visible, it waits for the actual error text to appear (which, if you use the composer-install-error.php mock, will be "An imaginary error occurred!").

So this seems very approachable to me. Thoughts?

Metadata

Metadata

Assignees

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