Skip to content
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
21 changes: 12 additions & 9 deletions modules/tool/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,20 @@ export async function downloadTool(objectName: string) {
const filepath = path.join(uploadPath, filename);

try {
await pipeline(await pluginFileS3Server.getFile(objectName), createWriteStream(filepath));

const toolId = await extractToolIdFromFile(filepath);
if (!toolId) return Promise.reject('Failed to extract toolId from file');

return toolId;
} catch (error) {
// clean the undownloaded file
await pipeline(await pluginFileS3Server.getFile(objectName), createWriteStream(filepath)).catch(
(err) => {
addLog.warn(`Download plugin file: ${objectName} from S3 error: ${getErrText(err)}`);
return Promise.reject(err);
}
);
const toolId = await extractToolIdFromFile(filepath).catch((err) => {
addLog.warn(`Can not parse the tool file: ${filepath}, ${getErrText(err)}`);
return Promise.reject(err);
});
addLog.debug(`Downloaded tool: ${toolId}`);
} catch {
if (fs.existsSync(filepath)) {
await fs.promises.unlink(filepath);
}
addLog.error(`Failed to download/install plugin:`, getErrText(error));
}
}
2 changes: 1 addition & 1 deletion src/utils/catch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @param fn
* @returns [result, error]
*/
export async function catchError<T>(fn: () => T): Promise<[T | null, unknown]> {
export async function catchError<T>(fn: () => T): Promise<[Awaited<T> | null, unknown]> {
try {
return [await fn(), null];
} catch (e) {
Expand Down