Skip to content

Commit

Permalink
fix(db): add null check for database instance
Browse files Browse the repository at this point in the history
- Add null check for db instance in getLastNameOps
- Return empty array if db is null
- Add logging for debugging purposes

Prevents potential null reference errors when database is unavailable
  • Loading branch information
silkroadnomad committed Jan 20, 2025
1 parent eddf1bd commit 5fc1c25
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion relay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libp2p-relay",
"version": "0.12.28",
"version": "0.12.29",
"private": true,
"scripts": {
"start:no-restart": "node src/relay.js",
Expand Down
5 changes: 5 additions & 0 deletions relay/src/pinner/nameOpsFileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export async function updateDailyNameOpsFile(
export async function getLastNameOps(orbitdb, pageSize, from = 10, filter) {
try {
const db = await getOrCreateDB(orbitdb);
if(!db) {
console.log("db is null")
return []
}
const allDocs = await db.all();
let nameOps = [];

Expand Down Expand Up @@ -207,6 +211,7 @@ export async function closeDB() {
}

function applyFilter(nameOp, selectedFilter) {
console.log("applyFilter", nameOp, selectedFilter)
const hasNameValue =
nameOp.nameValue &&
nameOp.nameValue !== '' &&
Expand Down

0 comments on commit 5fc1c25

Please sign in to comment.