Skip to content
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

Failures in -Djarmode=tools do not consistently return a non zero exit #43432

Closed
wants to merge 1 commit into from

Conversation

mpalourdio
Copy link
Contributor

@mpalourdio mpalourdio commented Dec 6, 2024

Hello,

we are dealing with multiple Spring boot versions in our CI.

As we want to leverage jar extraction and CDS, we need to deal with multiple scenarios :

  1. Spring Boot 3.3+ and jar non-executable : extract and CDS are OK
  2. Spring Boot < 3.3 : extract (and so CDS) is not available. It correctly fails with an exit(1) and claims Unsupported jarmode 'tools' . See here
  3. Spring Boot 3.3+ and jar executable : extract fails with XXXX.jar is not compatible; ensure jar file is valid and launch script is not enabled but when ran from CLI, the exit code is 0, although an exception is thrown.

3. is painful, because you need to catch the STD output to check and grep for an error. Something like this pseudo bash

java -Djarmode=tools -jar /opt/my.jar extract --destination /opt/extracted 2>&1`; if [[ $cmd =~ "Error" ]] || [[ $cmd  =~ "Unsupported" ]]; then whatever_you_want_to_do; fi

This PR handles 3 by moving the exception to a system exit code, which seems to be more in line with this feature which is mostly intended to run as CLI and could lead to cleaner error handling, ie

java -Djarmode=tools -jar /opt/my.jar extract --destination /opt/extracted ||  whatever_you_want_to_do

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 6, 2024
@mpalourdio mpalourdio force-pushed the jarmode branch 2 times, most recently from c128183 to 2e9c66b Compare December 6, 2024 11:17
@mhalbritter mhalbritter self-assigned this Dec 6, 2024
@mhalbritter
Copy link
Contributor

mhalbritter commented Dec 6, 2024

Hello!

I see that there's a issue to fix. Ideally the CLI should return code 1 in every error case.

Thanks for the PR, but I don't like that approach. Putting a System.exit() somewhere deep in the command handling code feels wrong. It would be better to let the AbortException bubble up the stack and then catch it in org.springframework.boot.loader.jarmode.JarModeLauncher and org.springframework.boot.loader.launch.JarModeRunner and then call System.exit(1) there. That's also the place to check for the DISABLE_SYSTEM_EXIT system property.

Do you want to implement that in this PR or should I file a new issue tracking this?

@mhalbritter mhalbritter added the status: waiting-for-feedback We need additional information before we can continue label Dec 6, 2024
@mhalbritter mhalbritter changed the title fix: Ensure extract command for jar that are flagged as executable returns an exit code 1 Not all failures in jarmode doesn't set exit code to 1 Dec 6, 2024
@mhalbritter mhalbritter changed the title Not all failures in jarmode doesn't set exit code to 1 Not all failures in jarmode set the exit code to 1 Dec 6, 2024
@mpalourdio
Copy link
Contributor Author

@mhalbritter thanks for feedback, I will give this a shot in this PR a little later

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 6, 2024
@mhalbritter mhalbritter added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Dec 6, 2024
@mpalourdio
Copy link
Contributor Author

@mhalbritter I have pushed some modifications. Does this look (a bit) at what you were expecting ?

Also, i can't catch AbortException, as it's private static final

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 6, 2024
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Dec 6, 2024
@philwebb philwebb added this to the 3.4.x milestone Dec 6, 2024
@philwebb philwebb changed the title Not all failures in jarmode set the exit code to 1 Failures in -Djarmode=tools do not consistently return a non zero exit Dec 6, 2024
@philwebb philwebb modified the milestones: 3.4.x, 3.3.x Dec 6, 2024
@philwebb philwebb self-assigned this Dec 6, 2024
@philwebb
Copy link
Member

philwebb commented Dec 7, 2024

Thanks for the updated PR @mpalourdio. Looking in more detail I think we should pull up our exiting error reporting logic to a central location. That ends up being quite a large change and something we'll need to apply in 3.3 so I'm going to take care of it in #43435.

Thanks for reporting the problem and for your PR.

@philwebb philwebb closed this Dec 7, 2024
@philwebb philwebb removed the type: bug A general bug label Dec 7, 2024
@philwebb philwebb added the status: superseded An issue that has been superseded by another label Dec 7, 2024
@philwebb philwebb removed this from the 3.3.x milestone Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants