Skip to content

Commit cfdcaa2

Browse files
authored
modrinth: improve error message when non-existent version ID given (#547)
1 parent 93d9e58 commit cfdcaa2

File tree

3 files changed

+238
-1
lines changed

3 files changed

+238
-1
lines changed

src/main/java/me/itzg/helpers/modrinth/ModrinthApiClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import lombok.extern.slf4j.Slf4j;
1818
import me.itzg.helpers.errors.GenericException;
1919
import me.itzg.helpers.errors.InvalidParameterException;
20+
import me.itzg.helpers.http.FailedRequestException;
2021
import me.itzg.helpers.http.Fetch;
2122
import me.itzg.helpers.http.FileDownloadedHandler;
2223
import me.itzg.helpers.http.SharedFetch;
@@ -146,7 +147,11 @@ public Mono<Version> resolveProjectVersion(Project project, ProjectRef projectRe
146147
return getVersionsForProject(project.getId(), loaderToQuery, gameVersion)
147148
.mapNotNull(versions -> pickVersion(project, versions, projectRef.getVersionType()));
148149
} else if (projectRef.hasVersionId()) {
149-
return getVersionFromId(projectRef.getVersionId());
150+
return getVersionFromId(projectRef.getVersionId())
151+
.onErrorMap(FailedRequestException::isNotFound, throwable ->
152+
new InvalidParameterException(String.format("Version %s does not exist, requested for project %s",
153+
projectRef.getVersionId(), project.getSlug()))
154+
);
150155
} else {
151156
return getVersionsForProject(project.getId(), loaderToQuery, gameVersion)
152157
.mapNotNull(versions -> pickVersion(project, versions, defaultVersionType));

src/test/java/me/itzg/helpers/modrinth/ModrinthCommandTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.itzg.helpers.modrinth;
22

3+
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemErrNormalized;
34
import static com.github.tomakehurst.wiremock.client.WireMock.*;
45
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
56
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
@@ -225,6 +226,44 @@ void errorWhenNoApplicableVersion(@TempDir Path tempDir) {
225226
assertThat(exitCode).isNotEqualTo(ExitCode.OK);
226227
}
227228

229+
@Test
230+
void handlesNotExistentVersionId(@TempDir Path tempDir) throws Exception {
231+
stubFor(
232+
get(urlPathMatching("/v2/projects"))
233+
.withQueryParam("ids", equalTo("[\"lithium\"]"))
234+
.willReturn(aResponse()
235+
.withHeader("Content-Type", "application/json")
236+
.withBodyFile("bulk-lithium.json")
237+
)
238+
);
239+
240+
stubFor(
241+
get(urlPathMatching("/v2/version/vWYoZjBF"))
242+
.willReturn(aResponse()
243+
.withStatus(404)
244+
)
245+
);
246+
247+
final String out = tapSystemErrNormalized(() -> {
248+
final int exitCode = new CommandLine(
249+
new ModrinthCommand()
250+
)
251+
.execute(
252+
"--api-base-url", wm.getRuntimeInfo().getHttpBaseUrl(),
253+
"--output-directory", tempDir.toString(),
254+
"--game-version", "1.21.5",
255+
"--loader", "fabric",
256+
"--projects", "lithium:vWYoZjBF"
257+
);
258+
259+
assertThat(exitCode).isNotEqualTo(ExitCode.OK);
260+
});
261+
262+
assertThat(out)
263+
.contains("InvalidParameterException")
264+
.contains("Version vWYoZjBF does not exist");
265+
}
266+
228267
@ParameterizedTest
229268
@ValueSource(booleans = {true, false})
230269
void handlesDatapacksSpecificVersion(boolean absoluteWorldDir, @TempDir Path tempDir) {
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
[
2+
{
3+
"client_side": "optional",
4+
"server_side": "optional",
5+
"game_versions": [
6+
"1.16.2",
7+
"1.16.3",
8+
"1.16.4",
9+
"1.16.5",
10+
"1.17",
11+
"1.17.1",
12+
"1.18",
13+
"1.18.1",
14+
"1.18.2",
15+
"1.19",
16+
"1.19.1",
17+
"1.19.2",
18+
"1.19.3",
19+
"1.19.4",
20+
"1.20",
21+
"1.20.1",
22+
"1.20.2",
23+
"1.20.3",
24+
"1.20.4",
25+
"1.20.5",
26+
"1.20.6",
27+
"1.21",
28+
"1.21.1",
29+
"1.21.2",
30+
"1.21.3",
31+
"1.21.4",
32+
"1.21.5"
33+
],
34+
"id": "gvQqBUqZ",
35+
"slug": "lithium",
36+
"project_type": "mod",
37+
"team": "peSx5UYg",
38+
"organization": "LjcZDkRW",
39+
"title": "Lithium",
40+
"description": "No-compromises game logic optimization mod. Well suited for clients and servers of all kinds. Now available for Fabric and NeoForge!",
41+
"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<br>\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<br>\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<br>\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<br>\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<br>\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<br>\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<br>\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<br>\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<br>\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",
42+
"body_url": null,
43+
"published": "2021-01-03T00:56:52.292581Z",
44+
"updated": "2025-04-09T00:57:04.627898Z",
45+
"approved": "2021-01-03T00:56:52.292581Z",
46+
"queued": null,
47+
"status": "approved",
48+
"requested_status": null,
49+
"moderator_message": null,
50+
"license": {
51+
"id": "LGPL-3.0-only",
52+
"name": "GNU Lesser General Public License v3.0 only",
53+
"url": null
54+
},
55+
"downloads": 27033910,
56+
"followers": 14372,
57+
"categories": [
58+
"optimization"
59+
],
60+
"additional_categories": [],
61+
"loaders": [
62+
"fabric",
63+
"neoforge",
64+
"quilt"
65+
],
66+
"versions": [
67+
"EhG1mQzx",
68+
"5fmGl08Y",
69+
"ouTdXXWj",
70+
"igqdFUYG",
71+
"pGhOMdTm",
72+
"Le0tKjFX",
73+
"rvsW1zhb",
74+
"7jxErppe",
75+
"aZ0JFf08",
76+
"cTZv31gu",
77+
"nVR7Q63z",
78+
"FHFKMKeu",
79+
"2w527DB2",
80+
"2CbyxeU0",
81+
"2aoHIXuK",
82+
"Ehsd7YUl",
83+
"MoF1cn6g",
84+
"pHl1Vi6k",
85+
"pXdccFQf",
86+
"sIKhU9s4",
87+
"ZRR9yqHD",
88+
"Zs3sdHjK",
89+
"Nba2vozh",
90+
"2ysRxhIL",
91+
"ySBrfN8N",
92+
"xVm1caOt",
93+
"IQxlSIiw",
94+
"FXG2XqRP",
95+
"ALnv7Npy",
96+
"OKrb9xMn",
97+
"3Gq9H7R9",
98+
"7scJ9RTg",
99+
"XS6vJwop",
100+
"sMWkk4VU",
101+
"GYl3zwgt",
102+
"m6sVgAi6",
103+
"53cwYYb1",
104+
"14hWYkog",
105+
"2KMrj5c1",
106+
"ZSNsJrPI",
107+
"qdzL5Hkg",
108+
"WzQmxYRa",
109+
"nMhjKWVE",
110+
"tDFVQpHO",
111+
"bAbb09VF",
112+
"g2qXxjsR",
113+
"fsK2ycFx",
114+
"OC4JOVBe",
115+
"my7uONjU",
116+
"p25IJhj0",
117+
"5a3sPIH2",
118+
"NTZCh7rb",
119+
"5szYtenV",
120+
"M7RXiitG",
121+
"9x0igjLz",
122+
"2mbrKlX3",
123+
"BrMIoIMv",
124+
"dq8Il4FW",
125+
"2Ea7RMWZ",
126+
"KhdehJ6l",
127+
"frXUdgvL",
128+
"QhCwdt4l",
129+
"wDD955sb",
130+
"9xfJi96s",
131+
"dQrmTeoA",
132+
"Yt6Jc9QP",
133+
"pZRO3EKX",
134+
"iDqQi66g",
135+
"t1FlWYl9",
136+
"Jjn7sFGq",
137+
"mhrxIJQX",
138+
"GGl8GkvX",
139+
"rzC1olaY",
140+
"SantNRs5",
141+
"IwD5UGmX",
142+
"6SB2ZRPm",
143+
"5WuQHJvU",
144+
"CfXh2ZF6",
145+
"zVOQw7YU",
146+
"vuuAe7ZA",
147+
"M43775k8",
148+
"W0Cc7ZVd",
149+
"fyVzZaMa",
150+
"GtRRmh9W",
151+
"OUCV8IgS",
152+
"QCuodIia",
153+
"cU1Q9UWL",
154+
"NHA11tBg",
155+
"kLc5Oxr4",
156+
"cHlCOaEl",
157+
"3HMQZXbw",
158+
"ccgnTSUG",
159+
"MM5BBBOK",
160+
"xYxpXTIt",
161+
"HtiXknlD",
162+
"UMEOToAx",
163+
"Mj9fgz9N",
164+
"969795RH",
165+
"nhc57Td2",
166+
"P5VT33Jo",
167+
"7ORhyYm2",
168+
"RuLfpULS",
169+
"5YInGgMN",
170+
"gBOUQzN7",
171+
"u8pHPXJl",
172+
"lP2Expzz",
173+
"2xAqic6O",
174+
"VWYoZjBF"
175+
],
176+
"icon_url": "https://cdn.modrinth.com/data/gvQqBUqZ/bcc8686c13af0143adf4285d741256af824f70b7_96.webp",
177+
"issues_url": "https://github.com/caffeinemc/lithium-fabric/issues",
178+
"source_url": "https://github.com/caffeinemc/lithium-fabric",
179+
"wiki_url": null,
180+
"discord_url": "https://caffeinemc.net/discord",
181+
"donation_urls": [
182+
{
183+
"id": "patreon",
184+
"platform": "Patreon",
185+
"url": "https://www.patreon.com/2No2Name"
186+
}
187+
],
188+
"gallery": [],
189+
"color": 15395571,
190+
"thread_id": "gvQqBUqZ",
191+
"monetization_status": "monetized"
192+
}
193+
]

0 commit comments

Comments
 (0)