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

dev/core#2340 Skip rather than fail on bad menu item #19464

Merged
merged 1 commit into from
Feb 3, 2021

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Jan 30, 2021

Overview

Reduces the severity of having an invalid menu item by displaying an error rather rather tha not loading the page

Before

After configuring an afform with a path of 'trxn' (instead of 'civicrm/trxn') the api explorer, the main dashboard and various other pages faile to load with an uncaught exception
image

After

image

Technical Details

Comments

@civibot
Copy link

civibot bot commented Jan 30, 2021

(Standard links)

@civibot civibot bot added the master label Jan 30, 2021
}
}
catch (CRM_Core_Exception $e) {
CRM_Core_Session::setStatus($e->getMessage(), ts('Path skipped'));
Copy link
Member

@colemanw colemanw Jan 30, 2021

Choose a reason for hiding this comment

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

In general I think CRM_Core_Session::setStatus() is only meant for use on forms, and lower-down BAO and Util classes should not call it. Consider the case of an API calling a BAO function and that BAO function calling CRM_Core_Session::setStatus() to handle errors. In that case the api might be running over REST or other headless state so there isn't even a user session to set messages for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah - but then it just gets swallowed doesn't it? Which seems OK - outside forms.

Copy link
Member

@colemanw colemanw Jan 30, 2021

Choose a reason for hiding this comment

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

Well it's led to some weird bugs in the past. Typically we expect the BAO to throw an exception and the layer that calls it to catch it and respond appropriately (if it's an api, generate an api error, if it's a form, display a status message, if it's somewhere else, maybe log it?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that the iterate-through-array-of-menu-items is still at the BAO layer - we want that layer to continue. I guess it could throw an exception at the end of the iteration - but then it might still kill api calls

Copy link
Member

Choose a reason for hiding this comment

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

@eileenmcnaughton I recommend logging the error instead of calling setStatus()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK - I've updated it

Copy link
Member

Choose a reason for hiding this comment

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

I don't know everything about logging in Civi but wouldn't this be classified as an error message rather than a debug message? e.g. Civi::log()->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.

@colemanw done - can we merge now?

@colemanw colemanw merged commit f8ad51c into civicrm:master Feb 3, 2021
@colemanw colemanw deleted the menu branch February 3, 2021 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants