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

FI-2035: Improve error handling for validator errors #379

Merged
merged 3 commits into from
Aug 28, 2023

Conversation

dehall
Copy link
Contributor

@dehall dehall commented Jul 31, 2023

Summary

This PR improves error handling when there is a problem in the validator, in two ways:

  1. Problems reported as OperationOutcome with an HTTP status other than 200 will raise an ErrorInValidatorException which renders in the inferno UI as a purple error, and more detail, when given in the OO, will be in the Messages tab:
    image
    (note - this message is introduced in Fi 1977 slow fhir-validator-wrapper#64 )
    (note 2 - a future PR will introduce a better error handler in the validator, which will render errors as OOs. still TBD)

  2. When the response from the validator can't be parsed as an OperationOutcome, for example when the validator returns an HTML page that just says "HTTP 500", that will be wrapped in an ErrorInValidatorException, and more detail if possible will be in the Messages tab. The overall message will indicate an issue with the validator and be a purple error, but not lead off with the stack trace of the Ruby code where things went off track because that's isn't useful:
    image

Please feel free to suggest alternate text. Also I suspect the logic of the modified function could be cleaner so I'm going to keep thinking about how to clean that up.

Testing Guidance

Testing this requires a test kit that actually validates resources via the validator service. I'm not sure what the "easiest" way to do that is, but I loaded the US Core 3.1.1 test kit into the dev_suites folders and it wasn't tough to get running. (There are some things that need to be pruned like references to TLS tests but those lines can be deleted/commented out)

Testing the various possibilities also requires an instance of the validator that you can easily control.
inferno-framework/fhir-validator-wrapper#64 introduces an OperationOutcome that is returned while the app is starting up. You may also want to manually add something like throw new RuntimeException(); in a spot of your choosing in the validator to simulate an error there.

@dehall dehall requested a review from Jammjammjamm July 31, 2023 14:38
@codecov
Copy link

codecov bot commented Jul 31, 2023

Codecov Report

Patch coverage: 82.14% and project coverage change: -0.01% ⚠️

Comparison is base (13db9cb) 76.96% compared to head (65be52c) 76.95%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #379      +/-   ##
==========================================
- Coverage   76.96%   76.95%   -0.01%     
==========================================
  Files         213      213              
  Lines       10573    10594      +21     
  Branches      972      976       +4     
==========================================
+ Hits         8137     8153      +16     
- Misses       1867     1872       +5     
  Partials      569      569              
Flag Coverage Δ
backend 94.38% <82.14%> (-0.13%) ⬇️
frontend 69.62% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
lib/inferno/exceptions.rb 86.95% <66.66%> (-1.42%) ⬇️
lib/inferno/dsl/fhir_validation.rb 93.47% <84.00%> (-3.82%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


# The validator should return OperationOutcome both on successful validation and on error,
# so parse the OO before checking the HTTP status code.
outcome = FHIR::OperationOutcome.new(JSON.parse(validation_response.body))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should specifically handle the case of non-json responses and display those in the message without the json parse error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to check for this specifically: image

Unfortunately this all put the resource_is_valid? function over rubocop's cyclomatic complexity limit and I had to refactor a bit. Feel free to say the refactorings aren't clear and I can spend a little more time on it

if response.start_with? '{'
FHIR::OperationOutcome.new(JSON.parse(response))
else
runnable.add_message('error', "Validator Response: #{response}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use a newline here:

Screenshot 2023-08-07 at 8 44 30 AM

@dehall dehall merged commit 0452e64 into main Aug 28, 2023
7 of 8 checks passed
@dehall dehall deleted the fi-2035-validator-errors branch September 7, 2023 12:10
Jammjammjamm added a commit that referenced this pull request Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants