简体   繁体   中英

Where is this unknown error coming from and how to prevent it?

solved Thank you all who have helped me tracking this error, with the debugger in Firefox, the error is called "Error: Exceeded maximum execution time." Hope this question can help someone later.

I am hoping someone who can explain this uncaught error and tell me how to prevent it.

I am developing a system for the library to harvest usage reports using Google App Script and our system is successful so far to get reports into Google Drive. However, lately, when we are testing the harvesting all function an unknown error message comes up in the console without any indication what type error it is and is showing a path where does not come from our code. I am wondering has anyone ever encountered this error? Is there an explanation for it? and how to prevent it?

This code is actually working fine if not uploading the reports into the Google Drive, but once I hooked my function with the parser and upload the parsed report into the Google Drive this error will happen.
(English is not my first language so I am sorry if my expressions are causing any confusions)
Here are the html codes:

<!DOCTYPE html>
<html>
<head>
    <!--import libraries-->
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
    <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
    <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>

/....../(load CSS, scripts)

<div data-role="page" id="main">
/....../(headers, navibar)

<div class='row'>
        <div class="column">
            <div class='row'>
                <h2>Harvest All</h2>
                <p>
                    <button type="submit" class='btn-harvest-vendor'>
                        <i class="material-icons" id="all">get_app</i>
                    </button>
                </p>
            </div>
        <div class="column">
            <div data-role="link" class="ui-content">
                <h2><a id="error-report" href="#error-dialog">Error Report</a></h2>
            </div>
        </div>
    </div>

    <div class='row' id='statusTable'>
        <h2>Vendor Finder</h2>
        <table id="status">
            /....../(loading status table with template, I know it's not idea, but I had an issue with using an asynchronous function to create the table back then.)
        </table>
    </div>
</div>

<!--create error report dialog content-->
<div data-role="page" data-dialog="true" id="error-dialog">
    <div data-role="header">
        <h1>Error Report</h1>
    </div>

    <div data-role="main" class="ui-content">
        <p id="errors"></p>
    </div>

    <div data-role="footer">
        <h1>Remember to refresh the page for updated status!</h1>
    </div>
</div>


<script>
    /** determines which function gets called in scripts.html */
    $('.btn-harvest-vendor').on('click', btnClassVendor).promise();
    $('.btn-retry-report').on('click', btnClassReport).promise();
</script>

</body>
</html>

I am also adding the stylesheet just in case.

<style>
    /* Style the header */
    .header {
        background-color: #f1f1f1;
        padding: 20px;
        text-align: center;
    }

    /* navigation bar style */
    ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: royalblue;
    }

    li {
        float: left;
    }

    li a {
        display: block;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
    }

    li a:hover {
        background-color: #117;
    }

    /* Create three equal columns that floats next to each other */
    .column {
        float: left;
        text-align: center;
        width: 33.33%;
    }

    .column-instruction {
        float: left;
        text-align: center;
        width: 33.33%;
        text-align: left;
    }


    /* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
    @media screen and (max-width: 600px) {
        .column,.column-instruction {
            width: 100%;
        }
    }

    /* Clear floats after the columns */
    .row:after {
        content: '';
        display: table;
        clear: both;
        padding: 20px;
    }


    /* button style */
    .btn-harvest-vendor, .btn-retry-report {
        background-color: white;
        border: none;
        color: black;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        cursor: pointer;
    }

    /* table settings */
    #myInput {
        font-size: 16px; /* Increase font-size */
        padding: 12px 20px 12px 40px; /* Add some padding */
    }

    #status {
        border-collapse: collapse; /* Collapse borders */
        width: 100%; /* Full-width */
        border: 1px solid #ddd; /* Add a grey border */
        font-size: 18px; /* Increase font-size */
    }

    #status th, #status td {
        text-align: center; /* center-align text */
        padding: 5px; /* Add padding */
    }

    #status tr {
        /* Add a bottom border to all table rows */
        border-bottom: 1px solid #ddd;
    }

    #status tr.header, #status tr:hover {
        /* Add a grey background color to the table header and on hover */
        background-color: #f1f1f1;
    }

    .float-right-nav {
        float: right;
    }

    .period {color:red;}

    #all {font-size:50px;}

    #unsupported {color:red;}

    #navi-ref {
        text-shadow: none;
        color: white;
    }
</style>

This is what I am doing for calling to the server. The harvesting all is a button without id so when this function is called, both two parameters of harvestVendorList are undefined .

var btnClassVendor = function(e){
google.script.run.withSuccessHandler(onSuccessVendor).harvestVendorList(e.currentTarget.id,null);
}

And in the server, since both vendorName and type (arguments of harvestVendorList ) is undefined . It will go to the else part of the code to run through the vendor list. I can't provide anything after calling parseSelect() because after that will be my teammates' codes and I am not familiar with those components. I know this is far from enough information but I really can't provide more for now. If later I can add more details I will keep posting here. Right now, sorry if the information is too less.

