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

View file

@ -26,7 +26,7 @@ return strict("Config", {
isDevBuild = isDevBuild, isDevBuild = isDevBuild,
codename = "Epiphany", codename = "Epiphany",
version = realVersion, 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, protocolVersion = 6,
defaultHost = "localhost", defaultHost = "localhost",
defaultPort = "34873", defaultPort = "34873",