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

If FuncGet() returns no code dont convert to str #89

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 40 additions & 34 deletions monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,40 +318,46 @@ func (sc *snowflakeConn) rowsForRunningQuery(

// Wait for query to complete from a query id from /queries/<qid>/result endpoint.
func (sc *snowflakeConn) blockOnRunningQuery(
ctx context.Context, qid string) error {
resultPath := fmt.Sprintf(urlQueriesResultFmt, qid)
resp, err := sc.waitForCompletedQueryResultResp(ctx, resultPath)
if err != nil {
logger.WithContext(ctx).Errorf("error: %v", err)
if resp != nil {
code, err := strconv.Atoi(resp.Code)
if err != nil {
return err
}
return (&SnowflakeError{
Number: code,
SQLState: resp.Data.SQLState,
Message: err.Error(),
QueryID: resp.Data.QueryID,
}).exceptionTelemetry(sc)
}
return err
}
if !resp.Success {
message := resp.Message
code, err := strconv.Atoi(resp.Code)
if err != nil {
code = ErrQueryStatus
message = fmt.Sprintf("%s: (failed to parse original code: %s: %s)", message, resp.Code, err.Error())
}
return (&SnowflakeError{
Number: code,
SQLState: resp.Data.SQLState,
Message: message,
QueryID: resp.Data.QueryID,
}).exceptionTelemetry(sc)
}
return nil
ctx context.Context, qid string) error {
resultPath := fmt.Sprintf(urlQueriesResultFmt, qid)
resp, err := sc.waitForCompletedQueryResultResp(ctx, resultPath)
if err != nil {
logger.WithContext(ctx).Errorf("error: %v", err)
if resp != nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will sc.waitForCompletedQueryResultResp ever return a non-nil resp if there was an error? I feel like we may be able to ignore this case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know why it would but they do this "if error and resp..." logic in rowsForRunningQuery which makes me worry that in some strange case FuncGet could return an error and a response... which I definitely dont like. Maybe it would be best to just say if there is an error return the error and ignore the response to keep things consistent

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I think I will keep it in here for now but if you think it would be better to remove it I can make a follow up pr!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, no worries

code := -1
if resp.Code != "" {
code, err = strconv.Atoi(resp.Code)
if err != nil {
return err
}
}
return (&SnowflakeError{
Number: code,
SQLState: resp.Data.SQLState,
Message: err.Error(),
QueryID: resp.Data.QueryID,
}).exceptionTelemetry(sc)
}
return err
}
if !resp.Success {
message := resp.Message
code := -1
if resp.Code != "" {
code, err = strconv.Atoi(resp.Code)
if err != nil {
code = ErrQueryStatus
message = fmt.Sprintf("%s: (failed to parse original code: %s: %s)", message, resp.Code, err.Error())
}
}
return (&SnowflakeError{
Number: code,
SQLState: resp.Data.SQLState,
Message: message,
QueryID: resp.Data.QueryID,
}).exceptionTelemetry(sc)
}
return nil
}

// prepare a Rows object to return for query of 'qid'
Expand Down