CN112948726A - Method, device and system for processing abnormal information - Google Patents

Method, device and system for processing abnormal information Download PDF

Info

Publication number
CN112948726A
CN112948726A CN202110332753.2A CN202110332753A CN112948726A CN 112948726 A CN112948726 A CN 112948726A CN 202110332753 A CN202110332753 A CN 202110332753A CN 112948726 A CN112948726 A CN 112948726A
Authority
CN
China
Prior art keywords
information
exception
abnormal
node
code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110332753.2A
Other languages
Chinese (zh)
Inventor
孟繁贵
梁锐
邢磊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
CCB Finetech Co Ltd
Original Assignee
CCB Finetech Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by CCB Finetech Co Ltd filed Critical CCB Finetech Co Ltd
Priority to CN202110332753.2A priority Critical patent/CN112948726A/en
Publication of CN112948726A publication Critical patent/CN112948726A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/955Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
    • GPHYSICS
    • G06COMPUTING; CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing

Abstract

The invention discloses a method, a device and a system for processing abnormal information, and relates to the technical field of mobile interconnection and automatic program design. One embodiment of the method comprises: the method comprises the steps of generating an abstract syntax tree based on an applied source code, searching a node to be processed from the abstract syntax tree, generating a new abstract syntax tree after adding exception handling information to the node, generating an applied target code based on the new abstract syntax tree, and acquiring the exception information of the application through a newly added exception handling module.

Description

