Repository: zeromicro/go-zero
Pull request #4063 (2024-04-10 09:11:24)

fix: fix ignored scanner.Err()

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/zeromicro/go-zero/pull/4063?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 95.16%. Comparing base [(`8690859`)](https://app.codecov.io/gh/zeromicro/go-zero/commit/8690859c7d1c9461bdc422c3c65608bde30904db?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro) to head [(`8c58e13`)](https://app.codecov.io/gh/zeromicro/go-zero/pull/4063?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro).
> Report is 8 commits behind head on master.

<details><summary>Additional details and impacted files</summary>



| [Files](https://app.codecov.io/gh/zeromicro/go-zero/pull/4063?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro) | Coverage Δ | |
|---|---|---|
| [core/stores/sqlx/orm.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/4063?src=pr&el=tree&filepath=core%2Fstores%2Fsqlx%2Form.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro#diff-Y29yZS9zdG9yZXMvc3FseC9vcm0uZ28=) | `94.15% <100.00%> (+1.25%)` | :arrow_up: |

... and [254 files with indirect coverage changes](https://app.codecov.io/gh/zeromicro/go-zero/pull/4063/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro)

</details>

Patch:
diff --git a/core/stores/sqlx/orm.go b/core/stores/sqlx/orm.go
index 9924eefc..feeed397 100644
--- a/core/stores/sqlx/orm.go
+++ b/core/stores/sqlx/orm.go
@@ -248,7 +248,7 @@ func unmarshalRows(v any, scanner rowsScanner, strict bool) error {
 			return ErrUnsupportedValueType
 		}
 
-		return nil
+		return scanner.Err()
 	default:
 		return ErrUnsupportedValueType
 	}


Test patch:
diff --git a/core/stores/sqlx/stmt_test.go b/core/stores/sqlx/stmt_test.go
index 34f67206..a2b0b1bb 100644
--- a/core/stores/sqlx/stmt_test.go
+++ b/core/stores/sqlx/stmt_test.go
@@ -291,19 +291,19 @@ func TestStmtBreaker(t *testing.T) {
 	})
 }
 
-func TestQueryScanTimeout(t *testing.T) {
+func TestQueryRowsScanTimeout(t *testing.T) {
 	dbtest.RunTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
-		ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
-		defer cancel()
-		row := sqlmock.NewRows([]string{"foo"})
+		rows := sqlmock.NewRows([]string{"foo"})
 		for i := 0; i < 10000; i++ {
-			row = row.AddRow("bar" + strconv.Itoa(i))
+			rows = rows.AddRow("bar" + strconv.Itoa(i))
 		}
+		mock.ExpectQuery("any").WillReturnRows(rows)
 		var val []struct {
-			Foo int
-			Bar string
+			Foo string
 		}
 		conn := NewSqlConnFromDB(db)
+		ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
+		defer cancel()
 		err := conn.QueryRowsCtx(ctx, &val, "any")
 		assert.ErrorIs(t, err, context.DeadlineExceeded)
 	})