Skip to content

Commit 06d11a0

Browse files
authored
fix: deploy: TypeError: Cannot read properties of undefined (reading 'length') (#221)
1 parent ea76b39 commit 06d11a0

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ async function findProjectHashOnServer (ow, projectName) {
17311731
// check for package with the projectName in manifest File and if found -> return the projectHash on the server
17321732
const resultSync = await ow.packages.list(options)
17331733
for (const pkg of resultSync) {
1734-
if (pkg.annotations.length > 0) {
1734+
if (pkg.annotations?.length > 0) {
17351735
const whiskManaged = pkg.annotations.find(elem => elem.key === 'whisk-managed')
17361736
if (whiskManaged !== undefined && whiskManaged.value.projectName === projectName) {
17371737
projectHash = whiskManaged.value.projectHash
@@ -1742,7 +1742,7 @@ async function findProjectHashOnServer (ow, projectName) {
17421742
// if no package exists with the projectName -> look in actions
17431743
const resultActionList = await ow.actions.list()
17441744
for (const action of resultActionList) {
1745-
if (action.annotations.length > 0) {
1745+
if (action.annotations?.length > 0) {
17461746
const whiskManaged = action.annotations.find(elem => elem.key === 'whisk-managed')
17471747
if (whiskManaged !== undefined && whiskManaged.value.projectName === projectName) {
17481748
projectHash = whiskManaged.value.projectHash
@@ -1754,7 +1754,7 @@ async function findProjectHashOnServer (ow, projectName) {
17541754
// if no action exists with the projectName -> look in triggers
17551755
const resultTriggerList = await ow.triggers.list()
17561756
for (const trigger of resultTriggerList) {
1757-
if (trigger.annotations.length > 0) {
1757+
if (trigger.annotations?.length > 0) {
17581758
const whiskManaged = trigger.annotations.find(elem => elem.key === 'whisk-managed')
17591759
if (whiskManaged !== undefined && whiskManaged.value.projectName === projectName) {
17601760
projectHash = whiskManaged.value.projectHash
@@ -1766,7 +1766,7 @@ async function findProjectHashOnServer (ow, projectName) {
17661766
// if no trigger exists with the projectName -> look in rules
17671767
const resultRules = await ow.rules.list()
17681768
for (const rule of resultRules) {
1769-
if (rule.annotations.length > 0) {
1769+
if (rule.annotations?.length > 0) {
17701770
const whiskManaged = rule.annotations.find(elem => elem.key === 'whisk-managed')
17711771
if (whiskManaged !== undefined &&
17721772
whiskManaged.value.projectName === projectName) {

test/utils.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,20 @@ describe('getProjectHash', () => {
19361936
})
19371937

19381938
describe('findProjectHashOnServer', () => {
1939+
test('default projectHash (null annotations in packages, actions, triggers, rules)', async () => {
1940+
const testProjectName = 'ThisIsTheNameOfTheProject'
1941+
const pkgList = ow.mockResolved('packages.list', [{ annotations: null }])
1942+
const actList = ow.mockResolved('actions.list', [{ annotations: null }])
1943+
const trgList = ow.mockResolved('triggers.list', [{ annotations: null }])
1944+
const rlzList = ow.mockResolved('rules.list', [{ annotations: null }])
1945+
const result = await utils.findProjectHashOnServer(ow, testProjectName)
1946+
expect(pkgList).toHaveBeenCalled()
1947+
expect(actList).toHaveBeenCalled()
1948+
expect(trgList).toHaveBeenCalled()
1949+
expect(rlzList).toHaveBeenCalled()
1950+
expect(result).toBe('')
1951+
})
1952+
19391953
test('default projectHash (no packages, actions, triggers, rules found)', async () => {
19401954
const testProjectName = 'ThisIsTheNameOfTheProject'
19411955
const pkgList = ow.mockResolved('packages.list', '')

0 commit comments

Comments
 (0)