mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
vscode: replaced DownloadFileError with NestedError itself for simplicity
This commit is contained in:
parent
a3febc1c57
commit
da6ae3b6e0
1 changed files with 7 additions and 6 deletions
|
@ -7,8 +7,6 @@ import { NestedError } from "ts-nested-error";
|
|||
|
||||
const pipeline = util.promisify(stream.pipeline);
|
||||
|
||||
class DownloadFileError extends NestedError {}
|
||||
|
||||
/**
|
||||
* Downloads file from `url` and stores it at `destFilePath` with `destFilePermissions`.
|
||||
* `onProgress` callback is called on recieveing each chunk of bytes
|
||||
|
@ -21,13 +19,13 @@ export async function downloadFile(
|
|||
destFilePermissions: number,
|
||||
onProgress: (readBytes: number, totalBytes: number) => void
|
||||
): Promise<void> {
|
||||
const res = await fetch(url).catch(DownloadFileError.rethrow("Failed at initial fetch"));
|
||||
const res = await fetch(url).catch(NestedError.rethrow("Failed at initial fetch"));
|
||||
|
||||
if (!res.ok) {
|
||||
console.log("Error", res.status, "while downloading file from", url);
|
||||
console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 });
|
||||
|
||||
throw new DownloadFileError(`Got response ${res.status}`);
|
||||
throw new NestedError(`Got response ${res.status}`);
|
||||
}
|
||||
|
||||
const totalBytes = Number(res.headers.get('content-length'));
|
||||
|
@ -43,9 +41,12 @@ export async function downloadFile(
|
|||
|
||||
const destFileStream = fs.createWriteStream(destFilePath, { mode: destFilePermissions });
|
||||
|
||||
await pipeline(res.body, destFileStream).catch(DownloadFileError.rethrow("Piping file error"));
|
||||
await pipeline(res.body, destFileStream).catch(NestedError.rethrow("Piping file error"));
|
||||
return new Promise<void>(resolve => {
|
||||
destFileStream.on("close", resolve); // details on workaround: https://github.com/rust-analyzer/rust-analyzer/pull/3092#discussion_r378191131
|
||||
destFileStream.on("close", resolve);
|
||||
destFileStream.destroy();
|
||||
|
||||
// Details on workaround: https://github.com/rust-analyzer/rust-analyzer/pull/3092#discussion_r378191131
|
||||
// Issue at nodejs repo: https://github.com/nodejs/node/issues/31776
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue