diff --git a/src/api-binder.ts b/src/api-binder.ts index 032f0633..a953a0f5 100644 --- a/src/api-binder.ts +++ b/src/api-binder.ts @@ -17,6 +17,7 @@ import { ContractValidationError, ContractViolationError, InternalInconsistencyError, + TargetStateError, } from './lib/errors'; import * as request from './lib/request'; @@ -186,7 +187,8 @@ export async function start() { function handleTargetUpdateError(err: any) { if ( err instanceof ContractValidationError || - err instanceof ContractViolationError + err instanceof ContractViolationError || + err instanceof TargetStateError ) { log.error(`Could not store target state for device: ${err}`); // the dashboard does not display lines correctly, diff --git a/src/device-state.ts b/src/device-state.ts index 33df4b56..0c5c9a4c 100644 --- a/src/device-state.ts +++ b/src/device-state.ts @@ -22,7 +22,11 @@ import * as globalEventBus from './event-bus'; import * as hostConfig from './host-config'; import constants = require('./lib/constants'); import * as dbus from './lib/dbus'; -import { InternalInconsistencyError, UpdatesLockedError } from './lib/errors'; +import { + InternalInconsistencyError, + TargetStateError, + UpdatesLockedError, +} from './lib/errors'; import * as updateLock from './lib/update-lock'; import * as validation from './lib/validation'; import * as network from './network'; @@ -52,7 +56,7 @@ function parseTargetState(state: unknown): TargetState { } const errors = ['Invalid target state.'].concat(Reporter.report(res)); - throw new Error(errors.join('\n')); + throw new TargetStateError(errors.join('\n')); } // TODO (refactor): This shouldn't be here, and instead should be part of the other diff --git a/src/lib/errors.ts b/src/lib/errors.ts index 38692d06..b4ab2155 100644 --- a/src/lib/errors.ts +++ b/src/lib/errors.ts @@ -81,6 +81,8 @@ export class ConfigurationValidationError extends TypedError { export class ImageAuthenticationError extends TypedError {} +export class TargetStateError extends TypedError {} + /** * An error thrown if our own container cannot be inspected. * See LocalModeManager for a usage example.