Skip to content
Permalink
Browse files

[FIXED JENKINS-41825] Display an informative message, rather than a G…

…roovy exception, when View.getItems fails.
  • Loading branch information
jglick committed Feb 7, 2017
1 parent 860144b commit fcf4ca7697b4a5293c95b221669f202621b178f7
@@ -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);
@@ -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.
@@ -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.*;
@@ -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;
@@ -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 {
@@ -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")

0 comments on commit fcf4ca7

Please sign in to comment.
You can’t perform that action at this time.