surrealdb / surrealdb.js

SurrealDB SDK for JavaScript
https://surrealdb.com
Apache License 2.0
271 stars 46 forks source link

Bug: MissingNamespaceDatabase: There are no namespace and/or database configured. #284

Closed cope closed 6 days ago

cope commented 3 weeks ago

Describe the bug

I keep seeing this error in my logs, even though I am still able to run queries just fine:

Trace: Unhandled Rejection Promise: Promise {
  <rejected> MissingNamespaceDatabase: There are no namespace and/or database configured.
      at HttpEngine.rpc (/my-server/node_modules/.pnpm/surrealdb.js@1.0.0-beta.9/node_modules/surrealdb.js/src/library/engine.ts:340:10)
      at async Surreal.ping (/my-server/node_modules/.pnpm/surrealdb.js@1.0.0-beta.9/node_modules/surrealdb.js/src/surreal.ts:173:21)
}
    at process.<anonymous> (/my-server/src/server/functions/server/add.process.error.handling.events.ts:18:11)
    at process.emit (node:events:518:28)
    at process.emit (node:domain:488:12)
    at process.emit.sharedData.processEmitHook.installedValue [as emit] (/my-server/node_modules/.pnpm/@cspotcode+source-map-support@0.8.1/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)
    at emit (node:internal/process/promises:150:20)
    at processPromiseRejections (node:internal/process/promises:284:27)
    at processTicksAndRejections (node:internal/process/task_queues:96:32)
Trace: error unhandledRejection {
  unhandledRejectionReason: MissingNamespaceDatabase: There are no namespace and/or database configured.
      at HttpEngine.rpc (/my-server/node_modules/.pnpm/surrealdb.js@1.0.0-beta.9/node_modules/surrealdb.js/src/library/engine.ts:340:10)
      at async Surreal.ping (/my-server/node_modules/.pnpm/surrealdb.js@1.0.0-beta.9/node_modules/surrealdb.js/src/surreal.ts:173:21),
  unhandledRejectionPromise: '{}',
  level_name: 'error'
}

Steps to reproduce

export default class SurrealDBService {
    public static async init(): Promise<SurrealDBService> {
        if (!SurrealDBService._instance || !SurrealDBService._db) {
            this._db = new Surreal();

            await this._db.connect(config.connections.surrealdb.url);

            await this._db.use({
                namespace: config.connections.surrealdb.namespace,
                database: config.connections.surrealdb.database
            });

            this._token = await this._db.signin({
                username: config.connections.surrealdb.username,
                password: config.connections.surrealdb.password
            });
            console.log('surreal', this._token);
        }

        this._instance = new SurrealDBService();
        return this._instance;
    }

    private static _initialized: boolean = false;
    private static _token: string;
    private static _db: Surreal;
    private static _instance: SurrealDBService;
}

All values under config.connections.surrealdb are correct, as I am still able to connect and run querries successfully.

This seems to be an error in the ping call.

Expected behaviour

not to throw an error...

SurrealDB version

1.5.3 for linux on x86_64

SurrealDB.js version

1.0.0-beta.9

Contact Details

stojadinovicp@gmail.com

Is there an existing issue for this?

Code of Conduct

kearfy commented 2 weeks ago

Hey @cope, thanks for opening this issue! While I was not able to reproduce this issue locally, I will be removing the pinger for the HTTP engine in general, as it was only added there by mistake! Only the WS engine needs a pinger, as the websocket implementation is sometimes flaky. I'll be working on some more improvements, but in one of the next beta's this issue will be fixed :D

cope commented 2 weeks ago

@kearfy Thanks 😃

I hope it will be soon, 'cause this is annoying 😄

Trace: Unhandled Rejection Reason: HttpConnectionError: There was a problem with authentication.
    at process.<anonymous> (/my-app/src/server/functions/server/add.process.error.handling.events.ts:24:11)
    at process.emit (node:events:518:28)
    at process.emit (node:domain:488:12)
    at process.emit.sharedData.processEmitHook.installedValue [as emit] (/my-app/node_modules/.pnpm/@cspotcode+source-map-support@0.8.1/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)
    at emit (node:internal/process/promises:150:20)
    at processPromiseRejections (node:internal/process/promises:284:27)
    at processTicksAndRejections (node:internal/process/task_queues:96:32)
Trace: Unhandled Rejection Promise: Promise {
  <rejected> HttpConnectionError: There was a problem with authentication
      at HttpEngine.rpc (/my-app/node_modules/.pnpm/surrealdb.js@1.0.0-beta.9/node_modules/surrealdb.js/src/library/engine.ts:386:10)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Surreal.ping (/my-app/node_modules/.pnpm/surrealdb.js@1.0.0-beta.9/node_modules/surrealdb.js/src/surreal.ts:173:21) {
    status: 401,
    statusText: 'Unauthorized',
    buffer: ArrayBuffer {
      [Uint8Contents]: <54 68 65 72 65 20 77 61 73 20 61 20 70 72 6f 62 6c 65 6d 20 77 69 74 68 20 61 75 74 68 65 6e 74 69 63 61 74 69 6f 6e>,
      byteLength: 39
    }
  }
}
    at process.<anonymous> (/my-app/src/server/functions/server/add.process.error.handling.events.ts:25:11)
    at process.emit (node:events:518:28)
    at process.emit (node:domain:488:12)
    at process.emit.sharedData.processEmitHook.installedValue [as emit] (/my-app/node_modules/.pnpm/@cspotcode+source-map-support@0.8.1/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)
    at emit (node:internal/process/promises:150:20)
    at processPromiseRejections (node:internal/process/promises:284:27)
    at processTicksAndRejections (node:internal/process/task_queues:96:32)
Trace: error unhandledRejection {
  unhandledRejectionReason: HttpConnectionError: There was a problem with authentication
      at HttpEngine.rpc (/my-app/node_modules/.pnpm/surrealdb.js@1.0.0-beta.9/node_modules/surrealdb.js/src/library/engine.ts:386:10)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Surreal.ping (/my-app/node_modules/.pnpm/surrealdb.js@1.0.0-beta.9/node_modules/surrealdb.js/src/surreal.ts:173:21) {
    status: 401,
    statusText: 'Unauthorized',
    buffer: ArrayBuffer {
      [Uint8Contents]: <54 68 65 72 65 20 77 61 73 20 61 20 70 72 6f 62 6c 65 6d 20 77 69 74 68 20 61 75 74 68 65 6e 74 69 63 61 74 69 6f 6e>,
      byteLength: 39
    }
  },
  unhandledRejectionPromise: '{}',
  level_name: 'error'
}
    at Logger._processAndSendToWinston (/my-app/src/server/logger.ts:57:39)
    at Logger.error (/my-app/src/server/logger.ts:97:8)
    at process.<anonymous> (/my-app/src/server/functions/server/add.process.error.handling.events.ts:26:10)
    at process.emit (node:events:518:28)
    at process.emit (node:domain:488:12)
    at process.emit.sharedData.processEmitHook.installedValue [as emit] (/my-app/node_modules/.pnpm/@cspotcode+source-map-support@0.8.1/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)
    at emit (node:internal/process/promises:150:20)
    at processPromiseRejections (node:internal/process/promises:284:27)
    at processTicksAndRejections (node:internal/process/task_queues:96:32)