Skip to content

Commit

Permalink
fix: command parameter injection service (#1526)
Browse files Browse the repository at this point in the history
### Motivation
When trying to execute specific commands, such as `version
installtemplate`, an exception is thrown due to a wrong implementation
of the cloud command injection service:
```
[10.10 20:55:49.130] ERROR: Exception during command execution
org.incendo.cloud.exception.InjectionException: Failed to inject type org.incendo.cloud.context.CommandContext<?>
	at org.incendo.cloud.injection.ParameterInjectorRegistry.getInjectable(ParameterInjectorRegistry.java:197)
	at org.incendo.cloud.annotations.method.AnnotatedMethodHandler.getInjectedValue(AnnotatedMethodHandler.java:135)
	at org.incendo.cloud.annotations.method.AnnotatedMethodHandler.createParameterValues(AnnotatedMethodHandler.java:206)
...
Caused by: org.incendo.cloud.services.PipelineException: Failed to retrieve result from ServiceWrapper{type=org.incendo.cloud.injection.InjectionService<C>,implementation=eu.cloudnetservice.node.command.defaults.AerogelInjectionService}
	at org.incendo.cloud.services.ServiceSpigot.complete(ServiceSpigot.java:97)
	at org.incendo.cloud.injection.ParameterInjectorRegistry.getInjectable(ParameterInjectorRegistry.java:178)
	... 13 common frames omitted
```

### Modification
Change the injection service so that it no longer throws an exception
but rather returns null as required if an instance of the requested type
cannot be injected.

### Result
The execution of specific commands no longer throws an exception and
works as expected again.
  • Loading branch information
derklaro authored Oct 10, 2024
1 parent e392bbb commit b02cdb5
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ final class AerogelInjectionService implements InjectionService<CommandSource> {

@Override
public @Nullable Object handle(@NonNull InjectionRequest<CommandSource> request) {
// get the associated data from the input values
var targetClass = request.injectedClass();
var injectionLayer = InjectionLayer.findLayerOf(targetClass);
try {
// get the associated data from the input values
var targetClass = request.injectedClass();
var injectionLayer = InjectionLayer.findLayerOf(targetClass);

// get the instance of the given class from the injection layer
return injectionLayer.instance(targetClass);
// get the instance of the given class from the injection layer
return injectionLayer.instance(targetClass);
} catch (Exception exception) {
return null;
}
}
}

0 comments on commit b02cdb5

Please sign in to comment.