Method, device and system for processing abnormal information
Technical Field
The invention relates to the technical field of mobile interconnection and automatic program design, in particular to a method, a device and a system for processing abnormal information.
Background
With the rapid development of internet technology, internet application based on the internet technology becomes an indispensable tool in the work and life of people; the stability of the internet application operation is very important to maintain, so that capturing abnormal information generated in the internet application operation in time becomes one of important operation and maintenance work.
The current method for processing abnormal information is that operation and maintenance personnel obtain the abnormal information generated when the internet application runs by looking at a console of a browser; and adopting a corresponding repairing method according to the abnormal information; however, such a method for processing the abnormal information has the problems of low efficiency, poor instantaneity for acquiring the abnormal information, and high operation complexity.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method, an apparatus, and a system for processing exception information, which can generate an abstract syntax tree based on an application source code, search a node to be processed from the abstract syntax tree, generate a new abstract syntax tree after adding exception processing information to the node, and generate an application target code based on the new abstract syntax tree, so as to obtain the application exception information through the newly added exception processing code, improve efficiency of processing exception information by automatically adding the exception processing code to the source code, improve instantaneity of obtaining exception information, and overcome a problem that an operation and maintenance worker has a high operation complexity.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a method of processing exception information, including: acquiring a source code of an application, and generating an abstract syntax tree for the source code; searching a node matched with a preset feature identifier from the abstract syntax tree; adding set exception handling information for the searched node in the abstract syntax tree; generating object code based on the abstract syntax tree to which the exception handling information is added, the object code including exception handling code generated based on the exception handling information; and responding to the triggering operation of the application, running the target code, and processing the exception information generated by the application through the exception handling code.
Optionally, the method of handling exception information,
the preset feature identifier comprises any one of a function declaration identifier, a function expression identifier and an arrow function identifier.
Optionally, the method for processing exception information, where the abstract syntax tree generated for the source code includes: analyzing the source code; and generating an abstract syntax tree according to one or more nodes and node contents included by the analyzed result.
Optionally, the method for processing exception information is further characterized by:
and acquiring the searched node content of the node, judging whether the node content meets the condition of adding the abnormal processing information, if so, executing the step of adding the corresponding abnormal processing information for the searched node, otherwise, not adding the corresponding abnormal processing information for the node.
Optionally, the method for processing exception information, where determining whether the content of the node meets a condition for adding exception processing information includes:
judging whether the node content contains a text matched with the abnormal processing information, if so, determining that the node content does not meet the condition of adding the abnormal processing information; otherwise, continuously judging whether the content of the node meets the condition of adding the abnormal processing information.
Optionally, the method for processing exception information, where determining whether the content of the node meets a condition for adding exception processing information includes:
judging whether the number of lines corresponding to the node content is smaller than a set line number threshold value, if so, determining that the node content does not meet the condition of adding abnormal processing information; otherwise, continuously judging whether the content of the node meets the condition of adding the abnormal processing information.
Optionally, the method for processing exception information, where determining whether the content of the node meets a condition for adding exception processing information includes:
judging whether a text indicating that exception processing is forbidden exists in the annotation text contained in the node content, if so, determining that the node content does not meet the condition of adding exception processing information; otherwise, continuously judging whether the content of the node meets the condition of adding the abnormal processing information.
Optionally, the method of handling exception information,
the exception handling information comprises matched captured exception information and exception reporting information;
adding corresponding exception handling information for the searched node, including: and acquiring the searched node content of the node, and adding the matched captured abnormal information and the abnormal reporting information based on the node content.
Optionally, the method for processing exception information, wherein generating object code includes: according to the capture abnormal information, adding capture abnormal codes on the outer layer of the source codes corresponding to the node contents; and adding an abnormal reporting code for the source code corresponding to the node content according to the abnormal reporting information.
Optionally, the method for processing exception information, where processing exception information generated by the application through the exception handling code includes: capturing exception information corresponding to the node content through one or more capture exception codes; and reporting the abnormal information to a server through the abnormal reporting code.
Optionally, the method for processing exception information is further characterized by:
the exception reporting code comprises a picture constructing submodule and a reporting submodule;
processing exception information generated by the application through the exception handling code, including:
constructing a reference picture for the abnormal information generated by the application through the picture construction sub-module, binding the abnormal information with the reference picture, and generating a corresponding picture identifier for the reference picture bound with the abnormal information; and splicing the server address reporting the abnormal information, the picture identifier and the abnormal information into a uniform resource locator through the reporting submodule, and reporting the abnormal information to a server corresponding to the server address by using the uniform resource locator.
Optionally, the method for processing exception information is further characterized by:
creating a plug-in to generate an abstract syntax tree for the source code by using the plug-in, adding the set exception handling information to the node found in the abstract syntax tree, and generating the corresponding exception handling code based on the exception handling information.
Optionally, the method for processing exception information is further characterized by:
acquiring abnormal information of the applied node from a server; the exception information comprises a plurality of pieces of sub information; and summarizing the sub-information according to the category aiming at the node, and carrying out visual display on the sub-information so as to display the abnormal information of the applied node in a classified manner.
To achieve the above object, according to a second aspect of the embodiments of the present invention, there is provided a method of processing exception information, including: receiving one or more requests for reporting abnormal information; respectively acquiring corresponding abnormal information from the uniform resource locators corresponding to the requests; analyzing the abnormal information based on a plurality of preset information categories; and classifying and storing the sub-information corresponding to each information category included in the analysis result.
Optionally, the method for processing exception information is further characterized by: and responding to the received abnormal information display request, and sending the sub-information corresponding to each classified and stored information category to a client side so as to perform classified display on the client side.
To achieve the above object, according to a third aspect of the embodiments of the present invention, there is provided a client for processing exception information, including: the system comprises a node searching module, an addition exception handling module and an exception information handling module; wherein the content of the first and second substances,
the node searching module is used for acquiring a source code of an application and generating an abstract syntax tree for the source code; searching a node matched with a preset feature identifier from the abstract syntax tree;
the addition exception handling module is used for adding set exception handling information for the searched node in the abstract syntax tree; generating object code based on the abstract syntax tree to which the exception handling information is added, the object code including exception handling code generated based on the exception handling information;
and the exception information processing module is used for responding to the triggering operation of the application, running the target code and processing exception information generated by the application through the exception processing code.
To achieve the above object, according to a fourth aspect of the embodiments of the present invention, there is provided a server for processing exception information, including: the abnormal information analyzing module and the abnormal information storing module; wherein the content of the first and second substances,
the analysis abnormal information module is used for receiving one or more requests for reporting abnormal information; respectively acquiring corresponding abnormal information from the uniform resource locators corresponding to the requests; analyzing the abnormal information based on a plurality of preset information categories;
and the abnormal information storage module is used for classifying and storing the sub-information corresponding to each information category included in the analysis result.
To achieve the above object, according to a fifth aspect of the embodiments of the present invention, there is provided a system for processing exception information, including one or more clients for processing exception information according to the third aspect and a server for processing exception information according to the fourth aspect.
To achieve the above object, according to a sixth aspect of the embodiments of the present invention, there is provided an electronic device that processes exception information, including: one or more processors; a storage device for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement the method as in any one of the above methods of handling exception information.
To achieve the above object, according to a seventh aspect of embodiments of the present invention, there is provided a computer-readable medium on which a computer program is stored, characterized in that the program, when executed by a processor, implements the method as any one of the methods of processing abnormality information described above.
One embodiment of the above invention has the following advantages or benefits: according to the method and the device, the abstract syntax tree is generated based on the application source code, the nodes needing to be added with the exception handling codes are searched based on the abstract syntax tree, and the exception handling information is automatically added, so that the corresponding exception handling codes are generated based on each exception handling information, and the code module for automatically adding the exception handling to the application is realized, so that the efficiency for processing the exception information is improved, the instantaneity for obtaining the exception information is improved, and the problem of higher operation complexity of operation and maintenance personnel is solved.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a flow chart illustrating a method for handling exception information according to an embodiment of the present invention;
FIG. 2 is a flow diagram of adding exception handling code according to one embodiment of the present invention;
FIG. 3 is a diagram illustrating a method for handling exception information according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an apparatus of a client for processing exception information according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an apparatus for processing a server of exception information according to an embodiment of the present invention;
FIG. 6 is a block diagram of a system for handling exception information according to an embodiment of the present invention;
FIG. 7 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 8 is a schematic structural diagram of a computer system suitable for implementing a terminal device or a server according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Internet application code typically consists primarily of HTML text, CSS, and JavaScript. The HTML text is used for displaying information and is a framework of an Internet application page; CSS is a cascading style sheet used for presentation of Internet applications and related to the appearance of the Internet applications; JavaScript is used in internet applications to perform business logic interactions, such as a user clicking a button, a user submitting an operation, and the like.
The running exception of the internet application is mainly from JavaScript code execution. Since the JavaScript language is a single thread, if a code in a certain line of the JavaScript is wrong or abnormal, all subsequent JavaScript codes cannot be executed, and thus, the internet application cannot provide stable services. When an internet application is in error (abnormal), an application maintainer often checks error information by checking a browser console, and a JavaScript error information is displayed on the browser console (for example, pressing a keyboard F12 can open the browser console).
The disadvantages of the prior art methods are: 1. the efficiency is low, and maintenance personnel are required to manually open the browser and check related error report or abnormal information on the console. 2. Abnormal information is easy to lose, and when operation and maintenance personnel check the information in a console, the abnormal information may not exist, so that the application operation and maintenance personnel cannot see the related information. 3. The operation is complex, the abnormal JavaScript is probably caused by the incompatible browser versions, at the moment, application operation and maintenance personnel need to install a plurality of low-version browsers to reproduce the abnormal, and the difficulty of reproducing some abnormal is high, so that the operation complexity is improved.
Therefore, the abnormal information generated by the JavaScript code running is reported in real time, which plays an important role in rapidly positioning the operation and maintenance of the Internet application, and meanwhile, the application can be continuously optimized according to the abnormal information, so that the performance and the stability of the Internet application are improved.
In view of this, as shown in fig. 1, an embodiment of the present invention provides a method for processing exception information, where the method may include the following steps:
step S101: acquiring a source code of an application, and generating an abstract syntax tree for the source code; and searching nodes matched with the preset feature identifications from the abstract syntax tree.
Specifically, source code of an application is obtained, wherein the application is an application which needs to monitor whether abnormal information is generated, such as an internet application; further, based on the source code of the application, an Abstract Syntax Tree (AST) is generated for the source code, wherein the AST is used for parsing the source code into a tree-structured representation and describing information of the source code. Specifically, the abstract syntax tree generated for the source code includes: analyzing the source code; and generating an abstract syntax tree according to one or more nodes and node contents included by the analyzed result. Taking JavaScript code as an example of source code, the source code can be analyzed by using an "@ babel/parser" library;
for example: an example of a function contained in the source code is as follows:
function test(){
console.log('FunctionDeclaration');
}
analyzing to obtain a schematic segment of a node in the abstract syntax tree, wherein the part indicated by the body is the content of the node; that is, an abstract syntax tree is generated based on one or more nodes and node contents; the format of the abstract syntax tree may be a JSON structure object, and examples are as follows:
further, searching nodes matched with preset feature identifications from the abstract syntax tree. The preset feature identifier comprises any one of a function declaration identifier, a function expression identifier and an arrow function identifier; in the abstract syntax tree fragment above, the function declaration in "type": function declaration "is identified for the function declaration. Further, the function expression identifier may be "function expression" and the arrow function identifier may be "arthwunction expression", that is, a node matching a preset feature identifier is searched from the abstract syntax tree, that is, any one of the function declaration identifier, the function expression identifier, and the arrow function identifier is searched.
Further, a preset feature identifier is described by taking a function in a JavaScript language as an example, for example: the function in the JavaScript language includes the following representation forms: function declarations (with corresponding function declaration identification), function expressions (with corresponding function expression identification), arrow functions (with corresponding arrow function identification). Wherein:
the function declares: refers to the function defined in JavaScript using function keywords. For example: the following code example is a function declaration:
function functionName(parameters){
code to be executed
}
The function expression: fingers can assign function definitions to variables to form function expressions, as shown in the following example code:
var x=function(a,b){return a*b};
arrow function: the following example code shows: x ═ x × x. The arrow function is simpler than the function declaration or function expression, and the arrow function is suitable for places where anonymous functions are required.
Further, traversing the abstract syntax tree, and searching a node matched with a preset feature identifier, namely any one of a function statement identifier, a function expression identifier and an arrow function identifier, from the abstract syntax tree. It can be understood that the function of the service logic of the execution code is determined by searching the preset feature identifier, so that the captured exception information is added to the function code, and the purpose of processing the exception information for the application is achieved.
Step S102: adding set exception handling information for the searched node in the abstract syntax tree; generating object code based on the abstract syntax tree to which the exception handling information is added, the object code including exception handling code generated based on the exception handling information.
Specifically, according to the description in step S101, a node matching a preset feature identifier is searched for from the abstract syntax tree, after the matched node is found, set exception handling information is added to the found node, and a target code is generated based on the abstract syntax tree to which the exception handling information is added.
For example: the fragments of the source code are as follows:
function test(){
console.log('FunctionDeclaration');}
examples of object code generated based on the example source code described above are as follows:
function test(){
try{console.log('FunctionDeclaration');
}catch(error){report();}
specifically, the exception handling information includes matching captured exception information and exception reporting information; the captured exception information is, for example, abstract syntax tree descriptions corresponding to try statements and catch statements; and the exception reporting information matched with the captured exception information is contained in the catch statement and is used for processing the service logic for reporting the captured exception information. Further, adding corresponding exception handling information for the searched node, including: and acquiring the searched node content of the node, and adding the matched captured abnormal information and the abnormal reporting information based on the node content.
Further, according to the capture exception information, adding capture exception codes on the outer layer of the source codes corresponding to the node contents; for example: the node content ("body") corresponds to the source code:
console.log('FunctionDeclaration');
then, adding capture exception code at the outer layer of the source code corresponding to the node content, as follows:
try{console.log('FunctionDeclaration');}catch(error){report();}
wherein, report () is an example of an exception report code; namely, according to the abnormal reporting information, an abnormal reporting code is added to the source code corresponding to the node content. Specifically, the nodes of the matched function statement, function expression and arrow function are traversed from the abstract syntax tree, and the base-transition library is used to add exception handling information to the above various functions, wherein the exception handling information comprises: configuring the content of the catch statement by using a try statement and a corresponding catch statement, wherein the parameter of the catch statement is 'error', and the real-time reporting operation of abnormal information is realized in the catch statement; configuring the content of the try statement, wherein the content of the try statement consists of a function body and a catch statement.
Regarding the source code based on the application, the process of automatically generating the target code including the exception handling code is consistent with the description of step S201 to step S209, and is not described again here.
Further, the "@ babel/core" library may be used to generate an abstract syntax tree with exception handling information added as target code, for example: JavaScript code was generated using the transformfromadastsync method. Preferably, in order to create a plug-in, exception handling information is automatically added by using the plug-in to generate exception handling code, the plug-in may be used by adopting the following method:
1) and (6) installing the plug-in.
2) The present plug-in is configured in webpack. The configured example code is as follows, and the automatic addition of exception handling code to JavaScript code in the application can be completed through the example code:
rules:[{test:/\.js$/,exclude:/node_modules/,
use [ "plug-in", "babel-loader" ] } ]
That is, a plug-in is created to generate an abstract syntax tree for the source code by using the plug-in, the set exception handling information is added to the node found in the abstract syntax tree, and the corresponding exception handling code is generated based on the exception handling information.
The webpack is a static module packager of the JavaScript application program. The Web pack packs resources (such as style files, JavaScript files, picture files, font files) of all applications, so that the applications can directly import the packed files. By using webpack packaging application, the performance of the application can be improved, and the compatibility of the browser version can be improved. babel is a JavaScript compiler that is mainly used to convert code of ECMAScript 2015+ version into backward compatible JavaScript syntax so that JavaScript code can run in current and old version browsers or other running environments. The plug-in created by the embodiment of the invention can be a babel plug-in, and the exception handling code can be automatically added through the babel plug-in.
Step S103: and responding to the triggering operation of the application, running the target code, and processing the exception information generated by the application through the exception handling code.
Specifically, when the application runs, the object code is run, so that the exception information generated by the application is processed through exception handling code contained in the object code; acquiring exception information corresponding to the node content through one or more capture exception codes (for example, acquiring exception information from an error object of a catch statement); and reporting the abnormal information to a server through the abnormal reporting code. Specifically, the descriptions of the capture exception code and the exception report code are the same as those of step S102, and are not repeated here.
The reported abnormal information may include:
description of exception information: retrieved from the error object of catch (in the message field of error), the root cause of the exception occurrence is directly indicated by this field.
Browser version: it is possible to acquire an exception which is an exception occurring in which version of which browser by using navigator object acquisition.
URL of the page where the exception information is generated: the window of the location of the page of the event can be obtained by using the window of the event, so that the operation and maintenance personnel can reproduce the event based on the corresponding page after viewing the event information.
The time of occurrence of an abnormality: the abnormal occurrence time can be obtained and converted into a year, month, day, hour, minute and second (YYYY-MM-DD HH: MM: ss) format, so that the operation and maintenance personnel can increase the operation and maintenance force in a time period with more abnormal occurrences according to the time information of the abnormal occurrences.
It can be understood that the exception information is reported as much as possible to help the application operation and maintenance personnel to determine the code causing the exception more accurately and efficiently through the exception information.
Further, processing the exception information comprises reporting the exception information;
two methods can be used for reporting the abnormal information:
the first method comprises the following steps: the reporting of the abnormal information can use Ajax request reporting, namely when the abnormal occurs, the abnormal information is obtained through an abnormal processing code, and a reporting request is sent to a server, wherein the reporting request information comprises the description (or the code indicating the abnormal) of the abnormal information, the browser version, the URL of the page generating the abnormal information and the abnormal occurrence time. One drawback of reporting abnormal information by using Ajax is that the problem of cross-domain of a browser and a server needs to be solved, interfaces of the server for receiving the abnormal information report need to be configured to support cross-domain requests, and the operation is complex.
The second method comprises the following steps: preferably, the utilized exception reporting code comprises a picture constructing submodule and a reporting submodule; processing exception information generated by the application through the exception handling code, including: and constructing a reference picture for the abnormal information generated by the application through the picture construction sub-module, binding the abnormal information with the reference picture, and generating a corresponding picture identifier for the reference picture bound with the abnormal information.
Wherein construct the picture submodule, include:
1) the object of creating a reference picture is preferably set to a size of 1 pixel wide and 1 pixel high, i.e. the volume of the file transmitted in the network is reduced as much as possible.
2) And packaging the acquired abnormal information. After abnormal information such as description of abnormal information, browser version, URL (uniform resource locator) for generating abnormal information page, abnormal occurrence time and the like is spliced on a server side abnormal information receiving interface by using an "&" character, for example, "http:// server side abnormal information reports a domain name? The abnormal information is in a format of a & abnormal page url & b & browser information & abnormal occurrence time & d ", wherein a, b, c and d represent abnormal related sub-information respectively. For example: http:// errorreport.com:8088/123. png? The abnormal information is a & abnormal page url & b & browser information & abnormal occurrence time & d.
3) Binding the exception information with the reference picture, for example: setting an address in an attribute of a reference picture to 2), the packaged exception information (in the format of URL) described in the step of (1). Then, a request is sent to the server by using a URL (uniform resource locator) to report the exception information to the server. The reporting submodule splices the server address reporting abnormal information, the picture identifier and the abnormal information into a uniform resource locator, and reports the abnormal information to a server corresponding to the server address by using the uniform resource locator; the abnormal information reporting method solves the problem of cross-domain of the browser, and the server does not need additional related configuration. Therefore, the method is simple to operate, and does not occupy large network bandwidth compared with Ajax requests; while using the reference picture as part of the request, the cross-domain problem is solved (picture requests in web applications are not restricted by browser cross-domain).
Further, after reporting the abnormal information, the server may obtain each abnormal information, and use the sub-information of each abnormal information corresponding to the visual display application, for example: as shown in the schematic diagram of table 1, the sub information of the abnormal information is displayed in a classified manner for the node, and the classification method includes: the abnormal information is divided into the description of the abnormal information (or the code indicating the abnormal), the browser version, the URL of the page generating the abnormal information, the abnormal occurrence time and other categories and is displayed respectively.
Namely, acquiring abnormal information of the node of the application from a server; the exception information comprises a plurality of pieces of sub information; and summarizing the sub-information according to the category aiming at the node, and carrying out visual display on the sub-information so as to display the abnormal information of the applied node in a classified manner.
The invention does not limit the form and content of the abnormal information visualization display page, for example: the abnormal information display page can be added with a search area except for the page display area, and operation and maintenance personnel can search the abnormal information according to the description (or abnormal code indication) dividing the abnormal information into the abnormal information, the browser version, the URL generating the abnormal information page and the abnormal occurrence time, and then check that the application contains the corresponding program code, so that the abnormal problem is repaired, and the efficiency of positioning the abnormal information and the corresponding code is improved.
As shown in fig. 2, an embodiment of the present invention provides a method for adding exception handling code, where the method may include the following steps:
step S201: the method comprises the steps of obtaining a source code of an application, generating an abstract syntax tree for the source code, and traversing nodes in the abstract syntax tree.
Specifically, regarding obtaining the source code of the application, the description of traversing the nodes in the abstract syntax tree generated for the source code is consistent with the description of step S101, and is not repeated here.
Step S202: and whether the node searched from the abstract syntax tree is matched with a preset characteristic identifier or not. If yes, go to step S203; otherwise, the next node is searched continuously.
Specifically, judging whether the node searched from the abstract syntax tree is matched with a preset feature identifier or not; the descriptions of the preset feature identifier and the search node are consistent with the description of step S101, and are not described herein again.
Step S203: and acquiring the searched node content of the node, and judging whether the node content meets the condition of adding abnormal processing information.
Specifically, when the node matching the preset feature identifier is found, the node content of the node is obtained, for example: the content corresponding to "body" in the abstract syntax tree corresponding to the node, i.e. the console.
function test(){console.log('FunctionDeclaration');}
Further, whether the content of the node meets the condition of adding abnormal processing information is judged. Illustratively, as described in step S204, step S205, and step S206, the case is "do not add corresponding exception handling information to the node", otherwise, the step of adding corresponding exception handling information to the searched node is executed.
Step S204: and judging whether the content of the node contains a text matched with the exception handling information.
Specifically, it is determined whether the content of the node includes a text matching the exception handling information, for example: the function already contains the try-catch exception handling code, i.e. the code for which the function already has exception handling information. As shown in the following example code:
if the node content (body object) in the abstract syntax tree obtained by analysis is a try statement, the try statement is a text matched with the exception handling information, and corresponding exception handling information is not added to the node
Namely, the judging whether the content of the node meets the condition of adding the abnormal processing information includes:
judging whether the node content contains a text matched with the abnormal processing information, if so, determining that the node content does not meet the condition of adding the abnormal processing information; otherwise, continuously judging whether the content of the node meets the condition of adding the abnormal processing information.
Step S205: and judging whether the number of lines corresponding to the content of the node is less than a set line number threshold value or not.
Specifically, whether the number of lines corresponding to the content of the node is less than a set line number threshold is judged; for example: when the function body content is less than the set LINE number threshold (LIMIT _ LINE), no corresponding exception handling information is added to the node. When LIMIT _ LINE is set to 0, the corresponding exception handling information is added by default regardless of how many LINEs of code the function contains. It is understood that LIMIT _ LINE is set according to the possible settings, for example: the user sets LIMIT _ LINE to 2, then, in the following code:
function test(){
console.log('FunctionDeclaration');
}
wherein, the function body included in the test function is known as a row, that is:
“console.log('FunctionDeclaration');”
that is, if the number of LINEs of the function body content (i.e., the number of LINEs corresponding to the node content) is 1 and is smaller than the set LINE number threshold LIMIT _ LINE (e.g., set to 2), no corresponding exception handling information is added to the node.
Namely, the judging whether the content of the node meets the condition of adding the abnormal processing information includes:
judging whether the number of lines corresponding to the node content is smaller than a set line number threshold value, if so, determining that the node content does not meet the condition of adding abnormal processing information; otherwise, continuously judging whether the content of the node meets the condition of adding the abnormal processing information.
Step S206: and judging whether a text indicating that abnormal processing is forbidden exists in the annotation text contained in the node content. If yes, go to step S209, otherwise go to step S207.
Specifically, it is determined whether a text indicating that exception handling is prohibited exists in the annotation text included in the node content, where the text indicating that exception handling is prohibited may be added to the annotation text of a certain function, for example: the character string "disable-try-catch" is a text indicating that exception processing is prohibited, and when the comment text of the function includes a "disable-try-catch" character, it indicates that corresponding exception processing information is not to be added to the node
For example: the annotation text may contain the following types: the preceding annotation text (leadingComments), the inline annotation text (inrnercommings) and the trailing annotation text (trailingcommutes) of the function.
The comment text (leadingComments) in front of the function is the content contained in/' symbol as follows:
/*leadingComments disable-try-catch*/
function test(){console.log('FunctionDeclaration');}
the in-line comments (lnnercommunications) correspond to the following// symbol:
function test(){
//innerComments disable-try-catch
console.log('FunctionDeclaration');}
the tail notes (trailing comments) correspond to the following// symbol:
Function test(){
console.log('FunctionDeclaration');
//trailingComments disable-try-catch}
and judging whether a text indicating that exception processing is forbidden exists in the annotation texts contained in the node content or not aiming at the annotation texts of the types, if a 'disable-try-catch' character string is found in the annotation text, not adding corresponding exception processing information for the node.
Namely, judging whether a text indicating that exception processing is prohibited exists in the annotation text contained in the node content, if so, determining that the node content does not meet the condition of adding exception processing information; otherwise, continuously judging whether the content of the node meets the condition of adding the abnormal processing information.
Step S207: and executing the step of adding corresponding exception handling information to the searched node.
Specifically, the description about the addition of the exception handling information is consistent with that of step S102, and is not described herein again.
Step S208: generating object code based on the abstract syntax tree to which the exception handling information is added, the object code including exception handling code generated based on the exception handling information.
Specifically, the description of generating the target code based on the abstract syntax tree to which the exception handling information is added is consistent with the description of step S102, and is not repeated here.
Step S209: corresponding exception handling information is not added for the node.
Specifically, based on the cases described in step S205, step S206, and step S207, it is executed not to add corresponding exception handling information to the node. The sequence of step S205, step S206, and step S207 is only an example, and the execution sequence of step S205, step S206, and step S207 is not limited in the present invention; it can be understood that the flexibility of automatically adding the abnormal information is improved by judging whether the content of the node meets the condition of adding the abnormal processing information.
As shown in fig. 3, an embodiment of the present invention provides a method for processing exception information, which is applied to a server, and the method may include the following steps:
step S301: receiving one or more requests for reporting abnormal information; respectively acquiring corresponding abnormal information from the uniform resource locators corresponding to the requests; and analyzing the abnormal information based on a plurality of preset information categories.
Specifically, one or more requests for reporting abnormal information are received, where the requests are sent by one or more clients, and further, corresponding abnormal information is obtained from uniform resource locators corresponding to the requests, for example: the uniform resource locator corresponding to the request is http:// errorreport. com:8088/123. png? The abnormal information is a, the abnormal page url is b, the browser information is c, and the abnormal occurrence time is d; analyzing the abnormal information based on a plurality of preset information categories; for example: the preset multiple information categories comprise: description of abnormal information, browser version, URL for generating abnormal information page, abnormal occurrence time, etc., and further, analyzing the URL according to a plurality of preset information categories to obtain each sub-information. The description about the abnormality information is identical to that of step S103 and is not described again here.
Step S302: and classifying and storing the sub-information corresponding to each information category included in the analysis result.
Specifically, the sub-information corresponding to each information category is obtained through analysis, and is stored in a classified manner, for example: the abnormal information is stored in the database by using a program of the server, and the MongoDB can be used as the database to store the word information in a classified mode. The invention does not limit the program language of the server and the type of the database used.
Further, in response to receiving an abnormal information display request, sending the sub-information corresponding to each of the classified and stored information categories to a client side, so as to perform classified display at the client side. When the client requests the sub information, the sub information is sent to the client, and the specific description about the classified display of the client is consistent with the description in step S103, which is not described herein again.
As shown in fig. 4, an embodiment of the present invention provides a client 400 for processing exception information, including: a node searching module 401, an added exception handling module 402 and an exception information handling module 403; wherein the content of the first and second substances,
the node searching module 401 is configured to obtain a source code of an application, and generate an abstract syntax tree for the source code; searching a node matched with a preset feature identifier from the abstract syntax tree;
the add exception handling module 402 is configured to add set exception handling information to the found node in the abstract syntax tree; generating object code based on the abstract syntax tree to which the exception handling information is added, the object code including exception handling code generated based on the exception handling information;
the exception information processing module 403 is configured to run the object code in response to a trigger operation of the application, and process exception information generated by the application through the exception handling code.
As shown in fig. 5, an embodiment of the present invention provides a server 500 for processing exception information, including: an abnormal information analyzing module 501 and an abnormal information storing module 502; wherein the content of the first and second substances,
the module 501 for analyzing abnormal information is configured to receive one or more requests for reporting abnormal information; respectively acquiring corresponding abnormal information from the uniform resource locators corresponding to the requests; analyzing the abnormal information based on a plurality of preset information categories;
the storage exception information module 502 is configured to store sub information corresponding to each information category included in the analysis result in a classified manner.
As shown in fig. 6, an embodiment of the present invention provides a system 600 for processing exception information, including: one or more of client 400 handling exception information shown in fig. 4, and server 500 handling exception information shown in fig. 5.
An embodiment of the present invention further provides an electronic device for processing exception information, including: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors are enabled to realize the method provided by any one of the above embodiments.
Embodiments of the present invention further provide a computer-readable medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method provided in any of the above embodiments.
Fig. 7 illustrates an exemplary system architecture 700 to which the method of handling exception information or the apparatus for handling exception information of embodiments of the present invention may be applied.
As shown in fig. 7, the system architecture 700 may include terminal devices 701, 702, 703, a network 704, and a server 705. The network 704 serves to provide a medium for communication links between the terminal devices 701, 702, 703 and the server 705. Network 704 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 701, 702, 703 to interact with a server 705 over a network 704, to receive or send messages or the like. Various client applications, such as an e-mall client application, a web browser application, a search-type application, an instant messaging tool, a mailbox client, and the like, may be installed on the terminal devices 701, 702, and 703.
The terminal devices 701, 702, 703 may be various electronic devices having display screens and supporting various client applications, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 705 may be a server providing various services, such as a background management server providing support for client applications used by users with the terminal devices 701, 702, 703. The background management server can process the received request for processing the abnormal information and feed back the classified abnormal information to the terminal equipment.
It should be noted that the method for processing the exception information provided in the embodiment of the present invention is generally executed by the terminal devices 701, 702, and 703, and accordingly, the client for processing the exception information is generally disposed in the terminal devices 701, 702, and 703, and the server for processing the exception information is generally disposed in the server 705.
It should be understood that the number of terminal devices, networks, and servers in fig. 7 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 8, shown is a block diagram of a computer system 800 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 8 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 8, the computer system 800 includes a Central Processing Unit (CPU)801 that can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)802 or a program loaded from a storage section 808 into a Random Access Memory (RAM) 803. In the RAM 803, various programs and data necessary for the operation of the system 800 are also stored. The CPU 801, ROM 802, and RAM 803 are connected to each other via a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
The following components are connected to the I/O interface 805: an input portion 806 including a keyboard, a mouse, and the like; an output section 807 including a signal such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 808 including a hard disk and the like; and a communication section 809 including a network interface card such as a LAN card, a modem, or the like. The communication section 809 performs communication processing via a network such as the internet. A drive 810 is also connected to the I/O interface 805 as necessary. A removable medium 811 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 810 as necessary, so that a computer program read out therefrom is mounted on the storage section 808 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 809 and/or installed from the removable medium 811. The computer program executes the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 801.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules and/or units described in the embodiments of the present invention may be implemented by software, and may also be implemented by hardware. The described modules and/or units may also be provided in a processor, and may be described as: a processor includes a lookup node module, an add exception handling module, and a handle exception information module. The names of these modules do not in some cases constitute a limitation on the modules themselves, and for example, the module for handling exception information may also be described as a "module for handling exception information according to an automatically generated exception handling code".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: acquiring a source code of an application, and generating an abstract syntax tree for the source code; searching a node matched with a preset feature identifier from the abstract syntax tree; adding set exception handling information for the searched node in the abstract syntax tree; generating object code based on the abstract syntax tree to which the exception handling information is added, the object code including exception handling code generated based on the exception handling information; and responding to the triggering operation of the application, running the target code, and processing the exception information generated by the application through the exception handling code.
Receiving one or more requests for reporting abnormal information; respectively acquiring corresponding abnormal information from the uniform resource locators corresponding to the requests; analyzing the abnormal information based on a plurality of preset information categories; and classifying and storing the sub-information corresponding to each information category included in the analysis result.
Therefore, the embodiment of the invention can generate the abstract syntax tree based on the applied source code, search the node to be processed from the abstract syntax tree, generate the new abstract syntax tree after adding the exception handling information to the node, and generate the applied target code based on the new abstract syntax tree so as to obtain the applied exception information through the newly added exception handling code; the efficiency of processing the abnormal information is improved by automatically adding the abnormal processing code, the instantaneity of obtaining the abnormal information is improved, and the problem of higher operation complexity of operation and maintenance personnel is solved.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (20)

1. A method of handling exception information, comprising:
acquiring a source code of an application, and generating an abstract syntax tree for the source code;
searching a node matched with a preset feature identifier from the abstract syntax tree;
adding set exception handling information for the searched node in the abstract syntax tree;
generating object code based on the abstract syntax tree to which the exception handling information is added, the object code including exception handling code generated based on the exception handling information;
and responding to the triggering operation of the application, running the target code, and processing the exception information generated by the application through the exception handling code.
2. The method of claim 1,
the preset feature identifier comprises any one of a function declaration identifier, a function expression identifier and an arrow function identifier.
3. The method of claim 1, wherein the generated abstract syntax tree for the source code comprises:
analyzing the source code;
and generating an abstract syntax tree according to one or more nodes and node contents included by the analyzed result.
4. The method of claim 1, further comprising:
and acquiring the searched node content of the node, judging whether the node content meets the condition of adding the abnormal processing information, if so, executing the step of adding the corresponding abnormal processing information for the searched node, otherwise, not adding the corresponding abnormal processing information for the node.
5. The method of claim 4, wherein determining whether the node content satisfies a condition for adding exception handling information comprises:
judging whether the node content contains a text matched with the abnormal processing information, if so, determining that the node content does not meet the condition of adding the abnormal processing information; otherwise, continuously judging whether the content of the node meets the condition of adding the abnormal processing information.
6. The method of claim 4, wherein determining whether the node content satisfies a condition for adding exception handling information comprises:
judging whether the number of lines corresponding to the node content is smaller than a set line number threshold value, if so, determining that the node content does not meet the condition of adding abnormal processing information; otherwise, continuously judging whether the content of the node meets the condition of adding the abnormal processing information.
7. The method of claim 4, wherein determining whether the node content satisfies a condition for adding exception handling information comprises:
judging whether a text indicating that exception processing is forbidden exists in the annotation text contained in the node content, if so, determining that the node content does not meet the condition of adding exception processing information; otherwise, continuously judging whether the content of the node meets the condition of adding the abnormal processing information.
8. The method of claim 1,
the exception handling information comprises matched captured exception information and exception reporting information;
adding corresponding exception handling information for the searched node, including:
and acquiring the searched node content of the node, and adding the matched captured abnormal information and the abnormal reporting information based on the node content.
9. The method of claim 8, wherein generating object code comprises:
according to the capture abnormal information, adding capture abnormal codes on the outer layer of the source codes corresponding to the node contents;
and adding an abnormal reporting code for the source code corresponding to the node content according to the abnormal reporting information.
10. The method of claim 9, wherein processing exception information generated by the application by the exception handling code comprises:
capturing exception information corresponding to the node content through one or more capture exception codes;
and reporting the abnormal information to a server through the abnormal reporting code.
11. The method of claim 9, further comprising:
the exception reporting code comprises a picture constructing submodule and a reporting submodule;
processing exception information generated by the application through the exception handling code, including:
constructing a reference picture for the abnormal information generated by the application through the picture construction sub-module, binding the abnormal information with the reference picture, and generating a corresponding picture identifier for the reference picture bound with the abnormal information;
and splicing the server address reporting the abnormal information, the picture identifier and the abnormal information into a uniform resource locator through the reporting submodule, and reporting the abnormal information to a server corresponding to the server address by using the uniform resource locator.
12. The method of claim 1, further comprising:
creating a plug-in to generate an abstract syntax tree for the source code by using the plug-in, adding the set exception handling information to the node found in the abstract syntax tree, and generating the corresponding exception handling code based on the exception handling information.
13. The method of any of claims 1-12, further comprising:
acquiring abnormal information of the applied node from a server; the exception information comprises a plurality of pieces of sub information;
and summarizing the sub-information according to the category aiming at the node, and carrying out visual display on the sub-information so as to display the abnormal information of the applied node in a classified manner.
14. A method of handling exception information, comprising:
receiving one or more requests for reporting abnormal information;
respectively acquiring corresponding abnormal information from the uniform resource locators corresponding to the requests;
analyzing the abnormal information based on a plurality of preset information categories;
and classifying and storing the sub-information corresponding to each information category included in the analysis result.
15. The method of claim 13, further comprising:
and responding to the received abnormal information display request, and sending the sub-information corresponding to each classified and stored information category to a client side so as to perform classified display on the client side.
16. A client for processing exception information, comprising: the system comprises a node searching module, an addition exception handling module and an exception information handling module; wherein the content of the first and second substances,
the node searching module is used for acquiring a source code of an application and generating an abstract syntax tree for the source code; searching a node matched with a preset feature identifier from the abstract syntax tree;
the addition exception handling module is used for adding set exception handling information for the searched node in the abstract syntax tree; generating object code based on the abstract syntax tree to which the exception handling information is added, the object code including exception handling code generated based on the exception handling information;
and the exception information processing module is used for responding to the triggering operation of the application, running the target code and processing exception information generated by the application through the exception processing code.
17. A server for processing exception information, comprising: the abnormal information analyzing module and the abnormal information storing module; wherein the content of the first and second substances,
the analysis abnormal information module is used for receiving one or more requests for reporting abnormal information; respectively acquiring corresponding abnormal information from the uniform resource locators corresponding to the requests; analyzing the abnormal information based on a plurality of preset information categories;
and the abnormal information storage module is used for classifying and storing the sub-information corresponding to each information category included in the analysis result.
18. A system for handling exception information, comprising one or more clients for handling exception information as claimed in claim 16 and a server for handling exception information as claimed in claim 17.
19. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-15.
20. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-15.
CN202110332753.2A 2021-03-29 2021-03-29 Method, device and system for processing abnormal information Pending CN112948726A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110332753.2A CN112948726A (en) 2021-03-29 2021-03-29 Method, device and system for processing abnormal information

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110332753.2A CN112948726A (en) 2021-03-29 2021-03-29 Method, device and system for processing abnormal information

Publications (1)

Publication Number Publication Date
CN112948726A true CN112948726A (en) 2021-06-11

Family

ID=76227776

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110332753.2A Pending CN112948726A (en) 2021-03-29 2021-03-29 Method, device and system for processing abnormal information

Country Status (1)

Country Link
CN (1) CN112948726A (en)

Similar Documents

Publication Publication Date Title
US20130268561A1 (en) Systems and methods for compressing and extracting information from marketplace taxonomies
CN107832045B (en) Method and apparatus for cross programming language interface conversion
CN107491382B (en) Log output method and device
WO2021023149A1 (en) Method and apparatus for dynamically returning message
CN111190888A (en) Method and device for managing graph database cluster
US20210334149A1 (en) Api adapter creation device, api adapter creation method, and api adapter creation program
US10983789B2 (en) Systems and methods for automating and monitoring software development operations
CN112948726A (en) Method, device and system for processing abnormal information
CN108959294B (en) Method and device for accessing search engine
CN110543297A (en) method and apparatus for generating source code
CN109359194B (en) Method and apparatus for predicting information categories
CN113535153A (en) Method, device, equipment and medium for encoding custom label
CN111178014A (en) Method and device for processing business process
CN113326188A (en) Browser testing method and device
CN111831536A (en) Automatic testing method and device
CN112947941A (en) Method and device for adding exception handling code
CN113268245A (en) Code analysis method, device and storage medium
CN113448827A (en) Test data processing method and device
CN113220381A (en) Click data display method and device
CN113031946A (en) Method and device for rendering page component
CN113220558A (en) Monitoring script generation method and device, and monitoring method and device
CN111427899A (en) Method, device, equipment and computer readable medium for storing file
CN111367517A (en) Information generation method and device
CN113138974A (en) Database compliance detection method and device
CN112579427A (en) Method and device for generating virtualization test code

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination