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

Options validation error messages in non-interactive mode

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

还没有人认领这个 Issue。

评估

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

调研方向

Start with NonInteractiveShellRunner, which appears in the reported stack trace, and inspect how validation failures become CommandExecutionException messages. The related customization points named in the issue are CommandExceptionResolver and CommandCatalogCustomizer; done means non-interactive validation exposes the validator's message instead of only USAGE_ERROR, with stack-trace suppression considered separately.

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

描述

Using Spring Shell 4.0.3 with Spring Boot 4.0.8, non-interactive mode (spring.shell.interactive.enabled=false).

When I add Bean Validation constraints to my @Options, and I start my application by specifying an argument which does not satisfy them, I get a very generic message, which does not explain at all what went wrong:

2026-10-02T16:45:29.372+02:00 ERROR 15460 --- [MyApp] [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.shell.core.command.CommandExecutionException: Unable to execute command plan -n testGen -c 0: USAGE_ERROR
	at org.springframework.shell.core.NonInteractiveShellRunner.executeCommand(NonInteractiveShellRunner.java:162) ~[spring-shell-core-4.0.3.jar:4.0.3]
	at org.springframework.shell.core.NonInteractiveShellRunner.run(NonInteractiveShellRunner.java:95) ~[spring-shell-core-4.0.3.jar:4.0.3]
	at org.springframework.shell.core.autoconfigure.ShellRunnerAutoConfiguration.lambda$springShellApplicationRunner$0(ShellRunnerAutoConfiguration.java:39) ~[spring-shell-core-autoconfigure-4.0.3.jar:4.0.3]
	at org.springframework.boot.SpringApplication.lambda$callRunner$0(SpringApplication.java:788) ~[spring-boot-4.0.8.jar:4.0.8]
	at org.springframework.util.function.ThrowingConsumer$1.acceptWithException(ThrowingConsumer.java:82) ~[spring-core-7.0.9.jar:7.0.9]
	at org.springframework.util.function.ThrowingConsumer.accept(ThrowingConsumer.java:60) ~[spring-core-7.0.9.jar:7.0.9]
	at org.springframework.util.function.ThrowingConsumer$1.accept(ThrowingConsumer.java:86) ~[spring-core-7.0.9.jar:7.0.9]
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:800) ~[spring-boot-4.0.8.jar:4.0.8]
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:788) ~[spring-boot-4.0.8.jar:4.0.8]
	at org.springframework.boot.SpringApplication.lambda$callRunners$0(SpringApplication.java:776) ~[spring-boot-4.0.8.jar:4.0.8]
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) ~[na:na]
	at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357) ~[na:na]
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510) ~[na:na]
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[na:na]
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) ~[na:na]
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) ~[na:na]
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[na:na]
	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:776) ~[spring-boot-4.0.8.jar:4.0.8]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:328) ~[spring-boot-4.0.8.jar:4.0.8]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1365) ~[spring-boot-4.0.8.jar:4.0.8]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) ~[spring-boot-4.0.8.jar:4.0.8]
	at example.MyApp.main(MyApp.java:31) ~[classes/:na]

In this case, I was specifying -c 0 while that option has @Min(1).
I would expect in some way to get the contents of the validation error message, as specified on the @Min annotation. Or, more generically, the error message supplied by the validator (in case custom error messages are built by my custom validator).

Asking AI, it suggests a quite complex customization through either CommandCatalogCustomizer or CommandExceptionResolver, which anyway requires to unwrap and inspect the ConstraintViolationException. Isn't there a built-in way to do this?
The default behavior I'm seeing seems to fully defeat the purpose of using the Bean Validation API.

Also suppressing the full stack trace would be nice, however, at least seeing the actual message (even if buried in the stack trace) would be better than nothing. What I'm trying to do is to write a command-line interface fro my Spring Boot app. Thanks!

主要语言
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 摘要。