Skip to content

Commit fdf7b5f

Browse files
authored
paper: suggest other release channel when build not found (#455)
1 parent a75327a commit fdf7b5f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/main/java/me/itzg/helpers/paper/InstallPaperCommand.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import java.io.IOException;
55
import java.net.URI;
66
import java.nio.file.Path;
7+
import java.util.Arrays;
78
import java.util.Collections;
89
import java.util.Objects;
910
import java.util.concurrent.Callable;
1011
import java.util.regex.Matcher;
1112
import java.util.regex.Pattern;
13+
import java.util.stream.Collectors;
1214
import lombok.Builder;
1315
import lombok.extern.slf4j.Slf4j;
1416
import me.itzg.helpers.errors.GenericException;
@@ -250,20 +252,31 @@ private Mono<Result> downloadUsingCoordinates(PaperDownloadsClient client, Strin
250252
String.format("Requested version %s is not available", version))
251253
)
252254
.switchIfEmpty(Mono.error(() -> new InvalidParameterException(
253-
String.format("No build found for version %s with channel %s", version, channel)
255+
String.format("No build found for version %s with channel '%s'. Perhaps try with a different channel: %s",
256+
version, channel, channelsExcept(channel))
254257
)))
255258
.flatMap(resolvedBuild -> download(client, project, version, resolvedBuild));
256259
}
257260
}
258261
else {
259262
return client.getLatestVersionBuild(project, channel)
260263
.switchIfEmpty(
261-
Mono.error(() -> new InvalidParameterException("No build found with channel " + channel))
264+
Mono.error(() -> new InvalidParameterException(
265+
String.format("No build found with channel '%s'. Perhaps try a different channel: %s",
266+
channel, channelsExcept(channel)
267+
)))
262268
)
263269
.flatMap(resolved -> download(client, project, resolved.getVersion(), resolved.getBuild()));
264270
}
265271
}
266272

273+
private String channelsExcept(ReleaseChannel channel) {
274+
return Arrays.stream(ReleaseChannel.values())
275+
.filter(c -> !Objects.equals(c, channel))
276+
.map(ReleaseChannel::toString)
277+
.collect(Collectors.joining(", "));
278+
}
279+
267280
private static boolean isSpecificVersion(String version) {
268281
return version != null && !version.equalsIgnoreCase("latest");
269282
}

0 commit comments

Comments
 (0)