Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

TypeError: counter.plus is not a function #31

Closed
0x4007 opened this issue Feb 22, 2024 · 11 comments · Fixed by #34
Closed

TypeError: counter.plus is not a function #31

0x4007 opened this issue Feb 22, 2024 · 11 comments · Fixed by #34

Comments

@0x4007
Copy link
Member

0x4007 commented Feb 22, 2024

There's an issue I've never seen before. Please research a solution before we fund this issue.

TypeError: counter.plus is not a function
    at CommentScoring._calculateWordScores (/home/runner/work/comment-incentives/comment-incentives/src/handlers/issue/comment-scoring-rubric.ts:164:25)
    at CommentScoring.computeWordScore (/home/runner/work/comment-incentives/comment-incentives/src/handlers/issue/comment-scoring-rubric.ts:255:35)
    at perUserCommentScoring (/home/runner/work/comment-incentives/comment-incentives/src/handlers/issue/per-user-comment-scoring.ts:10:19)
    at <anonymous> (/home/runner/work/comment-incentives/comment-incentives/src/handlers/issue/all-comment-scoring.ts:43:9)
    at Array.forEach (<anonymous>)
    at <anonymous> (/home/runner/work/comment-incentives/comment-incentives/src/handlers/issue/all-comment-scoring.ts:39:13)
    at Array.flatMap (<anonymous>)
    at allCommentScoring (/home/runner/work/comment-incentives/comment-incentives/src/handlers/issue/all-comment-scoring.ts:25:6)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at commentsScoring (/home/runner/work/comment-incentives/comment-incentives/src/handlers/issue/evaluate-comments.ts:28:40)
Error: TypeError: counter.plus is not a function

Source https://github.com/ubiquibot/comment-incentives/actions/runs/8002349026/job/21855360540#step:5:262
Related ubiquity/nft-rewards#3 (comment)

@molecula451
Copy link
Contributor

molecula451 commented Mar 14, 2024

relates to the decimal.js package

counter = counter.plus(this.roleWordScore);

@Keyrxng
Copy link
Member

Keyrxng commented Mar 14, 2024

It looks like it's failing for the word "constructor" as far as I can tell, using the rpc-racer as a base for testing. I'm just running a script calling aggregateAndScoreContributions(..args) but I'm unfamiliar with the specifics of this part of the codebase

image

@Keyrxng
Copy link
Member

Keyrxng commented Mar 14, 2024

this fails in and of itself

 const wordScoreCommentDetails: { [key: string]: Decimal } = {};
  const words = ["function", "was", "async", "but", "the", "constructor", "isn", "t", "I", "was"];
  const ZERO = new Decimal(0);
  const roleWordScore = new Decimal(0.1);

  for (const word of words) {
    let counter = wordScoreCommentDetails[word] || ZERO;
    counter = counter.plus(roleWordScore);

    wordScoreCommentDetails[word] = counter;
  }

the word constructor can't be used as a key or it's touching the object constructor

const wordScoreCommentDetails: { [key: string]: Decimal } = {};
  const words = ["function", "was", "async", "but", "the", "constructor", "isn", "t", "I", "was"];
  const ZERO = new Decimal(0);

  for (const word of words) {
    let counter = wordScoreCommentDetails[word] || ZERO;
    wordScoreCommentDetails[word] = counter;
  }

  console.log("scoringDetails: ", wordScoreCommentDetails);
scoringDetails:  {
  function: 0,
  was: 0,
  async: 0,
  but: 0,
  the: 0,
  constructor: [Function: Object],
  isn: 0,
  t: 0,
  I: 0
}

@Keyrxng
Copy link
Member

Keyrxng commented Mar 14, 2024

_getWordsNotInDisabledElements() seems like the only sort of 'blacklist' but it's for elements as opposed to literal strings, have I missed in it the codebase or is there a need to add something like it for literals?

@0x4007
Copy link
Member Author

0x4007 commented Mar 14, 2024

No there is no blacklist for words. Great find @Keyrxng!

@Keyrxng
Copy link
Member

Keyrxng commented Mar 14, 2024

No there is no blacklist for words. Great find @Keyrxng!

What's the approach then just wrap it in a try catch and log the failed word(s) or implement something a bit more robust?

It might be an idea to exclude reserved words like ["constructor", "toString", "prototype", etc] but it'll essentially be the same as try, catch, log wouldn't it and would need manually updated if more are found

@0x4007
Copy link
Member Author

0x4007 commented Mar 14, 2024

You can dynamically generate a blacklist based on all of the properties of the scoringDetails object.

It's not the right approach but we are going to have a brand new codebase to replace all this soon enough.

The alternative would be to design some type of encoding schema that will guarantee no collisions with the built in object properties (base64?) or alternatively just using some type of different data type to handle these words.

Copy link

ubiquibot bot commented Mar 14, 2024

+ Evaluating results. Please wait...

Copy link

ubiquibot bot commented Mar 14, 2024

[ 66 WXDAI ]

@pavlovcik
Contributions Overview
ViewContributionCountReward
IssueSpecification141.8
IssueComment218
ReviewComment16.2
Conversation Incentives
CommentFormattingRelevanceReward
There's an issue I've never seen before. Please research a solut...
41.8
code:
  count: 1
  score: "1"
  words: 0
141.8
No there is no blacklist for words. Great find @Keyrxng!...
20.742
You can dynamically generate a blacklist based on all of the pro...
16
code:
  count: 1
  score: "1"
  words: 1
0.67516
You can definitely include `my.ts` as a jest test. Just name it ...
6.2
code:
  count: 1
  score: "2"
  words: 2
0.626.2

[ 11.6 WXDAI ]

@molecula451
Contributions Overview
ViewContributionCountReward
IssueComment13.2
ReviewComment18.4
Conversation Incentives
CommentFormattingRelevanceReward
relates to the [decimal.js](https://www.npmjs.com/package/decima...
3.2
a:
  count: 1
  score: "1"
  words: 2
0.833.2
the only viable way i'd see testing this in a production like en...
8.40.558.4

[ 75 WXDAI ]

@Keyrxng
Contributions Overview
ViewContributionCountReward
IssueTask175
IssueComment40
Conversation Incentives
CommentFormattingRelevanceReward
It looks like it's failing for the word "constructor" as far as ...
-
li:
  count: 2
  score: "0"
  words: 8
code:
  count: 1
  score: "0"
  words: 2
0.78-
this fails in and of itself
 const wordScoreCommentDet...</a></h6></td><td><details><summary>-</summary>
<pre>code:
  count: 3
  score: "0"
  words: 0
</pre>
</details></td><td>0.62</td><td>-</td></tr><tr><td><h6><a href="https://github.com/ubiquibot/comment-incentives/issues/31#issuecomment-1997305383">``_getWordsNotInDisabledElements()`` seems like the only sort of...</a></h6></td><td><details><summary>-</summary>
<pre>code:
  count: 1
  score: "0"
  words: 1
</pre>
</details></td><td>0.56</td><td>-</td></tr><tr><td><h6><a href="https://github.com/ubiquibot/comment-incentives/issues/31#issuecomment-1997425173">> No there is no blacklist for words. Great find @Keyrxng!

Wh...</a></h6></td><td>-</td><td>0.71</td><td>-</td></tr></tbody></table>
  </details>
  
<!-- Ubiquity - Transactions - generatePermits - 90d7570
[
  {
    "permit": {
      "permitted": {
        "token": "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d",
        "amount": "66000000000000000000"
      },
      "nonce": "28989407596646675201937016975650893538129871437556580941966969832047589362899",
      "deadline": "115792089237316195423570985008687907853269984665640564039457584007913129639935"
    },
    "transferDetails": {
      "to": "0x4007CE2083c7F3E18097aeB3A39bb8eC149a341d",
      "requestedAmount": "66000000000000000000"
    },
    "owner": "0x44Ca15Db101fD1c194467Db6AF0c67C6BbF4AB51",
    "signature": "0x967ea690d126f1a35282f7dfbb15fadab22f4f9cb82ca57a8dbfc1b4a64de0155ef57a606917dc5ebdda0d5253b726e9d7356ef15e41f19a1c4037c4bea389c21b",
    "networkId": 100
  },
  {
    "permit": {
      "permitted": {
        "token": "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d",
        "amount": "11600000000000000000"
      },
      "nonce": "71629370266847490514228443997854799963593734248302674675453669654065814931598",
      "deadline": "115792089237316195423570985008687907853269984665640564039457584007913129639935"
    },
    "transferDetails": {
      "to": "0x4D0704f400D57Ba93eEa88765C3FcDBD826dCFc4",
      "requestedAmount": "11600000000000000000"
    },
    "owner": "0x44Ca15Db101fD1c194467Db6AF0c67C6BbF4AB51",
    "signature": "0x134f9ce9c8d0724a03530bfcddfff926c4af14b30265303d7b3218cc801e4f881d4da6f831a629488d7ef610a1447ad104076b441ed4f002aa37ae106923c4681b",
    "networkId": 100
  },
  {
    "permit": {
      "permitted": {
        "token": "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d",
        "amount": "75000000000000000000"
      },
      "nonce": "71196019213477808186309411334486208357124134992422917197907464507431026548680",
      "deadline": "115792089237316195423570985008687907853269984665640564039457584007913129639935"
    },
    "transferDetails": {
      "to": "0xAe5D1F192013db889b1e2115A370aB133f359765",
      "requestedAmount": "75000000000000000000"
    },
    "owner": "0x44Ca15Db101fD1c194467Db6AF0c67C6BbF4AB51",
    "signature": "0xea96af98247477aa978b8f0b8d4ed7c5edd59b98acb3616fb470b81ce9f2f6f2762ac3c93157531dff1599f6db7041842c8de7a0df48940949009b4247fb85351b",
    "networkId": 100
  }
]
-->

@molecula451
Copy link
Contributor

working https://github.com/ubiquibot/comment-incentives/actions/runs/8288619639, nice hack! @Keyrxng

@Keyrxng
Copy link
Member

Keyrxng commented Mar 14, 2024

I'm full of them 😂

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants