Skip to content

Commit

Permalink
Better use Result in the MethodExecutor#execute method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rollczi committed Dec 2, 2021
1 parent c39c6ad commit 7bcb70d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.rollczi.litecommands.inject.InjectContext;
import dev.rollczi.litecommands.valid.ValidationCommandException;
import dev.rollczi.litecommands.valid.ValidationInfo;
import panda.std.Option;
import panda.std.Pair;
import panda.std.Result;

Expand All @@ -28,7 +29,7 @@ public final class LiteExecution extends AbstractComponent {

@Override
public ExecutionResult resolveExecution(ContextOfResolving context) {
Result<Object, Pair<String, Throwable>> result = executor.execute(new InjectContext(context, this));
Result<Option<Object>, Pair<String, Throwable>> result = executor.execute(new InjectContext(context, this));

if (result.isOk()) {
return ExecutionResult.valid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public Option<Class<?>> getParameter(int currentArgsCount) {
return Option.of(cachedParameters.get(currentArgsCount));
}

public Result<Object, Pair<String, Throwable>> execute(InjectContext context) {
public Result<Option<Object>, Pair<String, Throwable>> execute(InjectContext context) {
try {
Object returned = injector.invokeMethod(method, instance, context);
return Result.ok(returned == null ? true : returned);
return Result.ok(Option.of(returned));
} catch (IllegalAccessException illegalAccessException) {
return Result.error(Pair.of("Method " + ReflectUtils.formatMethodParams(method) + " is " + ReflectUtils.modifier(method), illegalAccessException));
} catch (IllegalArgumentException illegalArgumentException) {
Expand Down

0 comments on commit 7bcb70d

Please sign in to comment.