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

Fix: Throw error if invalid model specified (+ refactor) #160

Merged
merged 4 commits into from
Jul 18, 2023

Conversation

alexdewar
Copy link
Contributor

I've been playing around with clang-tidy as part of my work on #89 and it flagged a problem in model_parser.cpp. The issue is that if the JSON file contains an invalid model name, although an error message is printed, the code doesn't abort and will happily register a nullptr model definition in the cache.

I think part of the problem is that the register_risk_factor_model_definitions is rather long and with a lot of different branches in it, so it's easy to lose track of what the code is doing. I've split up the model loading into a series of separate functions with appropriate error handling in each.

Copy link
Contributor

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

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

Looks good to me! Even if, for some reason, this does not solve all the problem, splitting long functions with a lot of nested branches is always a good idea.

@dalonsoa dalonsoa mentioned this pull request Jul 14, 2023
Copy link
Contributor

@jamesturner246 jamesturner246 left a comment

Choose a reason for hiding this comment

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

Yeah, that looks much nicer. Just a couple of trivial header fixups and it's good to go!

src/HealthGPS.Console/model_parser.h Outdated Show resolved Hide resolved
src/HealthGPS.Console/model_parser.h Outdated Show resolved Hide resolved
src/HealthGPS.Console/model_parser.h Show resolved Hide resolved
src/HealthGPS.Console/model_parser.h Show resolved Hide resolved
src/HealthGPS.Console/model_parser.h Outdated Show resolved Hide resolved
Copy link
Contributor

@jamesturner246 jamesturner246 left a comment

Choose a reason for hiding this comment

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

Looks good. Fire away!

@alexdewar alexdewar enabled auto-merge July 18, 2023 06:50
@alexdewar alexdewar merged commit 595fc75 into main Jul 18, 2023
5 checks passed
@alexdewar alexdewar deleted the refactor_model_loading branch July 18, 2023 09:23
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.

3 participants