diff --git a/src/main/java/me/itzg/helpers/modrinth/ModrinthApiClient.java b/src/main/java/me/itzg/helpers/modrinth/ModrinthApiClient.java index f2ac807c..1dcacccf 100644 --- a/src/main/java/me/itzg/helpers/modrinth/ModrinthApiClient.java +++ b/src/main/java/me/itzg/helpers/modrinth/ModrinthApiClient.java @@ -17,6 +17,7 @@ import lombok.extern.slf4j.Slf4j; import me.itzg.helpers.errors.GenericException; import me.itzg.helpers.errors.InvalidParameterException; +import me.itzg.helpers.http.FailedRequestException; import me.itzg.helpers.http.Fetch; import me.itzg.helpers.http.FileDownloadedHandler; import me.itzg.helpers.http.SharedFetch; @@ -146,7 +147,11 @@ public Mono resolveProjectVersion(Project project, ProjectRef projectRe return getVersionsForProject(project.getId(), loaderToQuery, gameVersion) .mapNotNull(versions -> pickVersion(project, versions, projectRef.getVersionType())); } else if (projectRef.hasVersionId()) { - return getVersionFromId(projectRef.getVersionId()); + return getVersionFromId(projectRef.getVersionId()) + .onErrorMap(FailedRequestException::isNotFound, throwable -> + new InvalidParameterException(String.format("Version %s does not exist, requested for project %s", + projectRef.getVersionId(), project.getSlug())) + ); } else { return getVersionsForProject(project.getId(), loaderToQuery, gameVersion) .mapNotNull(versions -> pickVersion(project, versions, defaultVersionType)); diff --git a/src/test/java/me/itzg/helpers/modrinth/ModrinthCommandTest.java b/src/test/java/me/itzg/helpers/modrinth/ModrinthCommandTest.java index c53e457e..29032f76 100644 --- a/src/test/java/me/itzg/helpers/modrinth/ModrinthCommandTest.java +++ b/src/test/java/me/itzg/helpers/modrinth/ModrinthCommandTest.java @@ -1,5 +1,6 @@ package me.itzg.helpers.modrinth; +import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemErrNormalized; import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; @@ -225,6 +226,44 @@ void errorWhenNoApplicableVersion(@TempDir Path tempDir) { assertThat(exitCode).isNotEqualTo(ExitCode.OK); } + @Test + void handlesNotExistentVersionId(@TempDir Path tempDir) throws Exception { + stubFor( + get(urlPathMatching("/v2/projects")) + .withQueryParam("ids", equalTo("[\"lithium\"]")) + .willReturn(aResponse() + .withHeader("Content-Type", "application/json") + .withBodyFile("bulk-lithium.json") + ) + ); + + stubFor( + get(urlPathMatching("/v2/version/vWYoZjBF")) + .willReturn(aResponse() + .withStatus(404) + ) + ); + + final String out = tapSystemErrNormalized(() -> { + final int exitCode = new CommandLine( + new ModrinthCommand() + ) + .execute( + "--api-base-url", wm.getRuntimeInfo().getHttpBaseUrl(), + "--output-directory", tempDir.toString(), + "--game-version", "1.21.5", + "--loader", "fabric", + "--projects", "lithium:vWYoZjBF" + ); + + assertThat(exitCode).isNotEqualTo(ExitCode.OK); + }); + + assertThat(out) + .contains("InvalidParameterException") + .contains("Version vWYoZjBF does not exist"); + } + @ParameterizedTest @ValueSource(booleans = {true, false}) void handlesDatapacksSpecificVersion(boolean absoluteWorldDir, @TempDir Path tempDir) { diff --git a/src/test/resources/ModrinthCommandTest/__files/bulk-lithium.json b/src/test/resources/ModrinthCommandTest/__files/bulk-lithium.json new file mode 100644 index 00000000..100e8987 --- /dev/null +++ b/src/test/resources/ModrinthCommandTest/__files/bulk-lithium.json @@ -0,0 +1,193 @@ +[ + { + "client_side": "optional", + "server_side": "optional", + "game_versions": [ + "1.16.2", + "1.16.3", + "1.16.4", + "1.16.5", + "1.17", + "1.17.1", + "1.18", + "1.18.1", + "1.18.2", + "1.19", + "1.19.1", + "1.19.2", + "1.19.3", + "1.19.4", + "1.20", + "1.20.1", + "1.20.2", + "1.20.3", + "1.20.4", + "1.20.5", + "1.20.6", + "1.21", + "1.21.1", + "1.21.2", + "1.21.3", + "1.21.4", + "1.21.5" + ], + "id": "gvQqBUqZ", + "slug": "lithium", + "project_type": "mod", + "team": "peSx5UYg", + "organization": "LjcZDkRW", + "title": "Lithium", + "description": "No-compromises game logic optimization mod. Well suited for clients and servers of all kinds. Now available for Fabric and NeoForge!", + "body": "Lithium is a modern, general-purpose optimization mod for Minecraft which works to improve a number of systems (game physics, mob AI, block ticking, etc) with the goal of **not changing any vanilla mechanics**. \n\n
\n\nThe mod works **on both the client and server**, and can be installed on servers **without requiring clients to also have the mod** (and vice versa.)\n\n
\n\nFor multiplayer servers, administrators can expect a sizeable improvement to tick times, allowing their hardware to support more loaded entities, chunks, and players. Even in single-player, Lithium helps to improve performance by optimizing the internal game server, which is used for \"ticking\" the world. This can free up your computer's processor to focus on other tasks, resulting in **improved frame rates and increased responsiveness**. \n\n\n
\n\n\nThe strict goal of maintaining exact behavior with vanilla makes Lithium suitable for almost any Minecraft server running Fabric, even for highly complex gameplay scenarios and creations. In fact, our continued insistence towards not changing vanilla gameplay has even led to the mod being officially allowed in [Minecraft speedrunning](https://www.speedrun.com/mc).\n\n
\n\n## Installation\n\nMake sure you have the latest version of Fabric Loader present and then simply drop the mod into your mods folder. No other mods or additional setup (not even Fabric API!) is required. You do not need to create new worlds in order to take advantage of the mod.\n\n
\n\n\nWhile you're at it, you may want to check out [Sodium](https://modrinth.com/mod/sodium), which improves rendering performance.\n\n
\n\n## Configuration\n\nLithium makes use of an semi-unusual configuration system which allows you to enable or completely disable patches the mod applies. This system allows fine-grained control over what code in Minecraft is modified by Lithium, and as such, can be used to completely eliminate bugs or mod incompatibilities introduced by the mod.\n\n
\n\nFor more information, please read [the wiki entry](https://github.com/CaffeineMC/lithium-fabric/wiki/Configuration-File) on modifying your configuration file.\n\n
\n\nPlease note: An empty configuration file is *perfectly normal* and just means you want to use the default options, which are already set up out of the box for the best performance the mod can offer.\n\n
\n\n## Reporting Issues\n\nPlease use the issue tracker linked at the top of the page to report bugs, crashes, and other issues.\n\n", + "body_url": null, + "published": "2021-01-03T00:56:52.292581Z", + "updated": "2025-04-09T00:57:04.627898Z", + "approved": "2021-01-03T00:56:52.292581Z", + "queued": null, + "status": "approved", + "requested_status": null, + "moderator_message": null, + "license": { + "id": "LGPL-3.0-only", + "name": "GNU Lesser General Public License v3.0 only", + "url": null + }, + "downloads": 27033910, + "followers": 14372, + "categories": [ + "optimization" + ], + "additional_categories": [], + "loaders": [ + "fabric", + "neoforge", + "quilt" + ], + "versions": [ + "EhG1mQzx", + "5fmGl08Y", + "ouTdXXWj", + "igqdFUYG", + "pGhOMdTm", + "Le0tKjFX", + "rvsW1zhb", + "7jxErppe", + "aZ0JFf08", + "cTZv31gu", + "nVR7Q63z", + "FHFKMKeu", + "2w527DB2", + "2CbyxeU0", + "2aoHIXuK", + "Ehsd7YUl", + "MoF1cn6g", + "pHl1Vi6k", + "pXdccFQf", + "sIKhU9s4", + "ZRR9yqHD", + "Zs3sdHjK", + "Nba2vozh", + "2ysRxhIL", + "ySBrfN8N", + "xVm1caOt", + "IQxlSIiw", + "FXG2XqRP", + "ALnv7Npy", + "OKrb9xMn", + "3Gq9H7R9", + "7scJ9RTg", + "XS6vJwop", + "sMWkk4VU", + "GYl3zwgt", + "m6sVgAi6", + "53cwYYb1", + "14hWYkog", + "2KMrj5c1", + "ZSNsJrPI", + "qdzL5Hkg", + "WzQmxYRa", + "nMhjKWVE", + "tDFVQpHO", + "bAbb09VF", + "g2qXxjsR", + "fsK2ycFx", + "OC4JOVBe", + "my7uONjU", + "p25IJhj0", + "5a3sPIH2", + "NTZCh7rb", + "5szYtenV", + "M7RXiitG", + "9x0igjLz", + "2mbrKlX3", + "BrMIoIMv", + "dq8Il4FW", + "2Ea7RMWZ", + "KhdehJ6l", + "frXUdgvL", + "QhCwdt4l", + "wDD955sb", + "9xfJi96s", + "dQrmTeoA", + "Yt6Jc9QP", + "pZRO3EKX", + "iDqQi66g", + "t1FlWYl9", + "Jjn7sFGq", + "mhrxIJQX", + "GGl8GkvX", + "rzC1olaY", + "SantNRs5", + "IwD5UGmX", + "6SB2ZRPm", + "5WuQHJvU", + "CfXh2ZF6", + "zVOQw7YU", + "vuuAe7ZA", + "M43775k8", + "W0Cc7ZVd", + "fyVzZaMa", + "GtRRmh9W", + "OUCV8IgS", + "QCuodIia", + "cU1Q9UWL", + "NHA11tBg", + "kLc5Oxr4", + "cHlCOaEl", + "3HMQZXbw", + "ccgnTSUG", + "MM5BBBOK", + "xYxpXTIt", + "HtiXknlD", + "UMEOToAx", + "Mj9fgz9N", + "969795RH", + "nhc57Td2", + "P5VT33Jo", + "7ORhyYm2", + "RuLfpULS", + "5YInGgMN", + "gBOUQzN7", + "u8pHPXJl", + "lP2Expzz", + "2xAqic6O", + "VWYoZjBF" + ], + "icon_url": "https://cdn.modrinth.com/data/gvQqBUqZ/bcc8686c13af0143adf4285d741256af824f70b7_96.webp", + "issues_url": "https://github.com/caffeinemc/lithium-fabric/issues", + "source_url": "https://github.com/caffeinemc/lithium-fabric", + "wiki_url": null, + "discord_url": "https://caffeinemc.net/discord", + "donation_urls": [ + { + "id": "patreon", + "platform": "Patreon", + "url": "https://www.patreon.com/2No2Name" + } + ], + "gallery": [], + "color": 15395571, + "thread_id": "gvQqBUqZ", + "monetization_status": "monetized" + } +] \ No newline at end of file