This topic contains 2 replies, has 0 voices, and was last updated by WakaWaka 5 years, 10 months ago.

  • Author
    Posts
  • #17788 Score: 0

    lw1
    • Contributions: 0
    • Level 1

    Such a powerful script type. Such a let down that we can’t debug them.

    Is anyone successfully able to run these in the script debugger and set breakpoints?

    Of course we can run the script dozens of times and log.debug JSON objects… or at least part of the JSON before it reaches the text limit.

    What’s the trick guys? Sure would speed things up having the ability to debug these types of scripts. We use them heavily.

    Thx in advance…
    This is a cached copy. Click here to see the original post.

  • #17789 Score: 0

    TheUsualSuspect
    • Contributions: 0
    • Level 1

    I write M/R scripts a lot and there is no sane way to debug them that i’ve found. NetSuite recommends you chop up each function to separate scripts and frankenstein to test but I have never done that. All you can do is log values and report errors

    Code:
    function summarize(summary) {
    try {

    var mapArr = [];
    summary.mapSummary.errors.iterator().each(function (key, value) {
    mapArr.push(JSON.stringify(JSON.parse(value).cause ));
    return true;
    });

    var reduceArr = [];
    summary.reduceSummary.errors.iterator().each(funct ion(key, value) {
    reduceArr.push(JSON.stringify(JSON.parse(value).ca use));
    return true;
    });

    if (mapArr.length > 0 || reduceArr.length > 0){
    log.error({ title: mapArr.length + ‘ Map (search) error(s) occured during script execution’, details: mapArr.join(‘n’) });
    log.error({ title: reduceArr.length + ‘ Reduce (deletion) error(s) occured during script execution’, details: reduceArr.join(‘n’) });
    } else if (mapArr.length === 0 && reduceArr.length === 0) {
    log.audit({ title: ‘summary’, details: ‘Script finished execution without errors’ });
    }

    log.audit({ title: ‘Map Time Total (seconds)’, details: summary.mapSummary.seconds });
    log.audit({ title: ‘Reduce Time Total (seconds)’, details: summary.reduceSummary.seconds });
    log.audit({ title: ‘Max Concurrency Utilized ‘, details: summary.reduceSummary.concurrency });
    log.audit({ title: ‘END’, details: ” });

    } catch (errorObj) {
    log.error({ title: ‘(Summary) Error’, details: THLib.getErrorDetails(errorObj) });
    }
    }

  • #17790 Score: 0

    WakaWaka
    • Contributions: 0
    • Level 1

    Here are a few things I like to do:

    1. Set the concurrency limit to 1. This can help you make more sense out of the log statements since you will see the output of each call to map/reduce one-by-one in order.

    2. At the top of the map or reduce function, I like to do something like this

    Code:
    if (context.key !== YOUR_SUSPECTED_PROBLEM_KEY_GOES_HERE) {
    return;
    }
    Then you can test a single call to map/reduce.

You must be logged in to reply to this topic.