Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling for downloads #6673

Merged
merged 1 commit into from
Mar 7, 2025
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
15 changes: 15 additions & 0 deletions extensions/positron-python/scripts/install-pet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,27 @@ async function downloadAndReplacePet(version: string, githubPat: string | undefi
}
let binaryData = Buffer.alloc(0);

// Ensure we got a 200 response on the final request.
if (dlResponse.statusCode !== 200) {
throw new Error(`Failed to download Pet: HTTP ${dlResponse.statusCode}`);
}

dlResponse.on('data', (chunk: any) => {
binaryData = Buffer.concat([binaryData, chunk]);
});
dlResponse.on('end', async () => {
const extensionParent = path.dirname(__dirname);
const petDir = path.join(extensionParent, 'python-env-tools');

// Ensure we got some bytes. Less than 1024 bytes is probably
// an error; none of our assets are under 1mb
if (binaryData.length < 1024) {
// Log the data we did get
console.error(binaryData.toString('utf-8'));
throw new Error(
`Binary data is too small (${binaryData.length} bytes); download probably failed.`);
}

// Create the resources/pet directory if it doesn't exist.
if (!(await existsAsync(petDir))) {
await fs.promises.mkdir(petDir);
Expand Down
14 changes: 14 additions & 0 deletions extensions/positron-r/scripts/install-kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,26 @@ async function downloadAndReplaceArk(version: string,
}
let binaryData = Buffer.alloc(0);

// Ensure we got a 200 response on the final request.
if (dlResponse.statusCode !== 200) {
throw new Error(`Failed to download Ark: HTTP ${dlResponse.statusCode}`);
}

dlResponse.on('data', (chunk: any) => {
binaryData = Buffer.concat([binaryData, chunk]);
});
dlResponse.on('end', async () => {
const arkDir = path.join('resources', 'ark');

// Ensure we got some bytes. Less than 1024 bytes is probably
// an error; none of our assets are under 1mb
if (binaryData.length < 1024) {
// Log the data we did get
console.error(binaryData.toString('utf-8'));
throw new Error(
`Binary data is too small (${binaryData.length} bytes); download probably failed.`);
}

// Create the resources/ark directory if it doesn't exist.
if (!await existsAsync(arkDir)) {
await fs.promises.mkdir(arkDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,26 @@ async function downloadAndReplaceKallichore(version: string,
}
let binaryData = Buffer.alloc(0);

// Ensure we got a 200 response on the final request.
if (dlResponse.statusCode !== 200) {
throw new Error(`Failed to download Kallichore: HTTP ${dlResponse.statusCode}`);
}

dlResponse.on('data', (chunk: any) => {
binaryData = Buffer.concat([binaryData, chunk]);
});
dlResponse.on('end', async () => {
const kallichoreDir = path.join('resources', 'kallichore');

// Ensure we got some bytes. Less than 1024 bytes is probably
// an error; none of our assets are under 1mb
if (binaryData.length < 1024) {
// Log the data we did get
console.error(binaryData.toString('utf-8'));
throw new Error(
`Binary data is too small (${binaryData.length} bytes); download probably failed.`);
}

// Create the resources/kallichore directory if it doesn't exist.
if (!await existsAsync(kallichoreDir)) {
await fs.promises.mkdir(kallichoreDir);
Expand Down
Loading