Autorest: Cancelled due to exception : Plugin imodeler1 reported failure

Created on 1 Dec 2017  路  8Comments  路  Source: Azure/autorest

Can't generate csharp code after update to 2.0.4215:

PS C:\src\autorest> autorest --input-file=http://localhost:31000/swagger/v1/swagger.json --csharp --output-folder=RestClient --namespace=DistributedTest.Core.RestClient --preview
AutoRest code generation utility [version: 2.0.4215]
(C) 2017 Microsoft Corporation.
https://aka.ms/autorest
No configuration found at 'file:///C:/src/autorest/'.
   Installing AutoRest extension '@microsoft.azure/autorest.csharp' (~2.2.45)
   Installing AutoRest extension '@microsoft.azure/autorest.modeler' (2.3.38)
FATAL: System.NullReferenceException: Object reference not set to an instance of an object.
   at AutoRest.Modeler.ObjectBuilder.BuildServiceType(String serviceTypeName, Boolean required) in C:\Users\ci\AppData\Local\Temp\PUBLISH8kiit\38_20171116T010915\autorest.modeler\src\ObjectBuilder.cs:line 49
   at AutoRest.Modeler.ParameterBuilder.ParentBuildServiceType(String serviceTypeName, Boolean required) in C:\Users\ci\AppData\Local\Temp\PUBLISH8kiit\38_20171116T010915\autorest.modeler\src\ParameterBuilder.cs:line
 97
   at AutoRest.Modeler.ParameterBuilder.BuildServiceType(String serviceTypeName, Boolean required) in C:\Users\ci\AppData\Local\Temp\PUBLISH8kiit\38_20171116T010915\autorest.modeler\src\ParameterBuilder.cs:line 94
   at AutoRest.Modeler.ParameterBuilder.Build() in C:\Users\ci\AppData\Local\Temp\PUBLISH8kiit\38_20171116T010915\autorest.modeler\src\ParameterBuilder.cs:line 54
   at AutoRest.Modeler.OperationBuilder.BuildMethodParameters(Method method) in C:\Users\ci\AppData\Local\Temp\PUBLISH8kiit\38_20171116T010915\autorest.modeler\src\OperationBuilder.cs:line 276
   at AutoRest.Modeler.OperationBuilder.BuildMethod(HttpMethod httpMethod, String url, String methodName, String methodGroup) in C:\Users\ci\AppData\Local\Temp\PUBLISH8kiit\38_20171116T010915\autorest.modeler\src\Ope
rationBuilder.cs:line 86
   at AutoRest.Modeler.SwaggerModeler.BuildMethod(HttpMethod httpMethod, String url, String name, Operation operation) in C:\Users\ci\AppData\Local\Temp\PUBLISH8kiit\38_20171116T010915\autorest.modeler\src\SwaggerMod
eler.cs:line 327
   at AutoRest.Modeler.SwaggerModeler.Build(ServiceDefinition serviceDefinition) in C:\Users\ci\AppData\Local\Temp\PUBLISH8kiit\38_20171116T010915\autorest.modeler\src\SwaggerModeler.cs:line 105
   at AutoRest.Modeler.Program.<ProcessInternal>d__2.MoveNext() in C:\Users\ci\AppData\Local\Temp\PUBLISH8kiit\38_20171116T010915\autorest.modeler\src\Program.cs:line 60
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NewPlugin.<Process>d__15.MoveNext()
FATAL: csharp/imodeler1 - FAILED
FATAL: Error: Plugin imodeler1 reported failure.
Process() Cancelled due to exception : Plugin imodeler1 reported failure.
  Error: Plugin imodeler1 reported failure.

Most helpful comment

I found that strategyArgs in my code is Dictionary. And it is generated as object in swagger.
I understand, that this may be wrong, but the error should be easier to understand.
I updated my API to accept List of typed objects instead of dictionary and generation works

All 8 comments

Can you post the swagger file?

{
    "swagger": "2.0",
    "info": {
        "version": "v1",
        "title": "DistributedTest Agent"
    },
    "basePath": "/",
    "paths": {
        "/api/Screen/available": {
            "get": {
                "tags": [
                    "Screen"
                ],
                "summary": "Returns status of screen on the machine",
                "operationId": "ApiScreenAvailableGet",
                "consumes": [],
                "produces": [
                    "text/plain",
                    "application/json",
                    "text/json"
                ],
                "responses": {
                    "200": {
                        "description": "Success",
                        "schema": {
                            "type": "boolean"
                        }
                    }
                }
            }
        },
        "/api/Test/run-axiomtrader": {
            "post": {
                "tags": [
                    "Test"
                ],
                "operationId": "ApiTestRun-axiomtraderPost",
                "consumes": [],
                "produces": [
                    "text/plain",
                    "application/json",
                    "text/json"
                ],
                "parameters": [
                    {
                        "name": "distributedId",
                        "in": "query",
                        "required": true,
                        "type": "string",
                        "format": "uuid"
                    },
                    {
                        "name": "version",
                        "in": "query",
                        "required": false,
                        "type": "string"
                    },
                    {
                        "name": "testNames",
                        "in": "query",
                        "required": false,
                        "type": "array",
                        "items": {
                            "type": "string"
                        },
                        "collectionFormat": "multi"
                    },
                    {
                        "name": "whereFilter",
                        "in": "query",
                        "required": false,
                        "type": "string"
                    },
                    {
                        "name": "hangingTestTimeout",
                        "in": "query",
                        "required": false,
                        "type": "string"
                    },
                    {
                        "name": "strategyArgs",
                        "in": "query",
                        "required": false,
                        "type": "object"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Success",
                        "schema": {
                            "type": "boolean"
                        }
                    }
                }
            }
        },
        "/api/Test/current": {
            "get": {
                "tags": [
                    "Test"
                ],
                "operationId": "ApiTestCurrentGet",
                "consumes": [],
                "produces": [
                    "text/plain",
                    "application/json",
                    "text/json"
                ],
                "responses": {
                    "200": {
                        "description": "Success",
                        "schema": {
                            "$ref": "#/definitions/TestRun"
                        }
                    }
                }
            }
        },
        "/api/Test/status": {
            "get": {
                "tags": [
                    "Test"
                ],
                "operationId": "ApiTestStatusGet",
                "consumes": [],
                "produces": [
                    "text/plain",
                    "application/json",
                    "text/json"
                ],
                "responses": {
                    "200": {
                        "description": "Success",
                        "schema": {
                            "type": "boolean"
                        }
                    }
                }
            }
        },
        "/api/Test/cancel": {
            "get": {
                "tags": [
                    "Test"
                ],
                "operationId": "ApiTestCancelGet",
                "consumes": [],
                "produces": [
                    "text/plain",
                    "application/json",
                    "text/json"
                ],
                "responses": {
                    "200": {
                        "description": "Success",
                        "schema": {
                            "type": "boolean"
                        }
                    }
                }
            }
        },
        "/api/Test/runs": {
            "get": {
                "tags": [
                    "Test"
                ],
                "operationId": "ApiTestRunsGet",
                "consumes": [],
                "produces": [
                    "text/plain",
                    "application/json",
                    "text/json"
                ],
                "parameters": [
                    {
                        "name": "started",
                        "in": "query",
                        "required": false,
                        "type": "string",
                        "format": "date-time"
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": true,
                        "type": "integer",
                        "format": "int32"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Success",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/TestRun"
                            }
                        }
                    }
                }
            }
        },
        "/api/Test/results": {
            "get": {
                "tags": [
                    "Test"
                ],
                "operationId": "ApiTestResultsGet",
                "consumes": [],
                "produces": [
                    "text/plain",
                    "application/json",
                    "text/json"
                ],
                "parameters": [
                    {
                        "name": "started",
                        "in": "query",
                        "required": false,
                        "type": "string",
                        "format": "date-time"
                    },
                    {
                        "name": "testRunId",
                        "in": "query",
                        "required": false,
                        "type": "string",
                        "format": "uuid"
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": true,
                        "type": "integer",
                        "format": "int32"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Success",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/TestResult"
                            }
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "TestRun": {
            "type": "object",
            "properties": {
                "id": {
                    "format": "uuid",
                    "type": "string"
                },
                "machineName": {
                    "type": "string"
                },
                "userName": {
                    "type": "string"
                },
                "version": {
                    "type": "string"
                },
                "testAssembly": {
                    "type": "string"
                },
                "description": {
                    "type": "string"
                },
                "testNames": {
                    "type": "string"
                },
                "whereFilter": {
                    "type": "string"
                },
                "preparationStrategy": {
                    "type": "string"
                },
                "strategyArgs": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/StrategyArgument"
                    }
                },
                "packages": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/PackageDefinition"
                    }
                },
                "results": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/TestResult"
                    }
                },
                "started": {
                    "format": "date-time",
                    "type": "string"
                },
                "finished": {
                    "format": "date-time",
                    "type": "string"
                },
                "duration": {
                    "type": "string"
                },
                "error": {
                    "type": "string"
                }
            }
        },
        "StrategyArgument": {
            "type": "object",
            "properties": {
                "id": {
                    "format": "uuid",
                    "type": "string"
                },
                "key": {
                    "type": "string"
                },
                "value": {
                    "type": "string"
                }
            }
        },
        "PackageDefinition": {
            "type": "object",
            "properties": {
                "id": {
                    "format": "uuid",
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "path": {
                    "type": "string"
                },
                "version": {
                    "type": "string"
                }
            }
        },
        "TestResult": {
            "type": "object",
            "properties": {
                "id": {
                    "format": "uuid",
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "started": {
                    "format": "date-time",
                    "type": "string"
                },
                "finished": {
                    "format": "date-time",
                    "type": "string"
                },
                "duration": {
                    "type": "string"
                },
                "passed": {
                    "type": "boolean"
                },
                "failed": {
                    "type": "boolean"
                },
                "ignored": {
                    "type": "boolean"
                },
                "ran": {
                    "type": "boolean"
                },
                "hang": {
                    "type": "boolean"
                },
                "errorMessage": {
                    "type": "string"
                },
                "stackTrace": {
                    "type": "string"
                },
                "testRunId": {
                    "format": "uuid",
                    "type": "string"
                },
                "testRun": {
                    "$ref": "#/definitions/TestRun"
                }
            }
        }
    },
    "securityDefinitions": {}
}

I installed autorest a couple of days ago. Today I used this same swagger file to generate classes. It went ok.
But in the output I saw "there is a new version, bla bla" and updated autorest.
Now it doesn't work

I found out what's making it mad; strategyArgs in /api/Test/run-axiomtrader has a type of object -- but that's perfectly legal swagger.

I think that it's possible that a tangential bug fix on inline models may have caused a problem -- @olydis -- is this related to that?

to go back to the previous version until we fix it:

npm install -g [email protected]
autorest --reset

I tried to go previous version. But this is only bootstrap version. And it still download latest modeler

I found that strategyArgs in my code is Dictionary. And it is generated as object in swagger.
I understand, that this may be wrong, but the error should be easier to understand.
I updated my API to accept List of typed objects instead of dictionary and generation works

Sounds like the issue is resolved, will close 馃檪 You're absolutely right about the better error message, tracked that here.

Was this page helpful?
0 / 5 - 0 ratings