Skip to content

Commit

Permalink
Improve error handling when project does not exist
Browse files Browse the repository at this point in the history
This either continues onwards when in debug mode, or throws a
descriptive exception (rather than an NPE).
  • Loading branch information
SquidDev committed Jan 15, 2025
1 parent 4f0fc0a commit 771354e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/java/com/modrinth/minotaur/TaskModrinthUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@ public void apply() {
try {
ModrinthAPI api = api(getProject());

String id = Objects.requireNonNull(api.projects().getProjectIdBySlug(ext.getProjectId().get()).join());
String slug = ext.getProjectId().get();
String id = api.projects().getProjectIdBySlug(slug).join();
if (id == null) {
if (ext.getDebugMode().get()) {
getLogger().error("Cannot find project with id '{}'.", slug);
id = "<unknown>";
} else {
throw new GradleException(String.format("Cannot find project with id '%s'", slug));
}
}
getLogger().debug("Uploading version to project {}", id);

// Add version name if it's null
Expand Down Expand Up @@ -248,7 +257,7 @@ && getProject().getExtensions().findByName("loom") != null) {
getLogger().lifecycle(
"Successfully uploaded version {} to {} ({}) as version ID {}. {}",
newVersion.getVersionNumber(),
ext.getProjectId().get(),
slug,
id,
newVersion.getId(),
String.format(
Expand Down

0 comments on commit 771354e

Please sign in to comment.