NonInteractiveShellRunner, wrong exit value when Commands cannot be parsed
还没有人认领这个 Issue。
评估
调研方向
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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
spring-projects/spring-shell 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 65/100
spring-projects/spring-shell#1390 · 1 条评论 ·
-
type/enhancement
难度 3/5 1-2 天 新手友好度 68/100
spring-projects/spring-shell#1383 · 6 条评论 ·
-
area/dependencies type/enhancement
难度 5/5 一周以上 新手友好度 25/100
spring-projects/spring-shell#1213 · 1 个 reaction ·
-
area/dependencies type/enhancement
难度 5/5 一周以上 新手友好度 25/100
spring-projects/spring-shell#1205 · 1 条评论 ·
-
status/need-triage
难度 5/5 一周以上 新手友好度 20/100
spring-projects/spring-shell#1198 · 2 条评论 ·
查看 spring-projects/spring-shell 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 86/100
-
Make branch and label autocomplete matching locale-independent可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 83/100
jenkinsci/gitlab-plugin#1950 ·
-
It's not necessary to copy the memory block in the readWrite() of org.h2.store.fs.mem.FileMemData未关闭
难度 2/5 1-3 小时 新手友好度 78/100
h2database/h2database#4435 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
micronaut-projects/micronaut-core#13717 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
ADORSYS-GIS/token-status-link#145 ·
维护者通常 3 天内回复