function harvestVendorList(vendorName, type) {
    var vendorSpreadsheet = SpreadsheetApp.openByUrl(vendorListUrl).getSheets()[0];
    var statusSpreadsheet = SpreadsheetApp.openByUrl(reportStatusUrl).getSheets()[0];
    var statusHeaders = statusSpreadsheet.getRange(1, 1, 1, statusSpreadsheet.getLastColumn()).getValues()[0];
    var vendorList = ObjApp.rangeToObjects(vendorSpreadsheet.getDataRange().getValues());
    var statusList = ObjApp.rangeToObjects(statusSpreadsheet.getDataRange().getValues());
    errors = "<p>";
    if (vendorName) {
        /....../(code for harvesting a vendor or a specific report)
    }
    else {
        for (var i in vendorList) {
            Logger.log("harvesting, vendor:" + vendorList[i].vendor);
            /** call function to harvest vendor */
            harvestVendor(vendorList[i], statusList[i]);
            Logger.log(i + " DONE!");
        }
    }
    /....../(code for writing updated status back to the google sheet)
    errors += "</p>";
    return errors;
}
function harvestVendor(vendor, status) {
    var date = new Date();
    var year = date.getYear();
    var month = date.getMonth();
    /** get vendor name for logging error message */
    var vendorName = vendor.vendor;
    for (var i in vendor) {
        if (i != "rowNum" && i != "vendor" && vendor[i]) {
            var requestUrl = createURL(vendor[i], year, month);
            var reportType = i.toUpperCase();
            try {
                var data = harvest(requestUrl);
                if (data[0] == 0) {
                    errors += (error messages);
                    status[i] = 0;
                    continue;
                }
                if (data[0] == 3) {
                    errors+=(error messages);
                    status[i] = 0;
                    continue;
                }
                if (data[0] == 2) {
                    errors+=(error messages);
                    status[i] = 0;
                    continue;
                }
            }
            catch (e) {
                errors += (error messages);
                continue;
            }
            status[i] = 1;

/**this is the parsing funcions*/

            try {
                parseSelect(data[1], vendorName, getPeriod());
            }
            catch (e) {
                errors += (error messages);
                status[i] = 2;
                continue;
            }
            /....../(checking exceptions)
            /** set 1 sec period between each harvest */
            Utilities.sleep(1000);
        }
    }
    status.last = Utilities.formatDate(date, "GMT", "yyyy.MM.dd");
}
function harvest(request) {
    var response = UrlFetchApp.fetch(encodeURI(request), { muteHttpExceptions: true });
    var content = response.getContentText();

    var returnType;

    try {
        /**checking returning types*/
        if(response valid)
            returnType=1;
        /**response is an array*/
        else if(content.substring(0,1) == "[" )
            returnType=2
        /**response is an object*/
        else if(content.substring(0,1)=="{")
            returnType=3;
        /**if the response is not valid*/
        else
            returnType=0;
    }
    /**if any exception happens*/
    catch(e){Logger.log(e);}

    /**if the response is valid*/
    if (returnType > 0)
        var data = JSON.parse(content);
    Logger.log("return type: " + returnType);
    /**store the type and data in an array*/
    var result = [returnType, data];
    return result;
}

This is what the error looked like in the console.

Uncaught
Md @ 420326566-mae_html_user_bin_i18n_mae_html_user__zh_cn.js:44
Qe @ 420326566-mae_html_user_bin_i18n_mae_html_user__zh_cn.js:59
(anonymous) @ 420326566-mae_html_user_bin_i18n_mae_html_user__zh_cn.js:6
cg.K @ 420326566-mae_html_user_bin_i18n_mae_html_user__zh_cn.js:86
vd @ 420326566-mae_html_user_bin_i18n_mae_html_user__zh_cn.js:35
rd @ 420326566-mae_html_user_bin_i18n_mae_html_user__zh_cn.js:36
b @ 420326566-mae_html_user_bin_i18n_mae_html_user__zh_cn.js:32

(I know this is hard to read but I can only get a link for the picture and it is at the end.)
(The error is just Uncaught and has nothing else, that's why I can't find anything about this error.)
(My OS is in Chinese so the last few characters are indicating Chinese OS environment when testing in an English environment it will change to something else.)

Here is what I copied from the source of that uncaught function. The error is coming from the Error(b) which I have no idea what it is.

function Md(a, b) {
        b = Error(b);
        b.name = a;
        return b
}

Console:

Updates:
After adding withFailureHandler(function(e){console.error(e)}), the error is changed to this in console: After adding failure handler and the error is coming from this userCodeAppPanel

Thank you all who have helped me tracking this error. With the debugger in Firefox, the error is called "Error: Exceeded maximum execution time."
For some reason, this error is not showing in the Chrome console.
Another way to track this is to use the view>execution for tracking each function run in the project.
I am hoping this could help someone who had the same issue later in their development in Google Apps Script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM