-
Notifications
You must be signed in to change notification settings - Fork 12
TypeError: counter.plus is not a function
#31
Comments
relates to the decimal.js package
|
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 |
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
} |
|
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 |
You can dynamically generate a blacklist based on all of the properties of the 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. |
+ Evaluating results. Please wait... |
I'm full of them 😂 |
There's an issue I've never seen before. Please research a solution before we fund this issue.
Source https://github.com/ubiquibot/comment-incentives/actions/runs/8002349026/job/21855360540#step:5:262
Related ubiquity/nft-rewards#3 (comment)
The text was updated successfully, but these errors were encountered: