繁体   English   中英

这个未知错误来自何处以及如何防止它发生?

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

已解决谢谢所有帮助我使用Firefox中的调试器跟踪此错误的人,该错误称为“错误:超出了最大执行时间”。 希望这个问题以后能对您有所帮助。

我希望有人可以解释这个未捕获的错误,并告诉我如何防止它。

我正在开发一个用于图书馆使用Google App Script收集使用情况报告的系统,到目前为止,我们的系统已经成功地将报告导入Google云端硬盘。 但是,最近,当我们测试收集所有功能时,控制台中会出现一个未知错误消息,而没有任何指示它是什么类型的错误,并且正在显示一条源于我们代码的路径。 我想知道有人遇到过此错误吗? 有解释吗? 以及如何预防呢?

如果不将报告上传到Google云端硬盘,则这段代码实际上可以正常工作,但是一旦我将函数与parser挂钩并将解析后的报告上传到Google云端硬盘,就会发生此错误。
(英语不是我的母语,因此,如果我的表情引起任何混乱,我深感抱歉)
以下是html代码:

<!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>

我还添加了样式表,以防万一。

<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>

这就是我要调用的服务器。 harvestVendorList all是一个没有id的按钮,因此在调用此函数时, harvestVendorList两个参数harvestVendorList undefined

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

而且在服务器中,由于vendorNametypeharvestVendorList参数)都undefined 它将转到代码的else部分以运行供应商列表。 调用parseSelect()之后,我什么也不能提供,因为在那之后将是队友的代码,而我对这些组件并不熟悉。 我知道这还远远不够,但我现在真的无法提供更多信息。 如果以后可以添加更多详细信息,我将继续在此处发布。 现在,很抱歉,如果信息太少。

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;
}

这就是控制台中的错误。

未捕获
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
(匿名)@ 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

(我知道这很难看,但是我只能得到图片的链接,并且它的结尾。)
(错误只是未捕获的错误,仅此而已,这就是为什么我无法找到与此错误有关的任何信息的原因。)
(我的操作系统是中文,因此在英语环境中进行测试时,最后几个字符表示中文操作系统环境,它将更改为其他内容。)

这是我从该未捕获函数的源中复制的内容。 错误来自Error(b),我不知道它是什么。

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

安慰:

更新:
添加withFailureHandler(function(e){console.error(e)})后,错误将在控制台中更改为: 添加失败处理程序后 ,错误来自此userCodeAppPanel

谢谢所有帮助我跟踪此错误的人。 使用Firefox中的调试器,该错误称为“错误:超出了最大执行时间”。
由于某些原因,Chrome控制台中未显示此错误。
跟踪此问题的另一种方法是使用view> execution跟踪项目中运行的每个函数。
我希望这可以对以后在Google Apps脚本开发中遇到相同问题的人有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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