Skip to content

Improve error reporting when non mandatory options are misconfigured or incorrectly specified at runtimeΒ #1245

Closed as not planned

Description

@czpilar

This seems like regression from some of the latests commits.

Consider this configuration:

@SpringBootApplication
public class SpringShellApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringShellApplication.class, args);
    }

    @Command(name = "hello", completionProvider = "helloNameCompletionProvider")
    public void sayHello(@Option(longName = "name", shortName = 'n') String name) {
        System.out.println("Hello " + name + "!");
    }

    @Bean
    public CompletionProvider helloNameCompletionProvider() {
        return completionContext -> Stream.of("Peter", "Paul", "Mary").map(CompletionProposal::new).toList();
    }

}

There are some issues:

  1. If a command is invoked without any option, the warning is logged. Which is not consistent if command is invoked with and option without value (there is no warning message).

    shell:>hello
    11:32:19.249 [main] WARN  o.s.s.c.c.a.MethodInvokerCommandAdapter - No value provided for optional option '--name' and no default value specified.
    Hello !
    
    shell:>hello --name
    Hello !
    
    shell:>hello -n
    Hello !
    
  2. If option is specified with a short or long name with space before the value, it's not recognized.

    shell:>hello --name Paul
    Hello !
    
    shell:>hello -n Paul
    Hello !
    
  3. The value is recognized only if specified with equal sign.

    shell:>hello --name=Paul
    Hello Paul!
    
    shell:>hello -n=Paul
    Hello Paul!
    
Image

Activity

  1. fmbenhassine commented on Dec 26, 2025

    @fmbenhassine
    Contributor
    1. If a command is invoked without any option, the warning is logged. Which is not consistent if command is invoked with and option without value (there is no warning message).

    I think those are different things: 1) not providing an optional option not having a default value vs 2) providing an option with incorrect syntax (missing value)

    1. is a command configuration problem and should fail fast at command configuration time (introspection time, ie in CommandFactoryBean)
    2. is a command usage problem which can happen at runtime (command invoking time, ie in MethodInvokerCommandAdapter).

    I think there is a room for improvement here, but this is not blocking for 4.0 GA.

    1. If option is specified with a short or long name with space before the value, it's not recognized.
    2. The value is recognized only if specified with equal sign.

    The default parser only supports key=value pairs. This is mentioned in the docs here: https://docs.spring.io/spring-shell/reference/4.0-SNAPSHOT/commands/syntax.html


    EDIT:

    Option values without an equal sign are not recognized

    Since this is not supported in the default parser as explained, I am changing the title of this issue to focus on issue 1): improve error reporting when non mandatory options are not specified or incorrectly specified.

  2. added and removed
    status/need-triageTeam needs to triage and take a first look
    on Dec 26, 2025
  3. added this to the 4.0.1 milestone on Dec 26, 2025
  4. changed the title [-]Option values without an equal sign are not recognized[/-] [+]Improve error reporting when non mandatory options are misconfigured or not incorrectly specified at runtime[/+] on Dec 26, 2025
  5. fmbenhassine commented on Dec 27, 2025

    @fmbenhassine
    Contributor

    The default parser only supports key=value pairs. This is mentioned in the docs here

    @czpilar While thinking about this, I improved the default parser to support the --key value / -k value syntax in addition to the --key=value / -k=valule form, see #1248.

    This works way better with command completion now! I think the updated DefaultCommandParserTests suite is fairly complete, but I might have missed a corner case or two at this time of the day night πŸ˜…. I will retest this with a fresh head again before GA. Any feedback is welcome!

  6. czpilar commented on Dec 27, 2025

    @czpilar
    ContributorAuthor

    @fmbenhassine Thank you for improving the default parser β€” it definitely works much better with completion now.

    I realized that after fixing the completion issue in #1246, I completely missed the case where a key=value pair is already present on the command line. Because of that, I opened a new PR to address this scenario. Please take a look.

  7. TusharSamaniya commented on Dec 28, 2025

    @TusharSamaniya

    Can i also work with #1245 issue

  8. changed the title [-]Improve error reporting when non mandatory options are misconfigured or not incorrectly specified at runtime[/-] [+]Improve error reporting when non mandatory options are misconfigured or incorrectly specified at runtime[/+] on Dec 28, 2025
  9. fmbenhassine commented on Dec 28, 2025

    @fmbenhassine
    Contributor

    @TusharSamaniya Sure! Contributions are welcome. Thank you for your offer to help!

  10. czpilar commented on Dec 31, 2025

    @czpilar
    ContributorAuthor

    Regardig:

    1. If a command is invoked without any option, the warning is logged. Which is not consistent if command is invoked with and option without value (there is no warning message).

    If an option specifies only a shortName and no default value, as in the following example:

    @Option(shortName = 'n') String first

    The warning message incorrectly reports the shortName with a double dash (e.g., --n). It should be -n.

    shell:>hello
    13:47:31.726 [main] WARN  o.s.s.c.c.a.MethodInvokerCommandAdapter - No value provided for optional option '--n' and no default value specified.
    Hello !
    

    Also, not providing a default value for optional options is, in my opinion, a valid scenario, as I may want the option value to be null, or to use the Java default value in the case of primitive types, without showing any warning message.

  11. jayychoi commented on Jan 24, 2026

    @jayychoi

    Hi @TusharSamaniya, how's the work going? May I work on this issue if you don't mind?

  12. added a commit that references this issue on Jan 24, 2026
    a54a97d
  13. modified the milestones: 4.0.1, 4.0.2 on Jan 30, 2026
  14. fmbenhassine commented on Apr 8, 2026

    @fmbenhassine
    Contributor

    I think what I said previously here:

    1. an optional option not having a default value
    1. is a command configuration problem and should fail fast at command configuration time (introspection time, ie in CommandFactoryBean)

    is not up-to-date anymore after db567c2. In fact, now if the user defines a non-mandatory option without a default value, the option will be assigned the default value in Java for primitives types, and null for non primitive types.

    Also, not providing a default value for optional options is, in my opinion, a valid scenario, as I may want the option value to be null, or to use the Java default value in the case of primitive types, without showing any warning message.

    @czpilar I agree, now that #1262 , #1304 are #1314 resolved. Since there is no error nor warning anymore in this case, I am closing this issue and related PR that were seeking to "Improve error reporting".

  15. removed this from the 4.0.2 milestone on Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions