From 7146448e3247a6cec095f1c0f72c003e4bda6421 Mon Sep 17 00:00:00 2001 From: Pasqual Koschmieder Date: Sat, 25 Jun 2022 09:10:03 +0200 Subject: [PATCH] expose failure reason when flag parsing fails (#380) --- CHANGELOG.md | 3 +++ .../arguments/compound/FlagArgument.java | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61011b2df..4069712d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Core: Expose failure reason when flag parsing fails ([#380](https://github.com/Incendo/cloud/pull/380)) + ## [1.7.1] ### Added diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/compound/FlagArgument.java b/cloud-core/src/main/java/cloud/commandframework/arguments/compound/FlagArgument.java index fe18e821e..358a6ed26 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/compound/FlagArgument.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/compound/FlagArgument.java @@ -483,6 +483,7 @@ public static final class FlagParseException extends ParserException { private static final long serialVersionUID = -7725389394142868549L; private final String input; + private final FailureReason failureReason; /** * Construct a new flag parse exception @@ -504,6 +505,7 @@ public FlagParseException( CaptionVariable.of("flag", input) ); this.input = input; + this.failureReason = failureReason; } /** @@ -514,6 +516,17 @@ public FlagParseException( public String getInput() { return this.input; } + + /** + * Returns the reason why the flag parsing failed. + * + * @return the failure reason + * @since 1.8.0 + */ + @API(status = API.Status.STABLE, since = "1.8.0") + public @NonNull FailureReason failureReason() { + return this.failureReason; + } }