Skip to content

Custom debug function missing last method argument #13364

Closed
@hieule3004

Description

@hieule3004

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

7.x.x

Node.js version

18.x

MongoDB server version

5

Typescript version (if applicable)

5

Description

Issue

[_this.name, i].concat(args.slice(0, args.length - 1)));

Logging with custom log function missing last argument due to incorrect slicing index.

Potential fix

Clone array with args.slice(0, args.length)

Risk

  • May require existing code to add redact action on large objects such as session which happen to be in last argument

Steps to Reproduce

import { connect } from 'mongoose';
import * as util from 'util';

(async () => {
  const MONGO_CONNECTION_STRING = 'mongodb://localhost:27017/db?&directConnection=true';
  const mongoose = await connect(MONGO_CONNECTION_STRING);

  mongoose.set('debug', (collectionName, methodName, ...methodArgs) => {
    console.log(`${collectionName}.${methodName}(${util.inspect(methodArgs).slice(2, -2)})`);
  });

  const collection = mongoose.connection.collection('Test');
  await collection.findOne({ key: 'value' });

  await mongoose.connection.close();
})();

Expected Behavior

Expect: print Test.findOne({ key: 'value' })
Actual: print Test.findOne()

Metadata

Metadata

Assignees

No one assigned

    Labels

    developer-experienceThis issue improves error messages, debugging, or reporting

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions