-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 caught in global error handler, exception message: Object reference not set to an instance of an object. #1608
Comments
Maybe, you configured duplication the endpoint about downstream/upstream url |
Klaudiusz, Klaudiusz, Klaudiusz... 😄 Hi Klaudiusz!
This is wrong template! You must add slash sign before
Bingo! 🤣 Have a great summer, Klaudiusz! 🌞 |
Please, upgrade your solution to v19 (.NET 7 release) |
@raman-m Error message which I've posted was extracted by myself during debugging. In the runtime it was hidden from the user. Btw NullReferenceException should never be thrown by the application. It should be handled somehow. As I said - original error message was hidden. Without debugging Ocelot code I would never be able to get to know what was wrong and misconfigured :) |
Aha, I see. Sorry! |
I would love to review your PR and/or discuss your idea to fix this error message hiding problem. |
@klaudiusz-czapla Hi, My Route in Ocelot.json file is, here I removed first slash of downstream path.
@raman-m Not sure what he was trying to explain last year, but on latest version I am unable to see any issue. |
These lines are under discussion: lines L92-L96 You've shown concrete line of code which fails in your user scenario. Regarding |
No, he mentioned these lines: lines L92-L96 which are below starting the line 92... |
@raman-m how he got an error? I see code is safe |
@ks1990cn The quote from the description:
|
This piece of code never executed in case of bad configuration... @raman-m , still I want to understand how he reached there..? |
do someone added this code on latest version? |
Probably Yes...
Tanmay, his case is invalid... He was kidding in this issue, and request to fix quite wrong user case. Tanmay, once again... We're discussing something quite specific... |
Exactly! Didn't you know the fact that Ocelot has global error handler which processes all exceptions? We've discussed the case. You pointed to the problematic line. The fix should be tiny... You have one month till January 5, 2024 to create a PR...otherwise you won't be an author of the fix, or we will close the issue at all. P.S.And please fork Ocelot repo! |
Expected Behavior
I'm expecting to get error details coming from ocelot.json file validation in case of invalid configuration being provided.
Actual Behavior
I had scenario where Errors collection coming from validation process (ocelot.json) is discarded and then I'm getting NullReferenceException instead which is hiding the real problem.
Steps to Reproduce the Problem
You have to create ocelot.json file where one of the routes contains something like this:
During debugging Ocelot I got at some point Errors collection with message: "Downstream Path Template {everything} doesnt start with forward slash"
It was in method Ocelot.Middleware.OcelotMiddlewareExtensions.CreateConfiguration'IApplicationBuilder -> fileConfig.OnChange callback
nevertheless somehow this mesage was never logged anywhere, it was discarded and finally I got NullReferenceException instead
{Ocelot.Responses.ErrorResponse<Ocelot.Configuration.IInternalConfiguration>}
-> Data -> null in my case
-> Errors -> Downstream Path Template {everything} doesnt start with forward slash
-> IsError -> true
In line
error should be checked before accessing .Data property
Specifications
The text was updated successfully, but these errors were encountered: