Fix language negotiation exception to be standard #24764
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Fix language negotiation exception to be standard
Before
CRM_Core_Locale::negotiate
throws aRunTime
exception when provided bad dataAfter
CRM_Core_Locale::negotiate
throws aCRM_Core_Exception
Technical Details
`RunTime exceptions are defined as
"Exception thrown if an error which can only be found on runtime occurs."
I guess you could argue that any place in the code that fails when data is bad / fails validation is a runTime exception - but in practice in our codebase historical bad database data (e.g having an invalid value in
civicrm_contact.preferred_language
or an invalid email would generally throw aCRM_Core_Exception
and most code that calls CiviCRM function expects and handles this). Where I seerunTime
exceptions in Civi code is mostly where a site is misconfigured - so not something that an extension would need to know about or handle.This function is a utility function that is frequently called from sending messages & it seems wrong to have an exception thrown that bypasses 99% of civicrm exception handling
Side note - the type of exception thrown should have been documented in the docblock & we should possibly document the reason whenever it isn't a derivative of
CRM_Core_Exception
Comments
@totten