First of all, kudos to the super cool tool ! π
I have no idea how emojis work. But I was looking for some cli tool to easily copy emojis and your tool was perfect! I loved it and the --dango
option is pretty cool π But the first time I used it, it gave me an error and I kept trying the same thing and got the same error. I was pretty pissed at first π then I was like "Let's debug this and send a PR may be?" and I started checking it out today even though I had no idea I was looking for. But I thought I will just give it a try. The error occurred when I typed the search query cool
and it gave me an error like this :
redux-saga error: uncaught
at currentQueryChanged
at takeLatest(ADD_CHARACTER,REMOVE_CHARACTER,SUBMIT, searchDango)
at searchDango
TypeError: Cannot read property 'output' of undefined
at /Users/karuppiah/.npm/_npx/75041/lib/node_modules/emoji-finder/lib/sagas.js:161:27
at Array.map (<anonymous>)
at searchDango$ (/Users/karuppiah/.npm/_npx/75041/lib/node_modules/emoji-finder/lib/sagas.js:152:31)
at tryCatch (/Users/karuppiah/.npm/_npx/75041/lib/node_modules/emoji-finder/node_modules/regenerator-runtime/runtime.js:64:40)
at Generator.invoke [as _invoke] (/Users/karuppiah/.npm/_npx/75041/lib/node_modules/emoji-finder/node_modules/regenerator-runtime/runtime.js:355:22)
at Generator.prototype.(anonymous function) [as next] (/Users/karuppiah/.npm/_npx/75041/lib/node_modules/emoji-finder/node_modules/regenerator-runtime/runtime.js:116:21)
at next (/Users/karuppiah/.npm/_npx/75041/lib/node_modules/emoji-finder/node_modules/redux-saga/lib/internal/proc.js:306:27)
I even recorded the error with asciinema https://asciinema.org/a/196964
After some digging and debugging and some searching, I finally found that the error is occurring when dango sends a response with emojis with variation selector in it https://www.fileformat.info/info/unicode/char/fe0f/index.htm . I didn't know much, I was just experimenting with what punycode
did with encoding codepoints and saw the difference between these two
> console.log(punycode.ucs2.encode([0x270C]))
β
undefined
> console.log(punycode.ucs2.encode([0x270C, 0xFE0F]))
βοΈ
undefined
The above doesn't show any difference in markdown, but in my terminal the first one doesn't have colors, and second one has it. I found this as one of the responses from dango for cool
was this and that's why I got the above error. I understood that there was some undefined
value from the error and looked for it, and after lots of checking, I understood that the bug was due to this line :
https://github.com/dematerializer/emoji-finder/blob/master/src/sagas.js#L64
where the seqHex
created using the dango emoji is compared with the annotation sequence alone, but looks like it has to be compared with annotation's variation presentation too, like the annotation.presentation.variation.text
, annotation.presentation.variation.emoji
, and may be the annotation.presentation.default
too? but looks like this is the same as the sequence. not sure thoughπ
I modified a few lines and tried this :
const isAnnotationEqualToHexCode = (ann, seqHex) => {
const { sequence, presentation = {} } = ann;
const { default: defaultPresentation = '', variation = {} } = presentation;
const { text = '', emoji = '' } = variation;
return (
sequence === seqHex ||
defaultPresentation === seqHex ||
text === seqHex ||
emoji === seqHex
);
};
...
...
const annotation = annotations.find(ann =>
isAnnotationEqualToHexCode(ann, seqHex),
) || {
output: '',
tts: '',
keywords: [''],
};
I also put a default value just in case it can't find any matching annotation. Let me know if this looks good, I can send a PR π I also recorded how the output looks after the above changes :
https://asciinema.org/a/196968