Skip to content

Commit

Permalink
Add error handling for OneAPIErrors in DataSetCompletion frame (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsafMah authored May 1, 2023
1 parent 3249bd5 commit e877826
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.12.1] - 2023-05-01
### Fixed
* Fixed parsing of errors in queries

## [0.12.0] - 2023-05-01
### Added
Expand Down
59 changes: 55 additions & 4 deletions kusto/internal/frames/v2/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v2

import (
"context"
"encoding/json"
"io"
"strings"
"testing"
Expand Down Expand Up @@ -344,8 +345,31 @@ func TestErrorDecode(t *testing.T) {
},
{
"FrameType":"DataSetCompletion",
"HasErrors":false,
"Cancelled":false
"HasErrors":true,
"Cancelled":false,
"OneApiErrors": [{
"error": {
"code": "LimitsExceeded",
"message": "Request is invalid and cannot be executed.",
"@type": "Kusto.Data.Exceptions.KustoServicePartialQueryFailureLimitsExceededException",
"@message": "Query execution has exceeded the allowed limits (80DA0003): .",
"@context": {
"timestamp": "2018-12-10T15:10:48.8352222Z",
"machineName": "RD0003FFBEDEB9",
"processName": "Kusto.Azure.Svc",
"processId": 4328,
"threadId": 7284,
"appDomainName": "RdRuntime",
"clientRequestId": "KPC.execute;d3a43e37-0d7f-47a9-b6cd-a889b2aee3d3",
"activityId": "a57ec272-8846-49e6-b458-460b841ed47d",
"subActivityId": "a57ec272-8846-49e6-b458-460b841ed47d",
"activityType": "PO-OWIN-CallContext",
"parentActivityId": "a57ec272-8846-49e6-b458-460b841ed47d",
"activityStack": "(Activity stack: CRID=KPC.execute;d3a43e37-0d7f-47a9-b6cd-a889b2aee3d3 ARID=a57ec272-8846-49e6-b458-460b841ed47d > PO-OWIN-CallContext/a57ec272-8846-49e6-b458-460b841ed47d)"
},
"@permanent": false
}
}]
}
]
`
Expand Down Expand Up @@ -442,9 +466,36 @@ func TestErrorDecode(t *testing.T) {
},
DataSetCompletion{
Base: Base{FrameType: "DataSetCompletion"},
HasErrors: false,
HasErrors: true,
Cancelled: false,
Op: errors.OpQuery,
OneAPIErrors: []interface{}{
map[string]interface{}{
"error": map[string]interface{}{
"@context": map[string]interface{}{
"activityId": "a57ec272-8846-49e6-b458-460b841ed47d",
"activityStack": "(Activity stack: CRID=KPC.execute;d3a43e37-0d7f-47a9-b6cd-a889b2aee3d3 ARID=a57ec272-8846-49e6-b458-460b841ed47d > PO-OWIN-CallContext/a57ec272-8846-49e6-b458-460b841ed47d)",
"activityType": "PO-OWIN-CallContext",
"appDomainName": "RdRuntime",
"clientRequestId": "KPC.execute;d3a43e37-0d7f-47a9-b6cd-a889b2aee3d3",
"machineName": "RD0003FFBEDEB9",
"parentActivityId": "a57ec272-8846-49e6-b458-460b841ed47d",
"processId": json.Number("4328"),
"processName": "Kusto.Azure.Svc",
"subActivityId": "a57ec272-8846-49e6-b458-460b841ed47d",
"threadId": json.Number("7284"),
"timestamp": "2018-12-10T15:10:48.8352222Z",
},
"@message": "Query execution has exceeded the allowed limits (80DA0003): .",
"@permanent": false,
"@type": "Kusto.Data.Exceptions.KustoServicePartialQueryFailureLimitsExceededException",
"code": "LimitsExceeded",
"message": "Request is invalid and cannot be executed.",
},
},
},
Error: *errors.ES(errors.OpUnknown, errors.KLimitsExceeded, "Request is invalid and cannot be executed.;See https://docs.microsoft."+
"com/en-us/azure/kusto/concepts/querylimits"),
Op: errors.OpQuery,
},
}

Expand Down
12 changes: 9 additions & 3 deletions kusto/internal/frames/v2/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ type DataSetCompletion struct {
// Cancelled indicates that the request was cancelled.
Cancelled bool
// OneAPIErrors is a list of errors encountered.
OneAPIErrors []string `json:"OneApiErrors"`
OneAPIErrors []interface{} `json:"OneApiErrors"`

Op errors.Op `json:"-"`
Error errors.Error
Op errors.Op `json:"-"`
}

// IsFrame implements frame.Frame.
Expand All @@ -98,8 +99,13 @@ func (DataSetCompletion) IsFrame() {}
func (d *DataSetCompletion) UnmarshalRaw(raw json.RawMessage) error {
err := json.Unmarshal(raw, &d)
if err != nil {
err = errors.GetCombinedError(fmt.Errorf("json parsing failed: %v", raw), err)
err = errors.GetCombinedError(fmt.Errorf("json parsing failed: %v", string(raw)), err)
} else {
if d.HasErrors {
d.Error = *errors.OneToErr(map[string]interface{}{"OneApiErrors": d.OneAPIErrors}, d.Op)
}
}

return err
}

Expand Down
2 changes: 1 addition & 1 deletion kusto/internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
package version

// Kusto is the version of this client package that is communicated to the server.
const Kusto = "0.12.0"
const Kusto = "0.12.1"
2 changes: 1 addition & 1 deletion quickstart/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/Azure/azure-kusto-go/quickstart

go 1.19

require github.com/Azure/azure-kusto-go v0.12.0
require github.com/Azure/azure-kusto-go v0.12.1

require (
github.com/Azure/azure-pipeline-go v0.1.8 // indirect
Expand Down

0 comments on commit e877826

Please sign in to comment.