invicticide / fractive

Fractive is a free, open-source, Markdown-based hypertext authoring tool for writing interactive fiction.
http://fractive.io
Other
37 stars 5 forks source link

Bad error message when function link function is undefined #74

Open NQNStudios opened 6 years ago

NQNStudios commented 6 years ago

What happened

I had mis-typed the name of a function in a function link. When clicking the link to go to the section containing the function link, the section link would become disabled, and the console would error: TypeError: Argument 2 of EventTarget.addEventListener is not an object.

As far as I can tell, the issue is that RegisterLinks() is failing to register the links in the new section, and never visiting the new section at all. So it seems like the error is actually coming from a different section than the one it is.

Steps to reproduce

{{Start}}

[Link1]({@Section2})

{{Section2}}

[Link2]({#notARealFunction})

Expected behavior

An error message should point out that the function doesn't exist, and print the name. Maybe it should even make the second section appear, but with the broken link highlighted red or something.

invicticide commented 6 years ago

If you still see RegisterLinks being called then you're behind the main repo, since that's been refactored to ActivateElement now. But with that being said, I suspect the issue is that in ActivateElement, we do this for a function link:

case "data-call-function":
{
    element.addEventListener("click", RetrieveFromWindow(element.attributes[i].value, 'function'));
    break;
}

Note that if RetrieveFromWindow hands back a null then we're going to try to bind a null function to the "click" event listener, which is probably the root cause of the error.

NQNStudios commented 6 years ago

You're right, it is ActivateElement. I just didn't look too closely at the source.