realm-js
realm-js copied to clipboard
Realm JS should never call console.log, console.warn or console.error
Goals
As mentioned in https://github.com/realm/realm-js/issues/2125#issuecomment-440616047 it would be great if Realm JS would never log to the console.
Expected Results
It's idiomatic that JavaScript libraries, such as Realm JS, never call console.log
as it pollutes a global resource (the console) and it is annoying for developers that they need to figure out how to disable it. I suggest that we use the debug
package instead by providing a default implementation for Realm.Sync.setSyncLogger
to use. This way a user can run any app using RealmJS with the DEBUG=realm
environment variable set to get the log messages. Additionally we could split up logging in the separate levels, one logger (which it's own context) per level.
Examples of places where Realm JS is logging unexpectedly:
- when revoking a token upon logout fails.
- when refreshing an admin token fails.
- when refreshing an access token fails.
Adding to the frustration here, Realm JS doesn't contextualize the error being logged when a token refresh fail. The immediate error is printed but the operation which was being performed (or that the error is even originating from Realm JS) is never relayed to the user:
{ FetchError: request to https://whatever.cloud.realm.io/auth failed, reason: connect ECONNREFUSED 3.112.70.142:443
at ClientRequest.<anonymous> (/.../node_modules/realm/node_modules/node-fetch/index.js:133:11)
at ClientRequest.emit (events.js:189:13)
at TLSSocket.socketErrorListener (_http_client.js:392:9)
at TLSSocket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
name: 'FetchError',
message:
'request to https://whatever.de1a.cloud.realm.io/auth failed, reason: connect ECONNREFUSED 3.112.70.142:443',
type: 'system',
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED' }
Version of Realm and Tooling
- Realm JS SDK Version: 2.23.0
- Node or React Native: Both
- Client OS & Version: N/A
- Which debugger for React Native: N/A
I've update the description ☝️ to include examples of where this happens an a stacktrace which makes it really hard to debug errors like this.