Skip to content

Command not found message should be configurable #778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jvalkeal opened this issue Jun 16, 2023 · 0 comments
Closed

Command not found message should be configurable #778

jvalkeal opened this issue Jun 16, 2023 · 0 comments
Assignees
Labels
branch/3.1.x Issue for a branch for/backport For backporting type/enhancement Is an enhancement request
Milestone

Comments

@jvalkeal
Copy link
Contributor

ThrowableResultHandler also handles CommandNotFound and thus we get rather long message which really is meant for last resort:

No command found for 'wrong'
org.springframework.shell.CommandNotFound: No command found for 'wrong'
        at org.springframework.shell.Shell.evaluate(Shell.java:205)
        at org.springframework.shell.Shell.run(Shell.java:158)
        at org.springframework.shell.jline.NonInteractiveShellRunner.run(NonInteractiveShellRunner.java:129)
        at org.springframework.shell.DefaultShellApplicationRunner.run(DefaultShellApplicationRunner.java:65)
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:761)
...

While it has always been possible to customise by adding a new bean something like:

public class CommandNotFoundResultHandler extends TerminalAwareResultHandler<CommandNotFound> {

	protected CommandNotFoundResultHandler(Terminal terminal) {
		super(terminal);
	}

	@Override
	protected void doHandleResult(CommandNotFound result) {
		terminal.writer().println("hello");
		terminal.writer().flush();
	}

}

It'd be nice we handle "command not found" centrally and make it easier configure and extend. We could have some kind of "context" what a new implementation could use to describe better error.

In 3.2.x we should make this default behaviour and in older versions allow user to enable it(don't want to change default behaviour).

@jvalkeal jvalkeal added the type/enhancement Is an enhancement request label Jun 16, 2023
@jvalkeal jvalkeal added this to the 3.2.x milestone Jun 16, 2023
@jvalkeal jvalkeal self-assigned this Jun 16, 2023
@jvalkeal jvalkeal changed the title Command not found should be easier to configure Command not found message should be configurable Jun 20, 2023
@jvalkeal jvalkeal added for/backport For backporting branch/3.1.x Issue for a branch labels Jun 20, 2023
jvalkeal added a commit to jvalkeal/spring-shell that referenced this issue Jun 20, 2023
- New CommandNotFoundResultHandler which handles
  CommandNotFound to be able to customize error shown.
- New CommandNotFoundMessageProvider which is a plain
  function given a "context" and returns a string.
  Context contains common info to provide better
  error messages.
- Default provider gives same message but
  removes long stacktrace(which previously originated
  from a common ThrowableResultHandler.
- Relates spring-projects#778
jvalkeal added a commit that referenced this issue Jun 20, 2023
- New CommandNotFoundResultHandler which handles
  CommandNotFound to be able to customize error shown.
- New CommandNotFoundMessageProvider which is a plain
  function given a "context" and returns a string.
  Context contains common info to provide better
  error messages.
- Default provider gives same message but
  removes long stacktrace(which previously originated
  from a common ThrowableResultHandler.
- Backport #778
- Relates #793
jvalkeal added a commit that referenced this issue Jun 23, 2023
@jvalkeal jvalkeal modified the milestones: 3.2.x, 3.2.0-M1 Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch/3.1.x Issue for a branch for/backport For backporting type/enhancement Is an enhancement request
Projects
None yet
Development

No branches or pull requests

1 participant