Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

TypeError: Cannot read property 'startsWith' of undefined #324

Closed
NoNameProvided opened this issue Jun 22, 2021 · 18 comments
Closed

TypeError: Cannot read property 'startsWith' of undefined #324

NoNameProvided opened this issue Jun 22, 2021 · 18 comments
Assignees

Comments

@NoNameProvided
Copy link

I know there is a related error in #284, I decided to open a new issue as this hits us 100% of the time, instead of rare cases reported in the other issue.

Since the last few weeks Codecov cannot upload coverage reports from Github Actions 100% of the time for some repositories. This causes a lot of work for us as all automated PRs like dependency updates must be merged manually.

We use the following command to upload our coverage:

codecov -f ./coverage/clover.xml -t  --commit=$GITHUB_SHA --branch=${GITHUB_REF##*/}

The log from the CLI is the following:

codecov -f ./coverage/clover.xml -t  --commit=$GITHUB_SHA --branch=${GITHUB_REF##*/}
  shell: /usr/bin/bash -e {0}
  _____          _  
 / ____|        | |  
| |     ___   __| | ___  ___ _____   __  
| |    / _ \ / _` |/ _ \/ __/ _ \ \ / /  
| |___| (_) | (_| |  __/ (_| (_) \ V /  
 \_____\___/ \__,_|\___|\___\___/ \_/  
                                v3.8.2
==> Detecting CI Provider
    GitHub Actions CI Detected
==> Configuration: 
    Endpoint: codecov.io
{
  commit: '<redacted>',
  branch: 'node-6.7.2',
  package: 'node-v3.8.2'
}
==> Building file structure
==> Generating gcov reports (skip via --disable=gcov)
    $ find /home/runner/work/<redacted>-api/<redacted>-api -type f -name '*.gcno'  -exec gcov  {} +
    Failed to run gcov command.
==> Targeting specific file
    + /home/runner/work/<redacted>-api/<redacted>-api/coverage/clover.xml
==> Uploading reports
/opt/hostedtoolcache/node/16.3.0/x64/lib/node_modules/codecov/node_modules/teeny-request/build/src/agents.js:33
    const isHttp = uri.startsWith('http://');
                       ^

TypeError: Cannot read property 'startsWith' of undefined
    at Object.getAgent (/opt/hostedtoolcache/node/16.3.0/x64/lib/node_modules/codecov/node_modules/teeny-request/build/src/agents.js:33:24)
    at requestToFetchOptions (/opt/hostedtoolcache/node/16.3.0/x64/lib/node_modules/codecov/node_modules/teeny-request/build/src/index.js:65:30)
    at teenyRequest (/opt/hostedtoolcache/node/16.3.0/x64/lib/node_modules/codecov/node_modules/teeny-request/build/src/index.js:121:30)
    at /opt/hostedtoolcache/node/16.3.0/x64/lib/node_modules/codecov/lib/codecov.js:214:9
    at /opt/hostedtoolcache/node/16.3.0/x64/lib/node_modules/codecov/node_modules/teeny-request/build/src/index.js:219:13
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Error: Process completed with exit code 1.
@jsjoeio
Copy link

jsjoeio commented Jun 22, 2021

I'm trying to fix a coverage report that's outdated and ran into the same issue locally. Looks like uri is undefined

image

Stack trace:

  _____          _  
 / ____|        | |  
| |     ___   __| | ___  ___ _____   __  
| |    / _ \ / _` |/ _ \/ __/ _ \ \ / /  
| |___| (_) | (_| |  __/ (_| (_) \ V /  
 \_____\___/ \__,_|\___|\___\___/ \_/  
                                v3.8.2
==> Detecting CI Provider
    No CI Detected. Using git/mercurial
==> Configuration: 
    Endpoint: https://codecov.io
{
  commit: '5d4e08e390f14ebdd62a6595a1851897a1377273',
  branch: 'master',
  package: 'node-v3.8.2'
}
==> Building file structure
==> Generating gcov reports (skip via --disable=gcov)
    $ find /Users/jp/Dev/code-server -type f -name '*.gcno'  -exec gcov  {} +
    Failed to run gcov command.
==> Scanning for reports
    + /Users/jp/Dev/code-server/coverage/coverage-final.json
    + /Users/jp/Dev/code-server/coverage/clover.xml
==> Uploading reports
uri https://codecov.io/upload/v4?commit=5d4e08e390f14ebdd62a6595a1851897a1377273&branch=master&yaml=&package=node-v3.8.2
uri undefined
(node:22039) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined
    at Object.getAgent (/Users/jp/Dev/code-server/node_modules/teeny-request/build/src/agents.js:34:24)
    at requestToFetchOptions (/Users/jp/Dev/code-server/node_modules/teeny-request/build/src/index.js:65:30)
    at teenyRequest (/Users/jp/Dev/code-server/node_modules/teeny-request/build/src/index.js:121:30)
    at /Users/jp/Dev/code-server/node_modules/codecov/lib/codecov.js:214:9
    at /Users/jp/Dev/code-server/node_modules/teeny-request/build/src/index.js:219:13
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Notes

  • Looks like this rejects the promise here in teeny-request because it assumes uri is defined.
  • and that is being called here where uri is being passed in
  • looks like they are asserting the type here causing this to fail 🤔
  • and this is the PR where that logic was added back in Nov. 2018
  • and here is where it's breaking in codecov-node. It's because you're splitting on '\n' but result is Could not determine repo and owner so there's no \n to split on, hence var codecov_report_url = result.split('\n')[0] and result.split('\n')[1] are both undefined

In my case, I opened a PR into a non-base branch and so codecov didn't run and doesn't have a coverage report for that commit/branch, which I think is why I'm getting an error here but maybe not 🤔 Either way, you could probably write a function and a test to properly parse/get the covecov_report_url

This feels like a bug 🤔 Because if the codecov API returns Could not determine repo and owner, that should be considered an error and should enter this if(err) block here.

@dragonejt
Copy link

Are there any known methods to fix this issue? Or do I just have to wait for the next update? Also, does the codecov Github action have the same problem or no? I might switch to just use that then

@RA80533
Copy link

RA80533 commented Jun 30, 2021

Thanks for your thorough investigation, @jsjoeio. I'm not a maintainer of this project but your summary will certainly lead to a fix for this issue sooner for all of us.

I'd like to correct you on your very last note. Given a defined string, String.prototype.split will return an array of at least size one wherein the first entry will be either: 1) the input string or, 2) if the string is splittable, the first segment of the splitted string. In terms of code:

const example = 'Could not determine repo and owner';

// (1)
example.split('\n');
// => [ 'Could not determine repo and owner' ]

// (2)
example.split();
// => [ 'Could not determine repo and owner' ]

// (3)
example.split(example); // An exercise to the reader
// => …?
Result of (3) The input string is splittable based on itself, unlike the previous two examples.
[ '', '' ]

@RA80533
Copy link

RA80533 commented Jun 30, 2021

I don't know the intention for why the body is being splitted to obtain the redirection URL but I suspect the logic is incorrect from a high level:

uri: result.split('\n')[1],

@jsjoeio
Copy link

jsjoeio commented Jun 30, 2021

Oh wow...thank you for the simple example and the correction @RA80533 - I didn't realize that was how it would work! I was making guesses without testing.

I don't know the intention for why the body is being splitted to obtain the redirection URL but I suspect the logic is incorrect from a high level

Yeah, I think you're right. I tried pinging someone from codecov on Twitter but they never responded. I'll try again today.

@jonalexander
Copy link

@jsjoeio any updates?

@jsjoeio
Copy link

jsjoeio commented Jul 1, 2021

@jonalexander sadly no :(

The person from Codecov on Twitter never responded. I DM'd the Codecov brand account, nothing. Next steps, going to try getting in contact with the CEO 🤷‍♂️

@RA80533
Copy link

RA80533 commented Jul 2, 2021

I believe many of them are on vacation at the moment. @jonalexander, do you have the ability to point the version you're using to a separate repo or commit for the time being?

@jsjoeio
Copy link

jsjoeio commented Jul 2, 2021

Heads-up — I made contact with them.

image

They're super nice and sounds like they'll be able to help us soon!

I believe many of them are on vacation at the moment

How'd you know?!

@RA80533
Copy link

RA80533 commented Jul 2, 2021

How'd you know?!

One of the maintainers poked their head in to mention that they were on vacation. I believe it was in this very repository but I can't seem to find the comment. Additionally, I received a vacation response from a different team member at Codecov, indicating that they were also on vacation and would return on 2021-07-07.

I imagine a lot of people are going to be taking an extra day or two off if they're in the U.S. since it's a holiday weekend.

@dragonejt
Copy link

Thanks @RA80533 and @jsjoeio for researching this issue and contacting Codecov. In the meantime though, I just wanted to mention for the rest of us that the Github Action for Codecov still works for uploading code coverage reports, so if you use GitHub Actions for CI/CD you can use the Action instead of the npm package.

@jsjoeio
Copy link

jsjoeio commented Jul 2, 2021

@dragonejt good to know! Guess that will have to do in the meantime.

P.S. saw you go to ASU — bear down 😜

@RA80533
Copy link

RA80533 commented Jul 3, 2021

Hey, @jsjoeio, did you ever get the response from Eli? What platform did you exchange messages with Jerrod?

@jerrode
Copy link

jerrode commented Jul 6, 2021

Hey y'all, stopping in here to say we have a big contingent of team back from vacation and jumping into this today. Sorry for delay!

@danielsss
Copy link

So any updates or is there a way for workaround ?

@thomasrockhu thomasrockhu self-assigned this Jul 12, 2021
@thomasrockhu
Copy link
Contributor

Hi @danielsss, looking to deploy a fix for this later this week. Sorry for the delay here.

@thomasrockhu
Copy link
Contributor

I released 3.8.3 which should help with this issue

@thomasrockhu
Copy link
Contributor

I'm going to close this ticket out. If you are still experiencing this issue, feel free to comment back

NullSoldier added a commit to iron-fish/ironfish that referenced this issue Dec 17, 2021
Were hoping it fixes this issue codecov/codecov-node#324
NullSoldier added a commit to iron-fish/ironfish that referenced this issue Dec 17, 2021
nickderobertis added a commit to nickderobertis/copier-typescript-npm-sphinx that referenced this issue May 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants