Changeset 90110 in webkit


Ignore:
Timestamp:
Jun 30, 2011, 6:22:29 AM (14 years ago)
Author:
loislo@chromium.org
Message:

2011-06-30 Ilya Tikhonovsky <loislo@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: Protocol: error object needs some improvement.
https://bugs.webkit.org/show_bug.cgi?id=63707

Current implementation is not useful in the code.
We need to have toString implementation with nice formatting
I'd like to use error.message property as the main place for the error's text.

  • inspector/elements/set-attribute.html:
  • inspector/report-protocol-errors-expected.txt:
  • inspector/report-protocol-errors.html:

2011-06-30 Ilya Tikhonovsky <loislo@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: Protocol: error object needs some improvement.
https://bugs.webkit.org/show_bug.cgi?id=63707

Current implementation is not useful in the code.
We need to have toString implementation with nice formatting
I'd like to use error.message property as the main place for the error's text.

  • inspector/CodeGeneratorInspector.pm:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r90104 r90110  
     12011-06-30  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: Protocol: error object needs some improvement.
     6        https://bugs.webkit.org/show_bug.cgi?id=63707
     7
     8        Current implementation is not useful in the code.
     9        We need to have toString implementation with nice formatting
     10        I'd like to use error.message property as the main place for the error's text.
     11
     12        * inspector/elements/set-attribute.html:
     13        * inspector/report-protocol-errors-expected.txt:
     14        * inspector/report-protocol-errors.html:
     15
    1162011-06-30  Philippe Normand  <pnormand@igalia.com>
    217
  • trunk/LayoutTests/inspector/elements/set-attribute.html

    r90013 r90110  
    103103            function callback(error)
    104104            {
    105                 InspectorTest.addResult("Error: " + error.data[0]);
     105                InspectorTest.addResult("Error: " + error.getMessage());
    106106                WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
    107107                InspectorTest.addResult("=== Set malformed attribute as text ===");
  • trunk/LayoutTests/inspector/report-protocol-errors-expected.txt

    r88535 r90110  
    44    error : {
    55        code : -32700
    6         message : "Parse error."
    7         data : [
    8             "Message should be in JSON format."
    9         ]
     6        message : "Message should be in JSON format"
    107    }
    118    id : null
    129}
     10error.code: -32700
     11error.getMessage(): Message should be in JSON format
     12error.toString(): Parse error(-32700): Message should be in JSON format.
     13-------------------------------------------------------
    1314{
    1415    error : {
    1516        code : -32600
    16         message : "Invalid Request."
    17         data : [
    18             "Invalid message format. 'id' property was not found in the request."
    19         ]
     17        message : "'id' property was not found"
    2018    }
    2119    id : null
    2220}
     21error.code: -32600
     22error.getMessage(): 'id' property was not found
     23error.toString(): Invalid Request(-32600): 'id' property was not found.
     24-------------------------------------------------------
    2325{
    2426    error : {
    2527        code : -32600
    26         message : "Invalid Request."
    27         data : [
    28             "Invalid message format. The type of 'id' property should be number."
    29         ]
     28        message : "The type of 'id' property should be number"
    3029    }
    3130    id : null
    3231}
     32error.code: -32600
     33error.getMessage(): The type of 'id' property should be number
     34error.toString(): Invalid Request(-32600): The type of 'id' property should be number.
     35-------------------------------------------------------
    3336{
    3437    error : {
    3538        code : -32600
    36         message : "Invalid Request."
    37         data : [
    38             "Invalid message format. The type of 'method' property should be string."
    39         ]
     39        message : "The type of 'method' property should be string"
    4040    }
    4141    id : 1
    4242}
    43 {
    44     error : {
    45         code : -32601
    46         message : "Method not found."
    47         data : [
    48             "Invalid method name was received. 'resourceContent' wasn't found."
    49         ]
     43error.code: -32600
     44error.getMessage(): The type of 'method' property should be string
     45error.toString(): Invalid Request(-32600): The type of 'method' property should be string.
     46-------------------------------------------------------
     47{
     48    error : {
     49        code : -32601
     50        message : "'resourceContent' wasn't found"
    5051    }
    5152    id : 2
    5253}
    53 {
    54     error : {
    55         code : -32601
    56         message : "Method not found."
    57         data : [
    58             "Invalid method name was received. 'DOM.test' wasn't found."
    59         ]
     54error.code: -32601
     55error.getMessage(): 'resourceContent' wasn't found
     56error.toString(): Method not found(-32601): 'resourceContent' wasn't found.
     57-------------------------------------------------------
     58{
     59    error : {
     60        code : -32601
     61        message : "'DOM.test' wasn't found"
    6062    }
    6163    id : 3
    6264}
    63 {
    64     error : {
    65         code : -32602
    66         message : "Invalid params."
     65error.code: -32601
     66error.getMessage(): 'DOM.test' wasn't found
     67error.toString(): Method not found(-32601): 'DOM.test' wasn't found.
     68-------------------------------------------------------
     69{
     70    error : {
     71        code : -32602
     72        message : "Some arguments of method 'Page.getResourceContent' can't be processed"
    6773        data : [
    6874            "'params' property with type 'object' was not found."
     
    7177    id : 4
    7278}
    73 {
    74     error : {
    75         code : -32602
    76         message : "Invalid params."
     79error.code: -32602
     80error.getMessage(): Some arguments of method 'Page.getResourceContent' can't be processed
     81error.toString(): Invalid params(-32602): Some arguments of method 'Page.getResourceContent' can't be processed. 'params' property with type 'object' was not found.
     82-------------------------------------------------------
     83{
     84    error : {
     85        code : -32602
     86        message : "Some arguments of method 'Page.getResourceContent' can't be processed"
    7787        data : [
    7888            "'params' property with type 'object' was not found."
     
    8191    id : 5
    8292}
    83 {
    84     error : {
    85         code : -32602
    86         message : "Invalid params."
     93error.code: -32602
     94error.getMessage(): Some arguments of method 'Page.getResourceContent' can't be processed
     95error.toString(): Invalid params(-32602): Some arguments of method 'Page.getResourceContent' can't be processed. 'params' property with type 'object' was not found.
     96-------------------------------------------------------
     97{
     98    error : {
     99        code : -32602
     100        message : "Some arguments of method 'Page.getResourceContent' can't be processed"
    87101        data : [
    88102            "Parameter 'frameId' with type 'String' was not found."
     
    92106    id : 6
    93107}
    94 {
    95     error : {
    96         code : -32602
    97         message : "Invalid params."
     108error.code: -32602
     109error.getMessage(): Some arguments of method 'Page.getResourceContent' can't be processed
     110error.toString(): Invalid params(-32602): Some arguments of method 'Page.getResourceContent' can't be processed. Parameter 'frameId' with type 'String' was not found. Parameter 'url' with type 'String' was not found.
     111-------------------------------------------------------
     112{
     113    error : {
     114        code : -32602
     115        message : "Some arguments of method 'Page.getResourceContent' can't be processed"
    98116        data : [
    99117            "Parameter 'url' with type 'String' was not found."
     
    102120    id : 7
    103121}
    104 {
    105     error : {
    106         code : -32601
    107         message : "Method not found."
    108         data : [
    109             "Invalid method name was received. 'Page.test' wasn't found."
    110         ]
     122error.code: -32602
     123error.getMessage(): Some arguments of method 'Page.getResourceContent' can't be processed
     124error.toString(): Invalid params(-32602): Some arguments of method 'Page.getResourceContent' can't be processed. Parameter 'url' with type 'String' was not found.
     125-------------------------------------------------------
     126{
     127    error : {
     128        code : -32601
     129        message : "'Page.test' wasn't found"
    111130    }
    112131    id : 8
    113132}
    114 {
    115     error : {
    116         code : -32601
    117         message : "Method not found."
    118         data : [
    119             "Invalid method name was received. 'Page.test' wasn't found."
    120         ]
     133error.code: -32601
     134error.getMessage(): 'Page.test' wasn't found
     135error.toString(): Method not found(-32601): 'Page.test' wasn't found.
     136-------------------------------------------------------
     137{
     138    error : {
     139        code : -32601
     140        message : "'Page.test' wasn't found"
    121141    }
    122142    id : 9
    123143}
    124 {
    125     error : {
    126         code : -32601
    127         message : "Method not found."
    128         data : [
    129             "Invalid method name was received. 'Page.test' wasn't found."
    130         ]
     144error.code: -32601
     145error.getMessage(): 'Page.test' wasn't found
     146error.toString(): Method not found(-32601): 'Page.test' wasn't found.
     147-------------------------------------------------------
     148{
     149    error : {
     150        code : -32601
     151        message : "'Page.test' wasn't found"
    131152    }
    132153    id : 10
    133154}
    134 {
    135     error : {
    136         code : -32601
    137         message : "Method not found."
    138         data : [
    139             "Invalid method name was received. 'Page.test' wasn't found."
    140         ]
     155error.code: -32601
     156error.getMessage(): 'Page.test' wasn't found
     157error.toString(): Method not found(-32601): 'Page.test' wasn't found.
     158-------------------------------------------------------
     159{
     160    error : {
     161        code : -32601
     162        message : "'Page.test' wasn't found"
    141163    }
    142164    id : 11
    143165}
    144 {
    145     error : {
    146         code : -32601
    147         message : "Method not found."
    148         data : [
    149             "Invalid method name was received. 'Page.test' wasn't found."
    150         ]
     166error.code: -32601
     167error.getMessage(): 'Page.test' wasn't found
     168error.toString(): Method not found(-32601): 'Page.test' wasn't found.
     169-------------------------------------------------------
     170{
     171    error : {
     172        code : -32601
     173        message : "'Page.test' wasn't found"
    151174    }
    152175    id : 12
    153176}
    154 {
    155     error : {
    156         code : -32601
    157         message : "Method not found."
    158         data : [
    159             "Invalid method name was received. 'Page.test' wasn't found."
    160         ]
     177error.code: -32601
     178error.getMessage(): 'Page.test' wasn't found
     179error.toString(): Method not found(-32601): 'Page.test' wasn't found.
     180-------------------------------------------------------
     181{
     182    error : {
     183        code : -32601
     184        message : "'Page.test' wasn't found"
    161185    }
    162186    id : 13
    163187}
    164 {
    165     error : {
    166         code : -32601
    167         message : "Method not found."
    168         data : [
    169             "Invalid method name was received. 'Page.test' wasn't found."
    170         ]
     188error.code: -32601
     189error.getMessage(): 'Page.test' wasn't found
     190error.toString(): Method not found(-32601): 'Page.test' wasn't found.
     191-------------------------------------------------------
     192{
     193    error : {
     194        code : -32601
     195        message : "'Page.test' wasn't found"
    171196    }
    172197    id : 14
    173198}
    174 {
    175     error : {
    176         code : -32601
    177         message : "Method not found."
    178         data : [
    179             "Invalid method name was received. 'Page.test' wasn't found."
    180         ]
     199error.code: -32601
     200error.getMessage(): 'Page.test' wasn't found
     201error.toString(): Method not found(-32601): 'Page.test' wasn't found.
     202-------------------------------------------------------
     203{
     204    error : {
     205        code : -32601
     206        message : "'Page.test' wasn't found"
    181207    }
    182208    id : 15
    183209}
    184 {
    185     error : {
    186         code : -32601
    187         message : "Method not found."
    188         data : [
    189             "Invalid method name was received. 'Page.test' wasn't found."
    190         ]
     210error.code: -32601
     211error.getMessage(): 'Page.test' wasn't found
     212error.toString(): Method not found(-32601): 'Page.test' wasn't found.
     213-------------------------------------------------------
     214{
     215    error : {
     216        code : -32601
     217        message : "'Page.test' wasn't found"
    191218    }
    192219    id : 16
    193220}
     221error.code: -32601
     222error.getMessage(): 'Page.test' wasn't found
     223error.toString(): Method not found(-32601): 'Page.test' wasn't found.
     224-------------------------------------------------------
    194225
  • trunk/LayoutTests/inspector/report-protocol-errors.html

    r88535 r90110  
    3131    InspectorBackend.reportProtocolError = function(message)
    3232    {
    33         if (numberOfReports < messages.length)
     33
     34        if (numberOfReports < messages.length) {
    3435            InspectorTest.addObject(message);
     36            InspectorTest.addResult("error.code: " + message.error.code);
     37            InspectorTest.addResult("error.getMessage(): " + message.error.getMessage());
     38            InspectorTest.addResult("error.toString(): " + message.error);
     39            InspectorTest.addResult("-------------------------------------------------------");
     40        }
    3541
    3642        if (++numberOfReports === messages.length)
  • trunk/Source/WebCore/ChangeLog

    r90107 r90110  
     12011-06-30  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: Protocol: error object needs some improvement.
     6        https://bugs.webkit.org/show_bug.cgi?id=63707
     7
     8        Current implementation is not useful in the code.
     9        We need to have toString implementation with nice formatting
     10        I'd like to use error.message property as the main place for the error's text.
     11
     12        * inspector/CodeGeneratorInspector.pm:
     13
    1142011-06-30  Mikhail Naganov  <mnaganov@chromium.org>
    215
  • trunk/Source/WebCore/inspector/CodeGeneratorInspector.pm

    r87146 r90110  
    499499        push(@function, "    }");
    500500    }
    501     push(@function, "    sendResponse(callId, result, protocolErrors, error);");
     501    push(@function, "    sendResponse(callId, result, String::format(s_argumentsErrorTemplate, \"$fullQualifiedFunctionNameDot\"), protocolErrors, error);");
    502502    push(@function, "}");
    503503    push(@function, "");
     
    509509    my $sendResponse = << "EOF";
    510510
    511 void ${backendClassName}::sendResponse(long callId, PassRefPtr<InspectorObject> result, PassRefPtr<InspectorArray> protocolErrors, ErrorString invocationError)
     511void ${backendClassName}::sendResponse(long callId, PassRefPtr<InspectorObject> result, const String& errorMessage, PassRefPtr<InspectorArray> protocolErrors, ErrorString invocationError)
    512512{
    513513    if (protocolErrors->length()) {
    514         reportProtocolError(&callId, InvalidParams, protocolErrors);
     514        reportProtocolError(&callId, InvalidParams, errorMessage, protocolErrors);
    515515        return;
    516516    }
     
    534534    my $reportProtocolError = << "EOF";
    535535
    536 void ${backendClassName}::reportProtocolError(const long* const callId, CommonErrorCode code, const String& customText) const
    537 {
    538     RefPtr<InspectorArray> data = InspectorArray::create();
    539     data->pushString(customText);
    540     reportProtocolError(callId, code, data.release());
    541 }
    542 
    543 void ${backendClassName}::reportProtocolError(const long* const callId, CommonErrorCode code, PassRefPtr<InspectorArray> data) const
    544 {
    545     DEFINE_STATIC_LOCAL(Vector<String>,s_commonErrors,);
     536void ${backendClassName}::reportProtocolError(const long* const callId, CommonErrorCode code, const String& errorMessage) const
     537{
     538    reportProtocolError(callId, code, errorMessage, 0);
     539}
     540
     541void ${backendClassName}::reportProtocolError(const long* const callId, CommonErrorCode code, const String& errorMessage, PassRefPtr<InspectorArray> data) const
     542{
     543    DEFINE_STATIC_LOCAL(Vector<int>,s_commonErrors,);
    546544    if (!s_commonErrors.size()) {
    547         s_commonErrors.insert(ParseError, "{\\\"code\\\":-32700,\\\"message\\\":\\\"Parse error.\\\"}");
    548         s_commonErrors.insert(InvalidRequest, "{\\\"code\\\":-32600,\\\"message\\\":\\\"Invalid Request.\\\"}");
    549         s_commonErrors.insert(MethodNotFound, "{\\\"code\\\":-32601,\\\"message\\\":\\\"Method not found.\\\"}");
    550         s_commonErrors.insert(InvalidParams, "{\\\"code\\\":-32602,\\\"message\\\":\\\"Invalid params.\\\"}");
    551         s_commonErrors.insert(InternalError, "{\\\"code\\\":-32603,\\\"message\\\":\\\"Internal error.\\\"}");
    552         s_commonErrors.insert(ServerError, "{\\\"code\\\":-32000,\\\"message\\\":\\\"Server error.\\\"}");
     545        s_commonErrors.insert(ParseError, -32700);
     546        s_commonErrors.insert(InvalidRequest, -32600);
     547        s_commonErrors.insert(MethodNotFound, -32601);
     548        s_commonErrors.insert(InvalidParams, -32602);
     549        s_commonErrors.insert(InternalError, -32603);
     550        s_commonErrors.insert(ServerError, -32000);
    553551    }
    554552    ASSERT(code >=0);
    555553    ASSERT((unsigned)code < s_commonErrors.size());
    556554    ASSERT(s_commonErrors[code]);
    557     ASSERT(InspectorObject::parseJSON(s_commonErrors[code]));
    558     RefPtr<InspectorObject> error = InspectorObject::parseJSON(s_commonErrors[code])->asObject();
     555    RefPtr<InspectorObject> error = InspectorObject::create();
     556    error->setNumber("code", s_commonErrors[code]);
     557    error->setString("message", errorMessage);
    559558    ASSERT(error);
    560     error->setArray("data", data);
     559    if (data)
     560        error->setArray("data", data);
    561561    RefPtr<InspectorObject> message = InspectorObject::create();
    562562    message->setObject("error", error);
     
    634634    RefPtr<InspectorValue> parsedMessage = InspectorValue::parseJSON(message);
    635635    if (!parsedMessage) {
    636         reportProtocolError(0, ParseError, "Message should be in JSON format.");
     636        reportProtocolError(0, ParseError, "Message should be in JSON format");
    637637        return;
    638638    }
     
    640640    RefPtr<InspectorObject> messageObject = parsedMessage->asObject();
    641641    if (!messageObject) {
    642         reportProtocolError(0, InvalidRequest, "Invalid message format. The message should be a JSONified object.");
     642        reportProtocolError(0, InvalidRequest, "Message should be a JSONified object");
    643643        return;
    644644    }
     
    646646    RefPtr<InspectorValue> callIdValue = messageObject->get("id");
    647647    if (!callIdValue) {
    648         reportProtocolError(0, InvalidRequest, "Invalid message format. 'id' property was not found in the request.");
     648        reportProtocolError(0, InvalidRequest, "'id' property was not found");
    649649        return;
    650650    }
    651651
    652652    if (!callIdValue->asNumber(&callId)) {
    653         reportProtocolError(0, InvalidRequest, "Invalid message format. The type of 'id' property should be number.");
     653        reportProtocolError(0, InvalidRequest, "The type of 'id' property should be number");
    654654        return;
    655655    }
     
    657657    RefPtr<InspectorValue> methodValue = messageObject->get("method");
    658658    if (!methodValue) {
    659         reportProtocolError(&callId, InvalidRequest, "Invalid message format. 'method' property wasn't found.");
     659        reportProtocolError(&callId, InvalidRequest, "'method' property wasn't found");
    660660        return;
    661661    }
     
    663663    String method;
    664664    if (!methodValue->asString(&method)) {
    665         reportProtocolError(&callId, InvalidRequest, "Invalid message format. The type of 'method' property should be string.");
     665        reportProtocolError(&callId, InvalidRequest, "The type of 'method' property should be string");
    666666        return;
    667667    }
     
    669669    HashMap<String, CallHandler>::iterator it = dispatchMap.find(method);
    670670    if (it == dispatchMap.end()) {
    671         reportProtocolError(&callId, MethodNotFound, "Invalid method name was received. '" + method + "' wasn't found.");
     671        reportProtocolError(&callId, MethodNotFound, "'" + method + "' wasn't found");
    672672        return;
    673673    }
     
    841841
    842842        if ("id" in messageObject) { // just a response for some request
    843             if (messageObject.error && messageObject.error.code !== -32000)
    844                 this.reportProtocolError(messageObject);
     843            if (messageObject.error) {
     844                messageObject.error.__proto__ = {
     845                    getDescription: function()
     846                    {
     847                        switch(this.code) {
     848                            case -32700: return "Parse error";
     849                            case -32600: return "Invalid Request";
     850                            case -32601: return "Method not found";
     851                            case -32602: return "Invalid params";
     852                            case -32603: return "Internal error";;
     853                            case -32000: return "Server error";
     854                        }
     855                    },
     856
     857                    toString: function()
     858                    {
     859                        var description ="Unknown error code";
     860                        return this.getDescription() + "(" + this.code + "): " + this.message + "." + (this.data ? " " + this.data.join(" ") : "");
     861                    },
     862
     863                    getMessage: function()
     864                    {
     865                        return this.message;
     866                    }
     867                }
     868
     869                if (messageObject.error.code !== -32000)
     870                    this.reportProtocolError(messageObject);
     871            }
    845872
    846873            var arguments = [];
     
    10521079    push(@backendHead, "    };");
    10531080    push(@backendHead, "");
    1054     push(@backendHead, "    void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorText) const;");
    1055     push(@backendHead, "    void reportProtocolError(const long* const callId, CommonErrorCode, PassRefPtr<InspectorArray> data) const;");
     1081    push(@backendHead, "    void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage) const;");
     1082    push(@backendHead, "    void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage, PassRefPtr<InspectorArray> data) const;");
    10561083    push(@backendHead, "    void dispatch(const String& message);");
    10571084    push(@backendHead, "    static bool getCommandName(const String& message, String* result);");
     
    10821109    unshift(@backendConstantDefinitions, "const char* InspectorBackendDispatcher::commandNames[] = {");
    10831110    push(@backendConstantDefinitions, "};");
     1111    push(@backendConstantDefinitions, "");
     1112    push(@backendConstantDefinitions, "static const char* s_argumentsErrorTemplate = \"Some arguments of method '%s' can't be processed\";");
    10841113
    10851114    # Make dispatcher methods private on the backend.
     
    10961125    }
    10971126
    1098     push(@backendConstantDeclarations, "    void sendResponse(long callId, PassRefPtr<InspectorObject> result, PassRefPtr<InspectorArray> protocolErrors, ErrorString invocationError);");
     1127    push(@backendConstantDeclarations, "    void sendResponse(long callId, PassRefPtr<InspectorObject> result, const String& errorMessage, PassRefPtr<InspectorArray> protocolErrors, ErrorString invocationError);");
    10991128
    11001129    generateBackendAgentFieldsAndConstructor();
Note: See TracChangeset for help on using the changeset viewer.