Skip to content

ATL-653: Added error handling for core/lib install #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as React from 'react';
import debounce = require('lodash.debounce');
import { Event } from '@theia/core/lib/common/event';
import { CommandService } from '@theia/core/lib/common/command';
import { MessageService } from '@theia/core/lib/common/message-service';
import { OutputCommands } from '@theia/output/lib/browser/output-commands';
import { ConfirmDialog } from '@theia/core/lib/browser/dialogs';
import { Searchable } from '../../../common/protocol/searchable';
import { Installable } from '../../../common/protocol/installable';
Expand Down Expand Up @@ -85,9 +88,13 @@ export class FilterableListContainer<T extends ArduinoComponent> extends React.C
const dialog = new InstallationProgressDialog(itemLabel(item), version);
try {
dialog.open();
await this.clearArduinoChannel();
await install({ item, version });
const items = await searchable.search({ query: this.state.filterText });
this.setState({ items: this.sort(items) });
} catch (error) {
this.props.messageService.error(error instanceof Error ? error.message : String(error));
throw error;
} finally {
dialog.close();
}
Expand All @@ -106,6 +113,7 @@ export class FilterableListContainer<T extends ArduinoComponent> extends React.C
const { uninstall, searchable, itemLabel } = this.props;
const dialog = new UninstallationProgressDialog(itemLabel(item));
try {
await this.clearArduinoChannel();
dialog.open();
await uninstall({ item });
const items = await searchable.search({ query: this.state.filterText });
Expand All @@ -115,6 +123,10 @@ export class FilterableListContainer<T extends ArduinoComponent> extends React.C
}
}

private async clearArduinoChannel(): Promise<void> {
return this.props.commandService.executeCommand(OutputCommands.CLEAR.id, { name: 'Arduino' });
}

}

export namespace FilterableListContainer {
Expand All @@ -129,6 +141,8 @@ export namespace FilterableListContainer {
readonly filterTextChangeEvent: Event<string | undefined>;
readonly install: ({ item, version }: { item: T, version: Installable.Version }) => Promise<void>;
readonly uninstall: ({ item }: { item: T }) => Promise<void>;
readonly messageService: MessageService;
readonly commandService: CommandService;
}

export interface State<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Deferred } from '@theia/core/lib/common/promise-util';
import { Emitter } from '@theia/core/lib/common/event';
import { MaybePromise } from '@theia/core/lib/common/types';
import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget';
import { CommandService } from '@theia/core/lib/common/command';
import { MessageService } from '@theia/core/lib/common/message-service';
import { Installable } from '../../../common/protocol/installable';
import { Searchable } from '../../../common/protocol/searchable';
import { ArduinoComponent } from '../../../common/protocol/arduino-component';
Expand All @@ -15,6 +17,12 @@ import { NotificationCenter } from '../../notification-center';
@injectable()
export abstract class ListWidget<T extends ArduinoComponent> extends ReactWidget {

@inject(MessageService)
protected readonly messageService: MessageService;

@inject(CommandService)
protected readonly commandService: CommandService;

@inject(NotificationCenter)
protected readonly notificationCenter: NotificationCenter;

Expand Down Expand Up @@ -87,7 +95,9 @@ export abstract class ListWidget<T extends ArduinoComponent> extends ReactWidget
uninstall={this.uninstall.bind(this)}
itemLabel={this.options.itemLabel}
itemRenderer={this.options.itemRenderer}
filterTextChangeEvent={this.filterTextChangeEmitter.event} />;
filterTextChangeEvent={this.filterTextChangeEmitter.event}
messageService={this.messageService}
commandService={this.commandService} />;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion arduino-ide-extension/src/node/boards-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ export class BoardsServiceImpl extends CoreClientAware implements BoardsService
});
await new Promise<void>((resolve, reject) => {
resp.on('end', resolve);
resp.on('error', reject);
resp.on('error', error => {
this.outputService.append({ chunk: `Failed to install platform: ${item.id}.\n` });
this.outputService.append({ chunk: error.toString() });
reject(error);
});
});

const items = await this.search({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ export class LibraryServiceImpl extends CoreClientAware implements LibraryServic
});
await new Promise<void>((resolve, reject) => {
resp.on('end', resolve);
resp.on('error', reject);
resp.on('error', error => {
this.outputService.append({ chunk: `Failed to install library: ${item.name}${version ? `:${version}` : ''}.\n` });
this.outputService.append({ chunk: error.toString() });
reject(error);
});
});

const items = await this.search({});
Expand Down