Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

NonInteractiveShellRunner, wrong exit value when Commands cannot be parsed

未关闭
#1,391 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
java
领域
cli

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Java
星标
826
派生
404
平均合并
6 天 9 小时
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

spring-projects/spring-shell 的其他 Issue

查看 spring-projects/spring-shell 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。