databricks-sdk-go icon indicating copy to clipboard operation
databricks-sdk-go copied to clipboard

[ISSUE] `apierr.GetAPIError` does not unmarshal `ErrorCode` correctly

Open nkvuong opened this issue 1 year ago • 3 comments

Description apierr.GetAPIError does not unmarshal ErrorCode correctly

Reproduction Below is a simplified version of parseErrorFromResponse

func main() {

	myError := apierr.APIError{
		ErrorCode: "RESOURCE_DOES_NOT_EXIST",
		Message:   "Path (/Users/abc) doesn't exist.",
	}
	b, err := json.Marshal(myError)
	if err != nil {
		panic(err)
	}
	print(b)
	var errorBody struct {
		ErrorCode any    `json:"error_code,omitempty"`
		Message   string `json:"message,omitempty"`
	}
	err = json.Unmarshal(b, &errorBody)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%+v\n", errorBody)
}

Expected behavior errorBody should be populated with ErrorCode & Message, however, ErrorCode is nil in this case

{ErrorCode:<nil> Message:Path (/Users/abc) doesn't exist.}

nkvuong avatar Jul 29 '24 08:07 nkvuong