NonInteractiveShellRunner, wrong exit value when Commands cannot be parsed
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
Direzione di ricerca
Start in spring-shell-core/src/main/java/org/springframework/shell/core/NonInteractiveShellRunner.java, reading executeCommand and scriptExecution together. Trace how parsing exceptions are handled and how the runner communicates command failure, then add or update coverage for parsing failures so the non-interactive command or script reports a nonzero exit code.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I have commands which I use in bash scripts using the NonInteractiveShellRunner.
Now I noticed, that if the parsing of a command fails, spring-shell return as an exit code "0" - which is the signal for other processes that everything went fine. Yet, the contrary is the case.
Indeed, when looking at the source code this behaviour is quite easily explained. In the NonInteractiveShellRunner#executeCommand the method simply returns in the case of an Exception during the parsing.
// https://github.com/spring-projects/spring-shell/blob/main/spring-shell-core/src/main/java/org/springframework/shell/core/NonInteractiveShellRunner.java
private void executeCommand(String primaryCommand) {
ParsedInput parsedInput;
try {
parsedInput = this.commandParser.parse(primaryCommand);
}
catch (Exception exception) {
log.error("Command " + primaryCommand + " parsed with error: " + exception.getMessage());
return;
}
CommandContext commandContext = new CommandContext(parsedInput, this.commandRegistry, this.outputWriter,
this.inputReader);
ExitStatus exitStatus = this.commandExecutor.execute(commandContext);
if (ExitStatus.OK.code() != exitStatus.code()) {
log.error("Command " + parsedInput.commandName() + " returned an error: " + exitStatus.description());
throw new CommandExecutionException(
"Unable to execute command " + primaryCommand + ": " + exitStatus.description(), exitStatus.code());
}
}
From my point of view, spring-shell should return a non "0"-code when a parsing-error occurs. This is true for the method #scriptExecution as well.
Any thoughts on that? I could provide an pull-request - yet I am not sure if just throwing an exception would be the correct way.
- Lingua principale
- Java
- Stelle
- 826
- Fork
- 404
- Merge medio
- 6g 9h
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di spring-projects/spring-shell
-
Options validation error messages in non-interactive modeForse già presa @czpilar l’ha presa 2 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
spring-projects/spring-shell#1390 · 1 commento ·
-
ShellInputProvider inputs are not consumed by `ComponentFlow`-based interactive components (e.g. `ConfirmationInput`, `StringInput`)Forse già presa @czpilar l’ha presa 14 giorni fa. Apertatype/enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
spring-projects/spring-shell#1383 · 6 commenti ·
-
area/dependencies type/enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
spring-projects/spring-shell#1213 · 1 reazione ·
-
Revisit dependency to Spring MessagingForse già presa @piotrooo l’ha presa 288 giorni fa. Apertaarea/dependencies type/enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
spring-projects/spring-shell#1205 · 1 commento ·
-
Spring CLI AI AgentApertastatus/need-triage
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
spring-projects/spring-shell#1198 · 2 commenti ·
Tutte le issue di spring-projects/spring-shell
Issue simili
-
Bump up AWS SDK to 2.54.3Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
jenkinsci/ec2-plugin#2041 ·
-
L: github:actions L: php:composer
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
dependabot/dependabot-core#16493 ·
I maintainer di solito rispondono entro 1 giorno
-
SHOW EDIT of a subclass for an object of its superclass: the form fails to open with AssertionErrorAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
FlashyReese/sodium-extra#608 ·