From 39d56651d4fd7d7bc764ca667f3781925693e987 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Wed, 21 Jun 2023 19:21:31 -0500 Subject: [PATCH] vt: validate pack definition has a type --- .../vanillatweaks/VanillaTweaksCommand.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/itzg/helpers/vanillatweaks/VanillaTweaksCommand.java b/src/main/java/me/itzg/helpers/vanillatweaks/VanillaTweaksCommand.java index a738a905..5979441c 100644 --- a/src/main/java/me/itzg/helpers/vanillatweaks/VanillaTweaksCommand.java +++ b/src/main/java/me/itzg/helpers/vanillatweaks/VanillaTweaksCommand.java @@ -198,14 +198,21 @@ private Flux loadPackDefinitions() { // handle --arg= case .filter(path -> !path.toString().isEmpty()) ) - .handle((path, sink) -> { + .flatMap(path -> { try { - sink.next(new SourcedPackDefinition( - "definition file " + path, - objectMapper.readValue(path.toFile(), PackDefinition.class) - )); + final PackDefinition packDefinition = objectMapper.readValue(path.toFile(), PackDefinition.class); + if (packDefinition.getType() == null) { + return Mono.error( + new InvalidParameterException(String.format("Pack definition file %s is missing 'type'", path))); + } + else { + return Mono.just(new SourcedPackDefinition( + "definition file " + path, + packDefinition + )); + } } catch (IOException e) { - sink.error(new GenericException("Failed to load pack definition file", e)); + return Mono.error(new GenericException("Failed to load pack definition file", e)); } }); }