j-holub / Node-MPV

A NodeJs Module for MPV Player
https://www.npmjs.com/package/node-mpv
MIT License
116 stars 73 forks source link

mpv.load: "Cannot read property trim of undefined" #47

Closed shabunin closed 4 years ago

shabunin commented 6 years ago

First of all, thanks for this work.

Now, to the issue. I'm using v2 of this module and was trying to load url with mpv.load function and got unexpected behavior and error "Cannot read property trim of undefined". So, I took a look at source and there is check if that function was called via load() or append() for error handling purposes (here comes irony), done by regexp. So, I took a look at stackMatch variable and mine was [ 'mpv.load ', 'mpvLoad ' ]. mpvLoad is function written by me and from it I call mpv.load(url);

So, it seems that split('.')[1].trim() is not the best way to check caller or may be you should change regexp(I'm not strong in it).

j-holub commented 6 years ago

Hey there,

sorry for the late reply, I got the Email Notification on my phone right away, read it and somehow forgot to reply.

I kinda have a feeling where the problem is coming from. My guess is, that the problem is, that your function has "mpv" in the name, but this shouldn't be a problem so this has to be fixed. I'll have a look.

shabunin commented 6 years ago

Line 78 of mpv.js: const caller = stackMatch[stackMatch.length-1].split('.')[1].trim() + '()'

My function is "mpvLoad" and I believe that I will be not the only one who give such names. So, regex new Error().stack.match(/mpv.\w+\s/g); creates array of two elements: [ 'mpv.load', 'mpvLoad' ]. So, last one is mpvLoad and can't be splitted by split('.')

So, I would reconsider error handling to avoid this issues in future.

j-holub commented 6 years ago

Yeah that's exactly what I thought. I'll see how I can fix that

j-holub commented 4 years ago

This should be fixed by c7075120235b5b379e10a691da51a903c87df61c if it's actually still relevant to you at all at this point.