Skip to content

Commit

Permalink
[FIXED JENKINS-41825] Display an informative message, rather than a G…
Browse files Browse the repository at this point in the history
…roovy exception, when View.getItems fails.

(cherry picked from commit fcf4ca7)
  • Loading branch information
jglick authored and olivergondza committed Feb 15, 2017
1 parent 9f83809 commit da2f57c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/src/main/resources/hudson/model/View/main.groovy
Expand Up @@ -3,7 +3,9 @@ package hudson.model.View;
t=namespace(lib.JenkinsTagLib)
st=namespace("jelly:stapler")

if (items.isEmpty()) {
if (items == null) {
p(_('broken'))
} else if (items.isEmpty()) {
if (app.items.size() != 0) {
set("views",my.owner.views);
set("currentView",my);
Expand Down
23 changes: 23 additions & 0 deletions core/src/main/resources/hudson/model/View/main.properties
@@ -0,0 +1,23 @@
# The MIT License
#
# Copyright 2017 CloudBees, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

broken=An error occurred when retrieving jobs for this view. Please consult the Jenkins logs for details.
35 changes: 34 additions & 1 deletion test/src/test/java/hudson/model/ViewTest.java
Expand Up @@ -53,6 +53,9 @@
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import jenkins.model.ProjectNamingStrategy;
import jenkins.security.NotReallyRoleSensitiveCallable;
import static org.junit.Assert.*;
Expand All @@ -61,6 +64,7 @@
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;
import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.MockAuthorizationStrategy;
import org.jvnet.hudson.test.MockFolder;
import org.jvnet.hudson.test.TestExtension;
Expand All @@ -73,6 +77,8 @@
public class ViewTest {

@Rule public JenkinsRule j = new JenkinsRule();
@Rule
public LoggerRule logging = new LoggerRule();

@Issue("JENKINS-7100")
@Test public void xHudsonHeader() throws Exception {
Expand Down Expand Up @@ -506,7 +512,34 @@ public Void call() throws Exception {
private void assertCheckJobName(ViewGroup context, String name, FormValidation.Kind expected) {
assertEquals(expected, context.getPrimaryView().doCheckJobName(name).kind);
}


@Issue("JENKINS-41825")
@Test
public void brokenGetItems() throws Exception {
logging.capture(100).record("", Level.INFO);
j.jenkins.addView(new BrokenView());
j.createWebClient().goTo("view/broken/");
boolean found = false;
LOGS: for (LogRecord record : logging.getRecords()) {
for (Throwable t = record.getThrown(); t != null; t = t.getCause()) {
if (t instanceof IllegalStateException && BrokenView.ERR.equals(t.getMessage())) {
found = true;
break LOGS;
}
}
}
assertTrue(found);
}
private static class BrokenView extends ListView {
static final String ERR = "oops I cannot retrieve items";
BrokenView() {
super("broken");
}
@Override
public List<TopLevelItem> getItems() {
throw new IllegalStateException(ERR);
}
}

@Test
@Issue("JENKINS-36908")
Expand Down

0 comments on commit da2f57c

Please sign in to comment.