Skip to content

Commit 5845043

Browse files
committed
fix: gracefully handle logName on undefined Arn
1 parent 208ba49 commit 5845043

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

code-build.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,18 @@ function buildSdk() {
234234
}
235235

236236
function logName(Arn) {
237-
const [logGroupName, logStreamName] = Arn.split(":log-group:")
238-
.pop()
239-
.split(":log-stream:");
240-
if (logGroupName === "null" || logStreamName === "null")
241-
return {
242-
logGroupName: undefined,
243-
logStreamName: undefined,
244-
};
245-
return { logGroupName, logStreamName };
237+
const logs = {
238+
logGroupName: undefined,
239+
logStreamName: undefined,
240+
};
241+
if (Arn) {
242+
const [logGroupName, logStreamName] = Arn.split(":log-group:")
243+
.pop()
244+
.split(":log-stream:");
245+
if (logGroupName !== "null" && logStreamName !== "null") {
246+
logs.logGroupName = logGroupName;
247+
logs.logStreamName = logStreamName;
248+
}
249+
}
250+
return logs;
246251
}

test/code-build-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ describe("logName", () => {
2929
expect(test).to.haveOwnProperty("logGroupName").and.to.equal(undefined);
3030
expect(test).to.haveOwnProperty("logStreamName").and.to.equal(undefined);
3131
});
32+
33+
it("return undefined when the Arn is undefined", () => {
34+
const arn = undefined;
35+
const test = logName(arn);
36+
expect(test).to.haveOwnProperty("logGroupName").and.to.equal(undefined);
37+
expect(test).to.haveOwnProperty("logStreamName").and.to.equal(undefined);
38+
});
3239
});
3340

3441
describe("githubInputs", () => {

0 commit comments

Comments
 (0)