From 771354eae7d4875bbb5a686d30e78d95821f1253 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Wed, 15 Jan 2025 21:23:48 +0000 Subject: [PATCH] Improve error handling when project does not exist This either continues onwards when in debug mode, or throws a descriptive exception (rather than an NPE). --- .../com/modrinth/minotaur/TaskModrinthUpload.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/modrinth/minotaur/TaskModrinthUpload.java b/src/main/java/com/modrinth/minotaur/TaskModrinthUpload.java index 36444fb..8b53069 100644 --- a/src/main/java/com/modrinth/minotaur/TaskModrinthUpload.java +++ b/src/main/java/com/modrinth/minotaur/TaskModrinthUpload.java @@ -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 = ""; + } 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 @@ -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(