Skip to content

Commit cd9719e

Browse files
author
Alberto Iannaccone
committed
refine platforms and libraries initialization in case of errors
1 parent 1b214e7 commit cd9719e

File tree

1 file changed

+55
-9
lines changed

1 file changed

+55
-9
lines changed

arduino-ide-extension/src/browser/contributions/init-libs-platforms.ts

+55-9
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,81 @@ export class InitLibsPlatforms extends Contribution {
1717
InitLibsPlatforms.INIT_LIBS_AND_PACKAGES
1818
));
1919
if (isFirstStartup) {
20-
await this.localStorageService.setData(
21-
InitLibsPlatforms.INIT_LIBS_AND_PACKAGES,
22-
true
23-
);
2420
const avrPackage = await this.boardsService.getBoardPackage({
2521
id: 'arduino:avr',
2622
});
2723
const builtInLibrary = (
28-
await this.libraryService.search({
29-
query: 'Arduino_BuiltIn',
30-
})
24+
await this.libraryService.search({ query: 'Arduino_BuiltIn' })
3125
)[0];
3226

27+
let avrPackageError: Error | undefined;
28+
let builtInLibraryError: Error | undefined;
29+
3330
if (avrPackage) {
3431
try {
3532
await this.boardsService.install({
3633
item: avrPackage,
3734
noOverwrite: true, // We don't want to automatically replace custom platforms the user might already have in place
3835
});
39-
} catch {} // If this fails, we still want to install the libraries
36+
} catch (e) {
37+
// There's no error code, I need to parse the error message: https://github.com/arduino/arduino-cli/commit/ffe4232b359fcfa87238d68acf1c3b64a1621f14#diff-10ffbdde46838dd9caa881fd1f2a5326a49f8061f6cfd7c9d430b4875a6b6895R62
38+
if (
39+
e.message.includes(
40+
`Platform ${avrPackage.id}@${avrPackage.installedVersion} already installed`
41+
)
42+
) {
43+
// If arduino:avr installation fails because it's already installed we don't want to retry on next start-up
44+
console.error(e);
45+
} else {
46+
// But if there is any other error (e.g.: no interntet cconnection), we want to retry next time
47+
avrPackageError = e;
48+
}
49+
}
50+
} else {
51+
avrPackageError = new Error('Could not find platform.');
4052
}
53+
4154
if (builtInLibrary) {
4255
try {
4356
await this.libraryService.install({
4457
item: builtInLibrary,
4558
installDependencies: true,
4659
noOverwrite: true, // We don't want to automatically replace custom libraries the user might already have in place
4760
});
48-
} catch {}
61+
} catch (e) {
62+
// There's no error code, I need to parse the error message: https://github.com/arduino/arduino-cli/commit/2ea3608453b17b1157f8a1dc892af2e13e40f4f0#diff-1de7569144d4e260f8dde0e0d00a4e2a218c57966d583da1687a70d518986649R95
63+
if (
64+
e.message.includes(
65+
`Library ${builtInLibrary.name} is already installed`
66+
)
67+
) {
68+
// If Arduino_BuiltIn installation fails because it's already installed we don't want to retry on next start-up
69+
console.log('error installing core', e);
70+
} else {
71+
// But if there is any other error (e.g.: no interntet cconnection), we want to retry next time
72+
builtInLibraryError = e;
73+
}
74+
}
75+
} else {
76+
builtInLibraryError = new Error('Could not find library');
77+
}
78+
79+
if (avrPackageError) {
80+
this.messageService.error(
81+
`Could not install Arduino AVR platform: ${avrPackageError}`
82+
);
83+
}
84+
if (builtInLibraryError) {
85+
this.messageService.error(
86+
`Could not install ${builtInLibrary.name} library: ${builtInLibraryError}`
87+
);
88+
}
89+
90+
if (!avrPackageError && !builtInLibraryError) {
91+
await this.localStorageService.setData(
92+
InitLibsPlatforms.INIT_LIBS_AND_PACKAGES,
93+
true
94+
);
4995
}
5096
}
5197
}

0 commit comments

Comments
 (0)