From 67a010c586b3361e9306e3593859bdd9482cd490 Mon Sep 17 00:00:00 2001 From: Sebastian-Webster <84299475+Sebastian-Webster@users.noreply.github.com> Date: Fri, 6 Dec 2024 04:19:19 +1300 Subject: [PATCH] fix unsupported version message not showing up --- src/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1e60cf2..d105ae9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import Logger from './libraries/Logger' import * as os from 'node:os' import Executor from "./libraries/Executor" -import { satisfies, lt } from "semver" +import { satisfies, lt, coerce } from "semver" import { BinaryInfo, InternalServerOptions, ServerOptions } from '../types' import getBinaryURL from './libraries/Version' import MySQLVersions from './versions.json' @@ -57,6 +57,12 @@ export async function createDB(opts?: ServerOptions) { binaryInfo = getBinaryURL(MySQLVersions, options.version, options) logger.log('Using MySQL binary version:', binaryInfo.version, 'from URL:', binaryInfo.url) } catch (e) { + if (options.version && lt(coerce(options.version), MIN_SUPPORTED_MYSQL)) { + //The difference between the throw here and the throw above is this throw is because the selected "version" is not supported. + //The throw above is because the system-installed MySQL is out of date and "ignoreUnsupportedSystemVersion" is not set to true. + throw `The selected version of MySQL (${options.version}) is not currently supported by this package. Please choose a different version to use.` + } + logger.error(e) if (options.version) { throw `A MySQL version ${options.version} binary could not be found that supports your OS (${os.platform()} | ${os.version()} | ${os.release()}) and CPU architecture (${os.arch()}). Please check you have the latest version of mysql-memory-server. If the latest version still doesn't support the version you want to use, feel free to make a pull request to add support!` @@ -64,17 +70,11 @@ export async function createDB(opts?: ServerOptions) { throw `A MySQL binary could not be found that supports your OS (${os.platform()} | ${os.version()} | ${os.release()}) and CPU architecture (${os.arch()}). Please check you have the latest version of mysql-memory-server. If the latest version still doesn't support your OS and CPU architecture, feel free to make a pull request to add support!` } - if (lt(binaryInfo.version, MIN_SUPPORTED_MYSQL)) { - //The difference between the throw here and the throw above is this throw is because the selected "version" is not supported. - //The throw above is because the system-installed MySQL is out of date and "ignoreUnsupportedSystemVersion" is not set to true. - throw `The selected version of MySQL (${options.version}) is not currently supported by this package. Please choose a different version to use.` - } - try { binaryFilepath = await downloadBinary(binaryInfo, options, logger); } catch (error) { logger.error('Failed to download binary:', error) - throw `Failed to download binary. The error was: "${error}"` + throw `Failed to download binary. The error was: "${error}"` } logger.log('Running downloaded binary')