Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unmarshalling JSON error in DeploymentOperationsClient.ListNextResults #938

Closed
dmitsh opened this issue Jan 3, 2018 · 15 comments
Closed
Assignees

Comments

@dmitsh
Copy link

dmitsh commented Jan 3, 2018

Failure responding to next results request:

StatusCode=200 -- Original Error: Error occurred unmarshalling JSON - Error = 'json: cannot unmarshal string into Go struct field DeploymentOperationProperties.statusMessage of type map[string]interface {}' JSON = '{"value":[{"id":"/subscriptions/3014546b-7d1c-4f80-8523-f24a9976fe6a/resourceGroups/ds-acse-tst40/providers/Microsoft.Resources/deployments/agent-18-01-03T10.39.23-1324017081/operations/08586866021206228739","operationId":"08586866021206228739","properties":{"provisioningOperation":"EvaluateDeploymentOutput","provisioningState":"Failed","timestamp":"2018-01-03T18:41:51.0473602Z","duration":"PT0.5431112S","trackingId":"98f19b12-ae95-49db-953b-6c983868f5e4","statusCode":"Conflict","statusMessage":"Template output evaluation skipped: at least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details."}}]}'

By comparing JSON data with DeploymentOperationProperties, the latter

  • doesn't have duration field
  • has StatusMessage is a map, not a string
@joshgav joshgav added bug This issue requires a change to an existing behavior in the product in order to be resolved. next and removed next labels Jan 3, 2018
@jhendrixMSFT
Copy link
Member

jhendrixMSFT commented Jan 5, 2018

Swagger bug? The statusMessage field is defined as an object.

@jhendrixMSFT
Copy link
Member

Here's the returned JSON in indented format.

{
  "value": [
    {
      "id": "/subscriptions/3014546b-7d1c-4f80-8523-f24a9976fe6a/resourceGroups/ds-acse-tst40/providers/Microsoft.Resources/deployments/agent-18-01-03T10.39.23-1324017081/operations/08586866021206228739",
      "operationId": "08586866021206228739",
      "properties": {
        "provisioningOperation": "EvaluateDeploymentOutput",
        "provisioningState": "Failed",
        "timestamp": "2018-01-03T18:41:51.0473602Z",
        "duration": "PT0.5431112S",
        "trackingId": "98f19b12-ae95-49db-953b-6c983868f5e4",
        "statusCode": "Conflict",
        "statusMessage": "Template output evaluation skipped: at least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details."
      }
    }
  ]
}

@jhendrixMSFT
Copy link
Member

@vivsriaus Are you the owner of the resources swagger (I dug up your name from specs history)? I'm trying to understand why the statusMessage field is defined as object when it's coming across the wire as a string.

@vivsriaus
Copy link

@jhendrixMSFT yes, this is because the statusMessage property is defined as a JToken in ARM, and it could potentially contain an ErrorMessage object (with its own "Code", "Message", "Target", "Details", "Innererror" properties)

@jhendrixMSFT
Copy link
Member

The problem here is that the server didn't return an object but a simple string which doesn't fit the definition. @amarzavery do you have any thoughts on this?

@jhendrixMSFT
Copy link
Member

Ping @amarzavery.
@vivsriaus can you please clarify what you mean by "JToken in ARM". The swagger, which is supposed to be the source of truth, defines this field as an object. In this example it's clear that what was sent across the wire is not an object.

@vivsriaus
Copy link

@jhendrixMSFT Like I mentioned above, the statusMessage property in DeploymentOperation can either return a string (like the case above) or an ErrorMessage object. Shouldn't autorest consider this as an object (which will then allow string to be processed as well), instead of string?

@jhendrixMSFT
Copy link
Member

I'm not an expert on the W3C spec but my understanding is that a JSON object is defined like this, so sending a simple string across the wire doesn't meet that definition.
CC @johanste

@johanste
Copy link
Member

In swagger (and JSON schema), a string is not an object. You can mentally replace object with dictionary in most cases. It so happens to (accidentally) work in most languages simply due to strings pretty much always derive from object.

In this case, will the return type always be a string, or does it depend on the context?

@jhendrixMSFT
Copy link
Member

OK that's what I thought and is in fact how we model JSON objects in Go.

map[string]interface{}

So it would seem that the service isn't honoring the contract defined in the swagger yes?

@vivsriaus
Copy link

To answer @johanste 's question, yes, the return type depends on the context. I'll try to find a real world example where an object is returned for a DeploymentOperation

@jhendrixMSFT
Copy link
Member

@vivsriaus Any update?

@vivsriaus
Copy link

@jhendrixMSFT I'll talk to our team and see if we can make a fix to always return either a string or an object for DeploymentOperationProperties.StatusMessage. Like I mentioned, currently, the statusMessage type returned depends on the context. I'm not sure if this is a common scenario in other object models, but it looks like autorest currently doesn't have a way to work with both types (string and object) at the same time.

@jhendrixMSFT
Copy link
Member

This is not an autorest issue. What you're asking for cannot be modeled in swagger as string and object are fundamentally different types.

@jhendrixMSFT jhendrixMSFT removed bug This issue requires a change to an existing behavior in the product in order to be resolved. investigating labels Jan 29, 2018
@jhendrixMSFT
Copy link
Member

This should be fixed in v14.0.0. The statusMessage field is now defined as interface{} so you will need to perform type assertion to determine if it's a string or JSON object.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants