Fix some more crashes

This commit is contained in:
Girish Ramakrishnan
2021-08-26 18:34:32 -07:00
parent f5c169f881
commit 7413ccd22e
2 changed files with 16 additions and 20 deletions

View File

@@ -493,13 +493,12 @@ async function stopContainers(appId) {
}
}
function deleteImage(manifest, callback) {
async function deleteImage(manifest) {
assert(!manifest || typeof manifest === 'object');
assert.strictEqual(typeof callback, 'function');
const dockerImage = manifest ? manifest.dockerImage : null;
if (!dockerImage) return callback(null);
if (dockerImage.includes('//')) return callback(null); // a common mistake is to paste a https:// as docker image. this results in a crash at runtime in dockerode module
if (!dockerImage) return;
if (dockerImage.includes('//')) return; // a common mistake is to paste a https:// as docker image. this results in a crash at runtime in dockerode module
const removeOptions = {
force: false, // might be shared with another instance of this app
@@ -509,18 +508,15 @@ function deleteImage(manifest, callback) {
// registry v1 used to pull down all *tags*. this meant that deleting image by tag was not enough (since that
// just removes the tag). we used to remove the image by id. this is not required anymore because aliases are
// not created anymore after https://github.com/docker/docker/pull/10571
gConnection.getImage(dockerImage).remove(removeOptions, function (error) {
if (error && error.statusCode === 400) return callback(null); // invalid image format. this can happen if user installed with a bad --docker-image
if (error && error.statusCode === 404) return callback(null); // not found
if (error && error.statusCode === 409) return callback(null); // another container using the image
const [error] = await safe(gConnection.getImage(dockerImage).remove(removeOptions));
if (error && error.statusCode === 400) return; // invalid image format. this can happen if user installed with a bad --docker-image
if (error && error.statusCode === 404) return; // not found
if (error && error.statusCode === 409) return; // another container using the image
if (error) {
debug('Error removing image %s : %j', dockerImage, error);
return callback(new BoxError(BoxError.DOCKER_ERROR, error));
}
callback(null);
});
if (error) {
debug('Error removing image %s : %j', dockerImage, error);
throw new BoxError(BoxError.DOCKER_ERROR, error);
}
}
async function inspect(containerId) {