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

Custom debug function missing last method argument #13364

Closed
2 tasks done
hieule3004 opened this issue May 2, 2023 · 1 comment · Fixed by #13418
Closed
2 tasks done

Custom debug function missing last method argument #13364

hieule3004 opened this issue May 2, 2023 · 1 comment · Fixed by #13418
Labels
developer-experience This issue improves error messages, debugging, or reporting
Milestone

Comments

@hieule3004
Copy link

hieule3004 commented May 2, 2023

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()

@hieule3004 hieule3004 changed the title Set debug options missing last methodArgs Custom debug missing last method argument May 2, 2023
@hieule3004 hieule3004 changed the title Custom debug missing last method argument Custom debug function missing last method argument May 2, 2023
@vkarpov15 vkarpov15 added this to the 7.1.2 milestone May 3, 2023
@vkarpov15 vkarpov15 added the developer-experience This issue improves error messages, debugging, or reporting label May 3, 2023
vkarpov15 added a commit that referenced this issue May 18, 2023
fix: custom debug function not processing all args
@forivall
Copy link

I also see this happening in mongoose 6.8.0 - I'll submit a PR to backport the fix before the August eol date 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer-experience This issue improves error messages, debugging, or reporting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants