Skip to content

Commit

Permalink
fix: show notification if lib/core install failed
Browse files Browse the repository at this point in the history
Closes #621

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta authored and kittaakos committed May 11, 2023
1 parent 36e2092 commit 278dd4b
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ import { MessageService } from '@theia/core/lib/common/message-service';
import { ConfirmDialog } from '@theia/core/lib/browser/dialogs';
import { Searchable } from '../../../common/protocol/searchable';
import { ExecuteWithProgress } from '../../../common/protocol/progressible';
import { Installable } from '../../../common/protocol/installable';
import {
Installable,
libraryInstallFailed,
platformInstallFailed,
} from '../../../common/protocol/installable';
import { ArduinoComponent } from '../../../common/protocol/arduino-component';
import { SearchBar } from './search-bar';
import { ListWidget } from './list-widget';
import { ComponentList } from './component-list';
import { ListItemRenderer } from './list-item-renderer';
import { ResponseServiceClient } from '../../../common/protocol';
import {
LibraryPackage,
ResponseServiceClient,
} from '../../../common/protocol';
import { nls } from '@theia/core/lib/common';
import { FilterRenderer } from './filter-renderer';
import { DisposableCollection } from '@theia/core/lib/common/disposable';
Expand Down Expand Up @@ -130,13 +137,24 @@ export class FilterableListContainer<
}

private async install(item: T, version: Installable.Version): Promise<void> {
const { install, searchable } = this.props;
const { install, searchable, messageService } = this.props;
const { name } = item;
await ExecuteWithProgress.doWithProgress({
...this.props,
progressText:
nls.localize('arduino/common/processing', 'Processing') +
` ${item.name}:${version}`,
run: ({ progressId }) => install({ item, progressId, version }),
` ${name}:${version}`,
run: async ({ progressId }) => {
try {
await install({ item, progressId, version });
} catch (err) {
const message = LibraryPackage.is(item) // TODO: this dispatch does not belong here
? libraryInstallFailed(name, version)
: platformInstallFailed(name, version);
const cause = err instanceof Error ? err.message : String(err);
messageService.error(`${message} ${cause}`);
}
},
});
const items = await searchable.search(this.state.searchOptions);
this.setState({ items, edited: undefined });
Expand Down
29 changes: 28 additions & 1 deletion arduino-ide-extension/src/common/protocol/installable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { MessageService } from '@theia/core/lib/common/message-service';
import { nls } from '@theia/core/lib/common/nls';
import {
coerce as coerceSemver,
compare as compareSemver,
Expand All @@ -9,6 +10,32 @@ import type { ArduinoComponent } from './arduino-component';
import { ExecuteWithProgress } from './progressible';
import type { ResponseServiceClient } from './response-service';

export function libraryInstallFailed(
name: string,
version?: string | undefined
): string {
const versionSuffix = version ? `:${version}` : '';
return nls.localize(
'arduino/installable/libraryInstallFailed',
"Failed to install library: '{0}{1}'.",
name,
versionSuffix
);
}

export function platformInstallFailed(
name: string,
version?: string | undefined
): string {
const versionSuffix = version ? `:${version}` : '';
return nls.localize(
'arduino/installable/platformInstallFailed',
"Failed to install platform: '{0}{1}'.",
name,
versionSuffix
);
}

export interface Installable<T extends ArduinoComponent> {
/**
* If `options.version` is specified, that will be installed. Otherwise, `item.availableVersions[0]`.
Expand Down Expand Up @@ -62,7 +89,7 @@ export namespace Installable {
'remove',
'unknown',
] as const;
export type Action = typeof ActionLiterals[number];
export type Action = (typeof ActionLiterals)[number];

export function action(params: {
installed?: Version | undefined;
Expand Down
3 changes: 2 additions & 1 deletion arduino-ide-extension/src/node/boards-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
BoardSearch,
sortComponents,
SortGroup,
platformInstallFailed,
} from '../common/protocol';
import {
PlatformInstallRequest,
Expand Down Expand Up @@ -474,7 +475,7 @@ export class BoardsServiceImpl
});
resp.on('error', (error) => {
this.responseService.appendToOutput({
chunk: `Failed to install platform: ${item.id}.\n`,
chunk: `${platformInstallFailed(item.id, version)}\n`,
});
this.responseService.appendToOutput({
chunk: `${error.toString()}\n`,
Expand Down
17 changes: 12 additions & 5 deletions arduino-ide-extension/src/node/library-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
sortComponents,
SortGroup,
} from '../common/protocol';
import { Installable } from '../common/protocol/installable';
import {
Installable,
libraryInstallFailed,
} from '../common/protocol/installable';
import {
LibraryDependency,
LibraryLocation,
Expand All @@ -34,6 +37,7 @@ import {
} from './cli-protocol/cc/arduino/cli/commands/v1/lib_pb';
import { CoreClientAware } from './core-client-provider';
import { ExecuteWithProgress } from './grpc-progressible';
import { ServiceError } from './service-error';

@injectable()
export class LibraryServiceImpl
Expand Down Expand Up @@ -272,7 +276,12 @@ export class LibraryServiceImpl
(resolve, reject) => {
client.libraryResolveDependencies(req, (error, resp) => {
if (error) {
reject(error);
console.error('Failed to list library dependencies', error);
// If a gRPC service error, it removes the code and the number to provider more readable error message to the user.
const unwrappedError = ServiceError.is(error)
? new Error(error.details)
: error;
reject(unwrappedError);
return;
}
resolve(
Expand Down Expand Up @@ -344,9 +353,7 @@ export class LibraryServiceImpl
});
resp.on('error', (error) => {
this.responseService.appendToOutput({
chunk: `Failed to install library: ${item.name}${
version ? `:${version}` : ''
}.\n`,
chunk: `${libraryInstallFailed(item.name, version)}\n`,
});
this.responseService.appendToOutput({
chunk: `${error.toString()}\n`,
Expand Down
4 changes: 4 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@
"updateAvailable": "Update Available",
"versionDownloaded": "Arduino IDE {0} has been downloaded."
},
"installable": {
"libraryInstallFailed": "Failed to install library: '{0}{1}'.",
"platformInstallFailed": "Failed to install platform: '{0}{1}'."
},
"library": {
"addZip": "Add .ZIP Library...",
"arduinoLibraries": "Arduino libraries",
Expand Down

0 comments on commit 278dd4b

Please sign in to comment.