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

Exception for validation failure in WebFlux does not match the documentation #33061

Closed
xinxiong-tw opened this issue Jun 18, 2024 · 8 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: documentation A documentation task
Milestone

Comments

@xinxiong-tw
Copy link

Affects: <Spring Framework 6.1.8 and maybe other versions>


I write a simple demo below, I write a Controller with a handler method receiving a post request and consume a valid request body

@RestController
class Controller {
    @PostMapping("/test")
    fun test(@RequestBody @Valid foo: Foo) {
        println(foo)
    }

    @ExceptionHandler(Exception::class)
    fun handleException(e: Exception) {
        println(e)
    }
}

data class Foo(
    @field:NotEmpty
    val name: String
)

Then I send a post request with this body to the application.

{
  "name": ""
}

Check out the console and you can see a exception printed and it's type is WebExchangeBindException
But according to the spring document validation, it should throw a MethodArgumentNotValidException.
image

I also test this behavior in mvc and it's the expected exception.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 18, 2024
@snicoll
Copy link
Member

snicoll commented Jun 18, 2024

Check out the console

It looks like you'd like us to run the example to actually see the error. Please don't paste code in text like that as the only choice we have is to copy it in a small project created from start.spring.io in the hope we're not missing another piece you're not showing. I haven't looked at the actual code, but please edit your description to replace that with a reference to an actual sample. You can attach a zip to this issue or push the code to a GitHub repository.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Jun 18, 2024
@xinxiong-tw
Copy link
Author

xinxiong-tw commented Jun 18, 2024

spring-kotlin-webflux-playground.zip
@snicoll Sorry, here is the code in zip.

@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 Jun 18, 2024
@snicoll
Copy link
Member

snicoll commented Jun 18, 2024

Thanks. I've reproduced what you've described, we'll look into it.

@imvtsl
Copy link
Contributor

imvtsl commented Jun 19, 2024

Hi @snicoll
I would like to begin contributing to spring framework. Do you mind assigning this to me?

@snicoll
Copy link
Member

snicoll commented Jun 20, 2024

@imvtsl thanks for the offer but I am not sure yet what we want to do for this. While the issue title makes it sound like a documentation change, it might not be. You can see this by the "waiting-for-triage" label that means the team hasn't really determined the nature of the issue yet.

@xinxiong-tw
Copy link
Author

xinxiong-tw commented Jun 20, 2024

@snicoll @imvtsl

While the issue title makes it sound like a documentation change

Maybe I didn't make it clean, IMO I would like this exception to be type of MethodArgumentNotValidException. Because in webmvc it's this exception type and align with the doc.

@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jun 20, 2024
@snicoll
Copy link
Member

snicoll commented Jun 22, 2024

I understood what you reported but I am not sure what we should do. @rstoyanchev should know.

@snicoll snicoll added the status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team label Jun 22, 2024
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Jun 24, 2024

WebExchangeBindException is the expected exception for WebFlux. It is a ResponseStatusException as other exceptions in WebFlux and BindingResult is implemented as an interface only. MethodArgumentNotValidException on the other hand extends BindException and inherits the BindingResult implementation. In short, I confirm that it is a documentation issue.

@rstoyanchev rstoyanchev added type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team labels Jun 24, 2024
@rstoyanchev rstoyanchev added this to the 6.1.11 milestone Jun 24, 2024
@rstoyanchev rstoyanchev self-assigned this Jun 24, 2024
@rstoyanchev rstoyanchev changed the title Webflux validation exception does not match the document description Exception for validation failure in WebFlux does not match the documentation Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

6 participants