Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BE - Node Mongoose Warning errors is a reserved schema pathname and may break some functionality #1539

Open
mertssmnoglu opened this issue Jan 9, 2025 · 2 comments

Comments

@mertssmnoglu
Copy link
Contributor

Describe the bug

Checkmate uses Capture as an Infrastructure monitoring agent. The Capture API Response includes errors field to correlate the data that cannot be retrieved. This responses are stored in MongoDB with the same key names, but since the `errors' object is a reserved schema pathname, Mongoose throws a warning as follows.

(node:544409) [MONGOOSE] Warning: `errors` is a reserved schema pathname and may break some functionality. You are allowed to use it, but use at your own risk. To disable this warning pass `suppressReservedKeysWarning` as a schema option.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Server/
  2. Install dependencies npm install
  3. Run npm run dev
  4. Scroll up to head of the logs
  5. See the warning starts with (node:544409) [MONGOOSE] Warning

Expected behavior
Seeing the log messages clearly in the terminal without any errors or warnings.

Additional context
For more information about reserved keys you can visit MongooseDocs#Schema.reserved

Possible Actions

  1. Changing the DB CRUD methods
    It will be more useful and safe solution for everyone.
  2. Changing the API Schema of the Capture
    A new version of Capture might be required for the users.
  3. Disabling the warning.
    To disable this warning pass suppressReservedKeysWarning as a schema option.
@ajhollid
Copy link
Collaborator

@mertssmnoglu can you elaborate on possible action 1? What are you thinking here?

@mertssmnoglu
Copy link
Contributor Author

Hey @ajhollid, I'm thinking about renaming the errors key in the Hardware Check Model because it's reserved on the mongoose.

https://github.com/bluewave-labs/checkmate/blob/0e443e4088ffe2f1f140aaa7717d7a45889bc41f/Server/db/models/HardwareCheck.js#L58-L61

My Options

[
  "error", "hardwareErrors", "hardwareError", "infrastructureErrors",
  "infraErrors", "hwErr", "errorsObj", "errObj", "err"
]

Spread syntax used here, because all of the keys are same as the Hardware Check Model
If we decide to rename the key, we will no longer be able to use spread syntax on the Hardware Check Module

https://github.com/bluewave-labs/checkmate/blob/0e443e4088ffe2f1f140aaa7717d7a45889bc41f/Server/db/mongo/modules/hardwareCheckModule.js#L35-L37

New code block will be like that

const hardwareCheck = await new HardwareCheck({
	//comes from "Base Check Model"
	monitorId: hardwareCheckData.monitorId,
	status: hardwareCheckData.status,
	responseTime: hardwareCheckData.responseTime,
	statusCode: hardwareCheckData.statusCode,
	message: hardwareCheckData.message,
	expiry: hardwareCheckData.expiry,

	cpu: hardwareCheckData.cpu,
	memory: hardwareCheckData.memory,
	disk: hardwareCheckData.disk,
	host: hardwareCheckData.host,	
	
	SOME_NEW_ERRORS_KEY: hardwareCheckData.errors
}).save();

Yes, spread operator is very clean and useful but I think we should rename the errors with something different. Because of this. I'm not sure about how big is the "Breaking Plugin Functionality" issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants