Skip to content

Commit

Permalink
Remove try without catch.
Browse files Browse the repository at this point in the history
The Scala 3 compiler reports a warning:

```scala
-- [E002] Syntax Warning: /Users/matt/scalasql/scalasql/core/src/DbApi.scala:205:8
205 |        try {
    |        ^
    |        A try without catch or finally is equivalent to putting
    |        its body in a block; no exceptions are handled.
206 |          val res = stream(query, fetchSize, queryTimeoutSeconds)(
207 |            qr.asInstanceOf[Queryable[Q, Seq[_]]],
208 |            fileName,
209 |            lineNum
210 |          )
211 |          if (qr.isSingleRow(query)) {
212 |            val results = res.take(2).toVector
213 |            assert(
214 |              results.size == 1,
215 |              s"Single row query must return 1 result, not ${results.size}"
216 |            )
217 |            results.head.asInstanceOf[R]
218 |          } else {
219 |            res.toVector.asInstanceOf[R]
220 |          }
221 |        }
```
  • Loading branch information
mrdziuban committed May 23, 2024
1 parent 9ffeb06 commit 011c3f6
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions scalasql/core/src/DbApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,20 @@ object DbApi {
.asInstanceOf[R]
else if (qr.isExecuteUpdate(query)) updateSql(flattened).asInstanceOf[R]
else {
try {
val res = stream(query, fetchSize, queryTimeoutSeconds)(
qr.asInstanceOf[Queryable[Q, Seq[_]]],
fileName,
lineNum
val res = stream(query, fetchSize, queryTimeoutSeconds)(
qr.asInstanceOf[Queryable[Q, Seq[_]]],
fileName,
lineNum
)
if (qr.isSingleRow(query)) {
val results = res.take(2).toVector
assert(
results.size == 1,
s"Single row query must return 1 result, not ${results.size}"
)
if (qr.isSingleRow(query)) {
val results = res.take(2).toVector
assert(
results.size == 1,
s"Single row query must return 1 result, not ${results.size}"
)
results.head.asInstanceOf[R]
} else {
res.toVector.asInstanceOf[R]
}
results.head.asInstanceOf[R]
} else {
res.toVector.asInstanceOf[R]
}
}
}
Expand Down

0 comments on commit 011c3f6

Please sign in to comment.