Skip to content

Commit

Permalink
chore: make use of optional catch binding (#683)
Browse files Browse the repository at this point in the history
Optional catch binding is a feature introduced in ECMAScript 2019 (ES10)
that allows you to use catch clauses in try/catch statements without
specifying an error variable
  • Loading branch information
patricebender authored Jun 14, 2024
1 parent 275688d commit 1809c6f
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion db-service/lib/SQLService.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class SQLService extends DatabaseService {
*/
async onSELECT({ query, data }) {
if (!query.target) {
try { this.infer(query) } catch (e) { /**/ }
try { this.infer(query) } catch { /**/ }
}
if (query.target && !query.target._unresolved) {
// Will return multiple rows with objects inside
Expand Down
2 changes: 1 addition & 1 deletion hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class HANAService extends SQLService {
const { query, data } = req

if (!query.target) {
try { this.infer(query) } catch (e) { /**/ }
try { this.infer(query) } catch { /**/ }
}
if (!query.target || query.target._unresolved) {
return super.onSELECT(req)
Expand Down
4 changes: 2 additions & 2 deletions hana/lib/drivers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Object.defineProperties(module.exports, {
// Have a bias to hdb as the default driver
if (dependencies.hdb) return module.exports.hdb
if (dependencies['@sap/hana-client']) return module.exports['hana-client']
} catch (e) {
} catch {
console.trace(`WARNING! Unable to require the project's package.json at "${cds.root + '/package.json'}". Please check your project setup.`)
}

// When no driver is installed still try to load any of the drivers
try {
return module.exports.hdb
} catch (e) {
} catch {
return module.exports['hana-client']
}
},
Expand Down
2 changes: 1 addition & 1 deletion postgres/lib/PostgresService.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ GROUP BY k
GRANT "${creds.usergroup}" TO "${creds.user}" WITH ADMIN OPTION;
`)
await this.exec(`CREATE DATABASE "${creds.database}" OWNER="${creds.user}" TEMPLATE=template0`)
} catch (e) {
} catch {
// Failed to reset database
} finally {
await this.dbc.end()
Expand Down
2 changes: 1 addition & 1 deletion postgres/test/beershop/srv/beershop-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = srv => {
let db
try {
db = await cds.connect.to('db')
} catch (err) {
} catch {
db = cds.db
}
await cds.deploy('./srv/', {}).to(db)
Expand Down
4 changes: 2 additions & 2 deletions sqlite/test/general/stream.compat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('streaming', () => {

try {
expect(changes).toEqual(2)
} catch (e) {
} catch {
// @sap/hana-client does not allow for returning the number of affected rows
}

Expand Down Expand Up @@ -218,7 +218,7 @@ describe('streaming', () => {
const changes = await INSERT.into(Images).entries(stream)
try {
expect(changes).toEqual(count)
} catch (e) {
} catch {
// @sap/hana-client does not allow for returning the number of affected rows
}
})
Expand Down
4 changes: 2 additions & 2 deletions sqlite/test/general/stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ describe('streaming', () => {

try {
expect(changes).toEqual(2)
} catch (e) {
} catch {
// @sap/hana-client does not allow for returning the number of affected rows
}

Expand Down Expand Up @@ -277,7 +277,7 @@ describe('streaming', () => {
const changes = await INSERT(stream).into(Images)
try {
expect(changes | 0).toEqual(count)
} catch (e) {
} catch {
// @sap/hana-client does not allow for returning the number of affected rows
}
}))
Expand Down
2 changes: 1 addition & 1 deletion test/cds.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ cds.test = Object.setPrototypeOf(function () {
const serviceDefinitionPath = testSource + 'test/service'
cds.env.requires.db = require(serviceDefinitionPath)
require(testSource + 'cds-plugin')
} catch (e) {
} catch {
// Default to sqlite for packages without their own service
cds.env.requires.db = require('@cap-js/sqlite/test/service')
}
Expand Down

0 comments on commit 1809c6f

Please sign in to comment.