Skip to content

TypeError: Cannot read properties of undefined (reading 'length') #9

@mziyut

Description

@mziyut

What

It seems that variables in repoData are sometimes undefined

const repoData = await Promise.all(
repoList.map(async (repo) => {
const url = `https://circleci.com/api/v2/project/gh/${repo}/envvar`;
const results = await fetch(url, {
headers: { "Circle-Token": `${CIRCLE_TOKEN}` },
}).then((res) => res.json());
return {
name: repo,
variables: results.items,
};
})
);
USER_DATA.projects = repoData.filter((repo) => repo.variables.length > 0);

Log

file:///project/index.js:150
USER_DATA.projects = repoData.filter((repo) => repo.variables.length > 0);
                                                              ^

TypeError: Cannot read properties of undefined (reading 'length')
    at file:///project/index.js:150:63
    at Array.filter (<anonymous>)
    at file:///project/index.js:150:31
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v19.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions