Giter Club home page Giter Club logo

Comments (5)

unscriptable avatar unscriptable commented on June 1, 2024

Hey @azazel75,

There's definitely some anomalies in the logic in this plugin. For instance, I noticed that the success path is different if the strictJSONParse config property is truthy. (e.g. strictJSONParse: true). If you have a minutes and can try setting that in a curl() or curl.config() call, that would be helpful.

I will continue to research and add tests...

-- J

from curl.

unscriptable avatar unscriptable commented on June 1, 2024

Nm. I cloned your example repo and tried it. This looks like a problem with all plugins specified in a call to curl([]).

from curl.

unscriptable avatar unscriptable commented on June 1, 2024

Actually, it seems like it's just a problem with json!, style!, and locale! plugins. Each of these plugins catches errors that are thrown from the success callbacks (which ultimately call the bootstrap success callback). The plugins send the error back into curl's loading mechanics which detects and suppresses multiple callbacks/errbacks. In short, the error is suppressed on purpose. The fix is to stop catching errors that happen in callbacks -- only catch errors that throw during fetch/processing of resources.

from curl.

unscriptable avatar unscriptable commented on June 1, 2024

Here's the updated curl/plugin/json.js if you want to proceed. I'll continue to fix & test the other plugins.

/** MIT License (c) copyright 2010-2013 B Cavalier & J Hann */

/**
 * curl json! plugin
 *
 * Like the text! plugin, will only load same-domain resources.
 */

(function (globalEval) {
define(/*=='curl/plugin/json',==*/ ['./_fetchText'], function (fetchText) {

    var hasJsonParse, missingJsonMsg;

    hasJsonParse = typeof JSON != 'undefined' && JSON.parse;
    missingJsonMsg = 'Cannot use strictJSONParse without JSON.parse';

    return {

        load: function (absId, require, loaded, config) {
            var evaluator, errback;

            errback = loaded['error'] || error;

            // create a json evaluator function
            evaluator = config.strictJSONParse
                ? guard(parseSource, loaded, errback)
                : guard(evalSource, loaded, errback);

            // get the text, then eval it
            fetchText(require['toUrl'](absId), evaluator, errback);

        },

        'cramPlugin': '../cram/json'

    };

    function error (ex) {
        throw ex;
    }

    function evalSource (source) {
        return globalEval('(' + source + ')');
    }

    function parseSource (source) {
        if (!hasJsonParse) throw new Error(missingJsonMsg);
        return JSON.parse(source);
    }

    function guard (evaluator, success, fail) {
        return function (source) {
            var value;
            try {
                value = evaluator(source);
            }
            catch (ex) {
                return fail(ex);
            }
            return success(value);
        }
    }

});
}(
    function () {/*jshint evil:true*/ return (1,eval)(arguments[0]); }
));

from curl.

azazel75 avatar azazel75 commented on June 1, 2024

It works!

from curl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.