mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-31 00:23:57 +00:00
Remove unnecessary check for docker status code
This commit is contained in:
parent
c6f911c36b
commit
f7bc30a310
@ -17,6 +17,7 @@ import {
|
||||
InternalInconsistencyError,
|
||||
NotFoundError,
|
||||
StatusCodeError,
|
||||
isStatusError,
|
||||
} from '../lib/errors';
|
||||
import * as LogTypes from '../lib/log-types';
|
||||
import { checkInt, isValidDeviceName } from '../lib/validation';
|
||||
@ -312,51 +313,31 @@ export async function start(service: Service) {
|
||||
|
||||
reportNewStatus(containerId, service, 'Starting' as ServiceStatus);
|
||||
|
||||
let shouldRemove = false;
|
||||
let err: Error | undefined;
|
||||
try {
|
||||
await container.start();
|
||||
} catch (e) {
|
||||
// Get the statusCode from the original cause and make sure it's
|
||||
// definitely an int for comparison reasons
|
||||
// QUESTION: does this ever happen?
|
||||
const maybeStatusCode = PermissiveNumber.decode(e.statusCode);
|
||||
if (isLeft(maybeStatusCode)) {
|
||||
shouldRemove = true;
|
||||
err = new Error(`Could not parse status code from docker error: ${e}`);
|
||||
throw err;
|
||||
if (!isStatusError(e)) {
|
||||
throw e;
|
||||
}
|
||||
const statusCode = maybeStatusCode.right;
|
||||
const message = e.message;
|
||||
|
||||
const { statusCode, message } = e;
|
||||
|
||||
// 304 means the container was already started, precisely what we want
|
||||
if (statusCode === 304) {
|
||||
alreadyStarted = true;
|
||||
} else if (
|
||||
statusCode === 500 &&
|
||||
_.isString(message) &&
|
||||
message.trim().match(/exec format error$/)
|
||||
) {
|
||||
// Provide a friendlier error message for "exec format error"
|
||||
const deviceType = await config.get('deviceType');
|
||||
err = new Error(
|
||||
throw new Error(
|
||||
`Application architecture incompatible with ${deviceType}: exec format error`,
|
||||
);
|
||||
throw err;
|
||||
} else {
|
||||
// rethrow the same error
|
||||
err = e;
|
||||
// rethrow the top-level error
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
if (shouldRemove) {
|
||||
// If starting the container fialed, we remove it so that it doesn't litter
|
||||
await container.remove({ v: true }).catch(_.noop);
|
||||
logger.logSystemEvent(LogTypes.startServiceError, {
|
||||
service,
|
||||
error: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const serviceId = service.serviceId;
|
||||
|
@ -19,6 +19,9 @@ export class StatusError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export const isStatusError = (x: unknown): x is StatusError =>
|
||||
x != null && x instanceof Error && !isNaN((x as any).statusCode);
|
||||
|
||||
interface CodedSysError extends Error {
|
||||
code?: string;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user