Skip to content

Commit 278dd4b

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
fix: show notification if lib/core install failed
Closes #621 Signed-off-by: Akos Kitta <[email protected]>
1 parent 36e2092 commit 278dd4b

File tree

5 files changed

+69
-12
lines changed

5 files changed

+69
-12
lines changed

Diff for: arduino-ide-extension/src/browser/widgets/component-list/filterable-list-container.tsx

+23-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ import { MessageService } from '@theia/core/lib/common/message-service';
66
import { ConfirmDialog } from '@theia/core/lib/browser/dialogs';
77
import { Searchable } from '../../../common/protocol/searchable';
88
import { ExecuteWithProgress } from '../../../common/protocol/progressible';
9-
import { Installable } from '../../../common/protocol/installable';
9+
import {
10+
Installable,
11+
libraryInstallFailed,
12+
platformInstallFailed,
13+
} from '../../../common/protocol/installable';
1014
import { ArduinoComponent } from '../../../common/protocol/arduino-component';
1115
import { SearchBar } from './search-bar';
1216
import { ListWidget } from './list-widget';
1317
import { ComponentList } from './component-list';
1418
import { ListItemRenderer } from './list-item-renderer';
15-
import { ResponseServiceClient } from '../../../common/protocol';
19+
import {
20+
LibraryPackage,
21+
ResponseServiceClient,
22+
} from '../../../common/protocol';
1623
import { nls } from '@theia/core/lib/common';
1724
import { FilterRenderer } from './filter-renderer';
1825
import { DisposableCollection } from '@theia/core/lib/common/disposable';
@@ -130,13 +137,24 @@ export class FilterableListContainer<
130137
}
131138

132139
private async install(item: T, version: Installable.Version): Promise<void> {
133-
const { install, searchable } = this.props;
140+
const { install, searchable, messageService } = this.props;
141+
const { name } = item;
134142
await ExecuteWithProgress.doWithProgress({
135143
...this.props,
136144
progressText:
137145
nls.localize('arduino/common/processing', 'Processing') +
138-
` ${item.name}:${version}`,
139-
run: ({ progressId }) => install({ item, progressId, version }),
146+
` ${name}:${version}`,
147+
run: async ({ progressId }) => {
148+
try {
149+
await install({ item, progressId, version });
150+
} catch (err) {
151+
const message = LibraryPackage.is(item) // TODO: this dispatch does not belong here
152+
? libraryInstallFailed(name, version)
153+
: platformInstallFailed(name, version);
154+
const cause = err instanceof Error ? err.message : String(err);
155+
messageService.error(`${message} ${cause}`);
156+
}
157+
},
140158
});
141159
const items = await searchable.search(this.state.searchOptions);
142160
this.setState({ items, edited: undefined });

Diff for: arduino-ide-extension/src/common/protocol/installable.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { MessageService } from '@theia/core/lib/common/message-service';
2+
import { nls } from '@theia/core/lib/common/nls';
23
import {
34
coerce as coerceSemver,
45
compare as compareSemver,
@@ -9,6 +10,32 @@ import type { ArduinoComponent } from './arduino-component';
910
import { ExecuteWithProgress } from './progressible';
1011
import type { ResponseServiceClient } from './response-service';
1112

13+
export function libraryInstallFailed(
14+
name: string,
15+
version?: string | undefined
16+
): string {
17+
const versionSuffix = version ? `:${version}` : '';
18+
return nls.localize(
19+
'arduino/installable/libraryInstallFailed',
20+
"Failed to install library: '{0}{1}'.",
21+
name,
22+
versionSuffix
23+
);
24+
}
25+
26+
export function platformInstallFailed(
27+
name: string,
28+
version?: string | undefined
29+
): string {
30+
const versionSuffix = version ? `:${version}` : '';
31+
return nls.localize(
32+
'arduino/installable/platformInstallFailed',
33+
"Failed to install platform: '{0}{1}'.",
34+
name,
35+
versionSuffix
36+
);
37+
}
38+
1239
export interface Installable<T extends ArduinoComponent> {
1340
/**
1441
* If `options.version` is specified, that will be installed. Otherwise, `item.availableVersions[0]`.
@@ -62,7 +89,7 @@ export namespace Installable {
6289
'remove',
6390
'unknown',
6491
] as const;
65-
export type Action = typeof ActionLiterals[number];
92+
export type Action = (typeof ActionLiterals)[number];
6693

6794
export function action(params: {
6895
installed?: Version | undefined;

Diff for: arduino-ide-extension/src/node/boards-service-impl.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
BoardSearch,
1919
sortComponents,
2020
SortGroup,
21+
platformInstallFailed,
2122
} from '../common/protocol';
2223
import {
2324
PlatformInstallRequest,
@@ -474,7 +475,7 @@ export class BoardsServiceImpl
474475
});
475476
resp.on('error', (error) => {
476477
this.responseService.appendToOutput({
477-
chunk: `Failed to install platform: ${item.id}.\n`,
478+
chunk: `${platformInstallFailed(item.id, version)}\n`,
478479
});
479480
this.responseService.appendToOutput({
480481
chunk: `${error.toString()}\n`,

Diff for: arduino-ide-extension/src/node/library-service-impl.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import {
88
sortComponents,
99
SortGroup,
1010
} from '../common/protocol';
11-
import { Installable } from '../common/protocol/installable';
11+
import {
12+
Installable,
13+
libraryInstallFailed,
14+
} from '../common/protocol/installable';
1215
import {
1316
LibraryDependency,
1417
LibraryLocation,
@@ -34,6 +37,7 @@ import {
3437
} from './cli-protocol/cc/arduino/cli/commands/v1/lib_pb';
3538
import { CoreClientAware } from './core-client-provider';
3639
import { ExecuteWithProgress } from './grpc-progressible';
40+
import { ServiceError } from './service-error';
3741

3842
@injectable()
3943
export class LibraryServiceImpl
@@ -272,7 +276,12 @@ export class LibraryServiceImpl
272276
(resolve, reject) => {
273277
client.libraryResolveDependencies(req, (error, resp) => {
274278
if (error) {
275-
reject(error);
279+
console.error('Failed to list library dependencies', error);
280+
// If a gRPC service error, it removes the code and the number to provider more readable error message to the user.
281+
const unwrappedError = ServiceError.is(error)
282+
? new Error(error.details)
283+
: error;
284+
reject(unwrappedError);
276285
return;
277286
}
278287
resolve(
@@ -344,9 +353,7 @@ export class LibraryServiceImpl
344353
});
345354
resp.on('error', (error) => {
346355
this.responseService.appendToOutput({
347-
chunk: `Failed to install library: ${item.name}${
348-
version ? `:${version}` : ''
349-
}.\n`,
356+
chunk: `${libraryInstallFailed(item.name, version)}\n`,
350357
});
351358
this.responseService.appendToOutput({
352359
chunk: `${error.toString()}\n`,

Diff for: i18n/en.json

+4
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@
278278
"updateAvailable": "Update Available",
279279
"versionDownloaded": "Arduino IDE {0} has been downloaded."
280280
},
281+
"installable": {
282+
"libraryInstallFailed": "Failed to install library: '{0}{1}'.",
283+
"platformInstallFailed": "Failed to install platform: '{0}{1}'."
284+
},
281285
"library": {
282286
"addZip": "Add .ZIP Library...",
283287
"arduinoLibraries": "Arduino libraries",

0 commit comments

Comments
 (0)