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

Fail gracefully if Custom Link URL does not expand #3461

Closed
candlerb opened this issue Aug 28, 2019 · 3 comments
Closed

Fail gracefully if Custom Link URL does not expand #3461

candlerb opened this issue Aug 28, 2019 · 3 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation

Comments

@candlerb
Copy link
Contributor

Environment

  • Python version: 3.5.2
  • NetBox version: 2.6.2

Proposed Functionality

At the moment, if you define a Custom Link but there is a template expansion failure in the link URL, Netbox raises a full-blown exception instead of displaying the object you requested. Users tend to confuse this with a bug in Netbox (e.g. #3304, forum)

I propose instead: if a template error occurs during expansion of the URL in a Custom Link, display the button greyed out. Preferably include the exception text as a tooltip.

Note: it's also possible that a template error occurs during expansion of the Text in a Custom Link. In that case, I think it's reasonable to continue to raise an exception, but an alternative would be to log the error and suppress the button, as if the text were blank.

Use Case

  • Making custom links easier to use: e.g. you can link to obj.primary_ip4.address.ip without having to worry whether the device has that field defined or not
  • Reducing support queries on the mailing list

Database Changes

None

External Dependencies

None

@bdlamprecht
Copy link
Contributor

Completely agree with this FR. If an object doesn't have a field or attribute used in a custom link, it shouldn't cause the whole page to fail.

I was surprised by this when I tried to manually create a new device and then after I did, I received an error stating that an attribute didn't exist.

Immediately I went to the open / closed issues and found this one and #3299 and the "work around" did solve the problem. My opinion is that it should fail gracefully instead of the failing hard as it currently does, especially for something as common as obj.primary_ip.address.ip.

@jeremystretch jeremystretch added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Sep 3, 2019
@jeremystretch
Copy link
Member

Handling the exception gracefully is easy, but reporting the failure to the user needs more thought. Exceptions can occur while rendering either the text or URL of grouped or non-grouped links, and the exception message needs to be conveyed in an obvious yet non-intrusive manner.

@candlerb
Copy link
Contributor Author

candlerb commented Sep 3, 2019

I believe that putting the text of the exception (without backtrace) in the "title" attribute means it will be displayed as a tooltip in most browsers. It seems modern browsers support "title" atttribute on <option> elements too, so that should deal with grouped links.

I just tested it:

<select>
<option>foo</option>
<option>bar</option>
<option title="Attribute abc missing" disabled>baz</option>
</select>

In Chrome 76, this works as expected: hover over the disabled 'baz' option and you see the message.

For anyone who doesn't have a compatible browser, but still wants to know why a particular selection is disabled, they can always inspect the HTML to read the title attribute.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: ui and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Dec 13, 2019
@jeremystretch jeremystretch self-assigned this Dec 31, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation
Projects
None yet
Development

No branches or pull requests

3 participants