Refactor version rejection logic in ApiContext

- Renamed the `rejectWrongProtocolVersion` function to `rejectWrongVersion` for clarity.
- Enhanced version mismatch handling by providing detailed error messages when the plugin and server versions do not match.
- Updated the expected server version format in the configuration to include the patch version, ensuring accurate version checks.

These changes improve error reporting and version management in the plugin's API context.
This commit is contained in:
Joe 2026-02-17 20:48:39 -06:00
parent 6c0098d839
commit dcd9253770
2 changed files with 22 additions and 14 deletions

View file

@ -24,20 +24,28 @@ local function rejectFailedRequests(response)
return response
end
local function rejectWrongProtocolVersion(infoResponseBody)
local function rejectWrongVersion(infoResponseBody)
local pluginVersion = Version.display(Config.version)
local serverVersion = infoResponseBody.serverVersion
if serverVersion ~= pluginVersion then
local message = (
"Found a server, but it's a different version than this plugin."
.. "\nThe Atlas plugin requires an exact version match with the server."
.. "\n\nYour plugin is version %s."
.. "\nYour server is version %s."
.. "\n\nPlease update your plugin or server so both are the same version."
):format(pluginVersion, serverVersion)
return Promise.reject(message)
end
if infoResponseBody.protocolVersion ~= Config.protocolVersion then
local message = (
"Found a server, but it's using a different protocol version, and is incompatible."
.. "\nMake sure you have matching versions of both the Atlas plugin and server!"
.. "\n\nYour client is version %s, with protocol version %s. It expects server version %s."
.. "\nYour server is version %s, with protocol version %s."
):format(
Version.display(Config.version),
Config.protocolVersion,
Config.expectedServerVersionString,
infoResponseBody.serverVersion,
infoResponseBody.protocolVersion
)
"Found a server with the same version, but a different protocol version."
.. "\nThis should not happen — please report this as a bug."
.. "\n\nPlugin protocol: %s, Server protocol: %s"
):format(Config.protocolVersion, infoResponseBody.protocolVersion)
return Promise.reject(message)
end
@ -159,7 +167,7 @@ function ApiContext:connect()
return Http.get(url)
:andThen(rejectFailedRequests)
:andThen(Http.Response.msgpack)
:andThen(rejectWrongProtocolVersion)
:andThen(rejectWrongVersion)
:andThen(rejectWrongFork)
:andThen(function(body)
assert(validateApiInfo(body))

View file

@ -26,7 +26,7 @@ return strict("Config", {
isDevBuild = isDevBuild,
codename = "Epiphany",
version = realVersion,
expectedServerVersionString = ("%d.%d or newer"):format(realVersion[1], realVersion[2]),
expectedServerVersionString = ("%d.%d.%d"):format(realVersion[1], realVersion[2], realVersion[3]),
protocolVersion = 6,
defaultHost = "localhost",
defaultPort = "34873",