Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function _copyAttributes() revealing error in input data #162

Open
arvgta opened this Issue Jan 9, 2019 · 4 comments

Comments

Projects
None yet
2 participants
@arvgta
Copy link
Owner

commented Jan 9, 2019

A user reported an error being thrown by _copyAttributes()

EDIT: This may not be an error in the function _copyAttributes(), but rathermore in the use-case input itself (corrupt jQuery selector or attributes)

Nevertheless, the question remains:

Should error handling be built into Ajaxify, when corrupt input data is detected?

@arvgta arvgta added the bug label Jan 9, 2019

@arvgta arvgta changed the title Bug in new function _copyAttributes() New function _copyAttributes() revealing error Jan 10, 2019

@arvgta arvgta added question and removed bug labels Jan 10, 2019

@arvgta arvgta changed the title New function _copyAttributes() revealing error New function _copyAttributes() revealing error in input data Jan 10, 2019

@arvgta arvgta closed this Jan 12, 2019

@arvgta arvgta reopened this Mar 25, 2019

@arvgta arvgta added the bug label Mar 25, 2019

@arvgta

This comment has been minimized.

Copy link
Owner Author

commented Mar 25, 2019

As this is the only error being reported in the last while, I have decided to re-open it.

Any ideas, how to handle this issue more gracefully?

Once more - here is the salient code:

function _copyAttributes(el, $S, flush) { //copy all attributes of element generically
    if (flush) //delete all old attributes
        for (var i = el.attributes.length - 1; i >= 0; i--) el.removeAttribute(el.attributes[i].name);

    var attr, attributes = Array.prototype.slice.call($S[0].attributes); //slice performs a copy, too
    while (attr = attributes.pop()) { //fetch one of all the attributes at a time
        el.setAttribute(attr.nodeName, attr.nodeValue); //low-level insertion
    }
}

The error occurs, when $S contains no or faulty data...

In course of the latest complaint, the user kindly suggested this:

You need to make it possible to "catch" this exception.
According to the standard, you can just alert() with a message, and for the developer the ability to make their own function, which will be called in error.

I would not like to employ an "alert", but would rather like to work with "try/catch/throw" etc.


I reckon, modifying the above code to the following may work:

function _copyAttributes(el, $S, flush) { //copy all attributes of element generically
    if (flush) //delete all old attributes
        for (var i = el.attributes.length - 1; i >= 0; i--) el.removeAttribute(el.attributes[i].name);

    var attr, attributes;

    try {
        attributes = Array.prototype.slice.call($S[0].attributes); //slice performs a copy, too
    } catch(e) {
        //What to put here?
    }

    while (attr = attributes.pop()) { //fetch one of all the attributes at a time
        el.setAttribute(attr.nodeName, attr.nodeValue); //low-level insertion
    }
}

...however, I don't have a clue, what to write in the catch branch instead of:

//What to put here?

e.g. :

  • Let Ajaxify throw a bespoke exception for the user to catch?
  • Write a logging message to the console?
@Seerver

This comment has been minimized.

Copy link

commented Mar 30, 2019

Hi, I wrote you an email.

arvgta added a commit that referenced this issue Apr 1, 2019

@arvgta

This comment has been minimized.

Copy link
Owner Author

commented Apr 1, 2019

Thanks for posting back - much appreciated!

For the moment, I have applied this patch, as indicated above already...

arvgta added a commit that referenced this issue Apr 24, 2019

Patch for issue #162 - deceptive error
No functional change, but getting rid of the nuissance described in issue #162
@arvgta

This comment has been minimized.

Copy link
Owner Author

commented Apr 24, 2019

I have patched this deceptive error in the latest release.

When caught, you should see the following text in the browser console:

  • "Bad input data"

The next question, that comes to my mind is whether this nuissance can be caught earlier, maybe even at first validaton during initialisation of Ajaxify?

If you happen to observe, that the error persists even when your data input (e.g. jQuery selector, HTML of content div etc.) is fine, then please write it in here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.