fix: fix ignored context.DeadlineExceeded (#4066)

This commit is contained in:
Kevin Wan
2024-04-11 11:14:20 +08:00
committed by GitHub
parent 2a7ada993b
commit 927f8bc821
4 changed files with 7 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package sqlx
import (
"context"
"errors"
"reflect"
"strings"
@@ -87,6 +88,10 @@ func getValueInterface(value reflect.Value) (any, error) {
}
}
func isScanFailed(err error) bool {
return err != nil && !errors.Is(err, context.DeadlineExceeded)
}
func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([]any, error) {
fields := unwrapFields(v)
if strict && len(columns) < len(fields) {

View File

@@ -296,7 +296,7 @@ func (db *commonSqlConn) queryRows(ctx context.Context, scanner func(*sql.Rows)
return query(ctx, conn, func(rows *sql.Rows) error {
e := scanner(rows)
if e != nil && !errors.Is(e, context.DeadlineExceeded) {
if isScanFailed(e) {
scanFailed = true
}
return e

View File

@@ -144,7 +144,7 @@ func (s statement) queryRows(ctx context.Context, scanFn func(any, rowsScanner)
err := s.brk.DoWithAcceptable(func() error {
return queryStmt(ctx, s.stmt, func(rows *sql.Rows) error {
err := scanFn(v, rows)
if err != nil {
if isScanFailed(err) {
scanFailed = true
}
return err

View File

@@ -35,6 +35,5 @@ LABEL org.opencontainers.image.description="A cloud-native Go microservices fram
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.source="https://github.com/zeromicro/go-zero"
LABEL org.opencontainers.image.title="goctl (cli)"
LABEL org.opencontainers.image.version="v1.6.3"
ENTRYPOINT ["/usr/local/bin/goctl"]