Skip to content
26 changes: 22 additions & 4 deletions packages/controller/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ interface SendResponseToOptions {
payload: Record<string, unknown>;
}

/**
* Error class for adapter not found dependency issues
*/
class AdapterNotFoundError extends Error {}

/**
* Error class for adapter version mismatch dependency issues
*/
class AdapterVersionMismatchError extends Error {}

/** Host information including host id and running version */
type HostInformation = ioBroker.HostCommon & { host: string; runningVersion: string };

Expand Down Expand Up @@ -3285,7 +3295,7 @@ function checkVersion(name: string, version: string, instances: Record<string, i
// Check only a version
if (version) {
if (!semver.satisfies(ioPackage.common.version, version, { includePrerelease: true })) {
throw new Error(
throw new AdapterVersionMismatchError(
`Invalid version of "${name}". Installed "${ioPackage.common.version}", required "${version}"`,
);
} else {
Expand All @@ -3303,7 +3313,7 @@ function checkVersion(name: string, version: string, instances: Record<string, i
);
for (const inst of filteredInst) {
if (version && !semver.satisfies(instances[inst].common.version, version, { includePrerelease: true })) {
throw new Error(
throw new AdapterVersionMismatchError(
`required adapter "${name}" has wrong version. Installed "${instances[inst].common.version}", required "${version}"!`,
);
}
Expand All @@ -3312,7 +3322,7 @@ function checkVersion(name: string, version: string, instances: Record<string, i
}

if (!isFound) {
throw new Error(`required adapter "${name}" not found!`);
throw new AdapterNotFoundError(`required adapter "${name}" not found!`);
}
}

Expand Down Expand Up @@ -3365,7 +3375,15 @@ async function checkVersions(id: string, deps?: Dependencies, globalDeps?: Depen
}
} catch (e) {
logger.debug(`${hostLogPrefix} ${id} [globalDependency]: ${JSON.stringify(globalDeps)}`);
throw new Error(`Adapter dependency not fulfilled on any host: ${e.message}`);

if (e instanceof AdapterNotFoundError) {
throw new Error(`Adapter required by dependency not installed: ${e.message}`);
} else if (e instanceof AdapterVersionMismatchError) {
throw new Error(`Adapter dependency not fulfilled on all hosts where adapter is installed: ${e.message}`);
} else {
// fallback for any other errors
throw new Error(`Adapter dependency not fulfilled: ${e.message}`);
}
}
}

Expand Down
Loading