Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

NonInteractiveShellRunner, wrong exit value when Commands cannot be parsed

Aperta
#1,391 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@czpilar ci sta già lavorando.

Dal 5/10/2026.

  • #1393 di @czpilar — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java
Ambito
cli

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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di spring-projects/spring-shell

Tutte le issue di spring-projects/spring-shell

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.