Skip to content

Commit b88f7aa

Browse files
stuartroweRowe, Stuart
andauthored
Fix "null" string literal in steps that no exception text (#1170)
Co-authored-by: Rowe, Stuart <stuartr@ea.com>
1 parent f08f212 commit b88f7aa

File tree

7 files changed

+74
-1
lines changed

7 files changed

+74
-1
lines changed

src/main/frontend/common/RestClient.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export async function getExceptionText(stepId: string): Promise<string[]> {
118118
const response = await fetch(`exceptionText?nodeId=${stepId}`);
119119
if (!response.ok) throw response.statusText;
120120
const text = await response.text();
121+
if (!text) return [];
121122
return text.split("\n");
122123
} catch (e) {
123124
console.error(`Caught error when fetching console: '${e}'`);

src/main/java/io/jenkins/plugins/pipelinegraphview/consoleview/PipelineConsoleViewAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ public HttpResponse getExceptionText(StaplerRequest2 req, StaplerResponse2 rsp)
185185
run.checkPermission(Item.READ);
186186
String nodeId = req.getParameter("nodeId");
187187
if (nodeId == null) return HttpResponses.error(400, "missing ?nodeId");
188-
return HttpResponses.text(getNodeExceptionText(nodeId));
188+
String exceptionText = getNodeExceptionText(nodeId);
189+
return HttpResponses.text(exceptionText != null ? exceptionText : "");
189190
}
190191

191192
private AnnotatedLargeText<? extends FlowNode> getLogForNode(String nodeId) throws IOException {

src/test/java/io/jenkins/plugins/pipelinegraphview/PipelineGraphViewTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,42 @@ void searchOffScreen(Page p, JenkinsConfiguredWithCodeRule j) throws Exception {
164164
.scrollToText("Hello, world 1000!")
165165
.scrollToText("Hello, world 1!");
166166
}
167+
168+
@Test
169+
@ConfiguredWithCode("configure-appearance.yml")
170+
void errorWithMessage(Page p, JenkinsConfiguredWithCodeRule j) throws Exception {
171+
String name = "gh1169";
172+
WorkflowRun run = TestUtils.createAndRunJob(j, name, "gh1169_errorWithMessage.jenkinsfile", Result.FAILURE);
173+
174+
// Note that the locator used in stageHasSteps accumulates the error step's message text content into the found
175+
// step name so we just check that instead of also calling stepContainText
176+
new PipelineJobPage(p, run.getParent())
177+
.goTo()
178+
.hasBuilds(1)
179+
.nthBuild(0)
180+
.goToBuild()
181+
.goToPipelineOverview()
182+
.hasStagesInGraph(1, "Stage")
183+
.selectStageInGraph("Stage")
184+
.stageHasSteps("Error signalError");
185+
}
186+
187+
@Issue("GH#1169")
188+
@Test
189+
@ConfiguredWithCode("configure-appearance.yml")
190+
void errorWithNoMessage(Page p, JenkinsConfiguredWithCodeRule j) throws Exception {
191+
String name = "gh1169";
192+
WorkflowRun run = TestUtils.createAndRunJob(j, name, "gh1169_errorWithNoMessage.jenkinsfile", Result.FAILURE);
193+
194+
new PipelineJobPage(p, run.getParent())
195+
.goTo()
196+
.hasBuilds(1)
197+
.nthBuild(0)
198+
.goToBuild()
199+
.goToPipelineOverview()
200+
.hasStagesInGraph(1, "Stage")
201+
.selectStageInGraph("Stage")
202+
.stageHasSteps("Error signal")
203+
.stepDoesNotContainText("Error signal", "null");
204+
}
167205
}

src/test/java/io/jenkins/plugins/pipelinegraphview/playwright/PipelineConsole.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,28 @@ public void stepContainsText(String stepName, String textToFind) {
7777
}
7878
}
7979

80+
public void stepDoesNotContainText(String stepName, String textToNotFind) {
81+
log.info("Checking that the step {} does not contain a log with the text {}", stepName, textToNotFind);
82+
83+
Locator stepContainer = steps().filter(new Locator.FilterOptions()
84+
.setHas(page.locator(
85+
STEP_NAME_CLASS,
86+
new Page.LocatorOptions().setHasText(Pattern.compile("^" + stepName + "$")))))
87+
.first();
88+
89+
if (!isOpenStep(stepContainer)) {
90+
stepContainer.click();
91+
}
92+
Locator stepLogs = stepContainer.getByRole(AriaRole.LOG);
93+
assertThat(stepLogs).not().containsText(textToNotFind);
94+
95+
Locator plainTextLogsLink = stepContainer.getByRole(
96+
AriaRole.LINK, new Locator.GetByRoleOptions().setName("View step as plain text"));
97+
try (Page plainText = page.context().waitForPage(plainTextLogsLink::click)) {
98+
assertThat(plainText.locator("body")).not().containsText(textToNotFind);
99+
}
100+
}
101+
80102
public void stageHasSteps(String step, String... additional) {
81103
List<String> expectedSteps = new ArrayList<>();
82104
expectedSteps.add(step);

src/test/java/io/jenkins/plugins/pipelinegraphview/playwright/PipelineOverviewPage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public PipelineOverviewPage stepContainsText(String stepName, String textToFind)
8585
return this;
8686
}
8787

88+
public PipelineOverviewPage stepDoesNotContainText(String stepName, String textToNotFind) {
89+
logs.stepDoesNotContainText(stepName, textToNotFind);
90+
return this;
91+
}
92+
8893
public PipelineOverviewPage stageHasSteps(String step, String... additional) {
8994
logs.stageHasSteps(step, additional);
9095
return this;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
stage("Stage") {
2+
error("Error")
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
stage("Stage") {
2+
error()
3+
}

0 commit comments

Comments
 (0)