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 fast when the frontend sends an invalid class name #322

Merged
merged 1 commit into from
Mar 14, 2022

Conversation

basil
Copy link
Member

@basil basil commented Jan 24, 2022

Untested PR to return better error messages for users who are affected by tables-to-divs issues. In JENKINS-67218 and JENKINS-67550, a tables-to-divs issue caused the frontend to send a list of classes rather than a single class to the backend. This list eventually made its way to the class loader, resulting in confusing error messages. Users thought that the classloader couldn't load the classes because they weren't present, but the real reason class loading is failing is that we're passing a list rather than a single class to the class loader. This PR changes the code to fail fast in this situation and give the user an informative error message before the problem makes its way to lower layers.

@basil basil added the bug label Jan 24, 2022
@basil basil requested a review from a team March 14, 2022 18:54
@basil
Copy link
Member Author

basil commented Mar 14, 2022

Does the core team have any thoughts on this? I think that failing fast is generally always preferable to make the error more clear to users. If there are concerns about the error being too specific to Jenkins or tables-to-divs, I can always remove the link from the error message and keep it more generic.

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Makes sense I think.

if (isArray) {
throw new IllegalArgumentException(
"The frontend sent an unexpected list of classes ("
+ className
Copy link
Member

Choose a reason for hiding this comment

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

What will an example value be?

Copy link
Member Author

Choose a reason for hiding this comment

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

Please read JENKINS-67550 (which I linked to in the PR description). It contains an example value seen in the wild:

["org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition","org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition"]

Copy link
Member

Choose a reason for hiding this comment

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

So we could also check, say,

className.contains(",")

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct

"The frontend sent an unexpected list of classes ("
+ className
+ ") rather than an expected single class. See"
+ " https://www.jenkins.io/doc/developer/views/table-to-div-migration/"
Copy link
Member

Choose a reason for hiding this comment

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

I am pretty sure tables-to-divs is not the only case where this problem arises, though it may be the most common one recently.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I have no strong preference about including the link in the error message. If we think that the error is better without the link I am happy to remove it.

Copy link
Member

Choose a reason for hiding this comment

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

Oh definitely include the link. I just meant it might be appropriate to adjust the phrasing to explain that this is only one possible root cause.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will keep an eye out for other causes in the future and adjust the message then if needed.

@basil basil requested a review from timja March 14, 2022 20:15
Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

can always iterate it if we find other usecases

@basil basil merged commit 0275e61 into jenkinsci:master Mar 14, 2022
@basil basil deleted the error branch March 14, 2022 20:21
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.

3 participants