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

Bug: [BUG] Crashes on undefined if maskValuesRegEx option specified #197

Closed
ekho opened this issue Dec 20, 2022 · 8 comments
Closed

Bug: [BUG] Crashes on undefined if maskValuesRegEx option specified #197

ekho opened this issue Dec 20, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@ekho
Copy link

ekho commented Dec 20, 2022

Describe the bug
Crashes on undefined if maskValuesRegEx option specified

To Reproduce

import { Logger } from 'tslog';

const logger = new Logger({ maskValuesRegEx: [/bearer \S+/] });

logger.info(undefined);

Expected behavior
Log empty value same as in case without maskValuesRegEx.

Screenshots

> node dist/cli
./node_modules/tslog/dist/cjs/BaseLogger.js:181
                                    source = source.replace(regEx, this.settings.maskPlaceholder);
                                                    ^

TypeError: Cannot read properties of undefined (reading 'replace')
    at ./node_modules/tslog/dist/cjs/BaseLogger.js:181:53
    at Array.forEach (<anonymous>)
    at ./node_modules/tslog/dist/cjs/BaseLogger.js:180:65
    at Logger._recursiveCloneAndMaskValuesOfKeys (./node_modules/tslog/dist/cjs/BaseLogger.js:184:31)
    at ./node_modules/tslog/dist/cjs/BaseLogger.js:154:25
    at Array.map (<anonymous>)
    at Logger._mask (./node_modules/tslog/dist/cjs/BaseLogger.js:153:22)
    at Logger.log (./node_modules/tslog/dist/cjs/BaseLogger.js:96:24)
    at Logger.info (./node_modules/tslog/dist/cjs/index.js:23:22)
    at Object.<anonymous> (./src/cli.ts:35:8)

Additional context
Add any other context about the problem here.

Node.js Version
Node.js v18.12.1

OS incl. Version
macOS 13.1 (22C65)

@ekho ekho added the bug Something isn't working label Dec 20, 2022
@terehov
Copy link
Contributor

terehov commented Dec 20, 2022

Thank you. I’ll fix it today

@ekho ekho changed the title Bug: [BUG] Bug: [BUG] Crashes on undefined if maskValuesRegEx option specified Dec 20, 2022
@ekho
Copy link
Author

ekho commented Dec 20, 2022

@terehov thank you!

@terehov
Copy link
Contributor

terehov commented Dec 20, 2022

V4.4.6 is out now 👍

@ekho
Copy link
Author

ekho commented Dec 20, 2022

Amazing )

@ekho
Copy link
Author

ekho commented Dec 20, 2022

@terehov yet another problem

import { Logger } from 'tslog';

const logger = new Logger({ maskValuesRegEx: [/bearer \S+/] });

logger.info({ count: 0 });
TypeError: source?.replace is not a function

./node_modules/tslog/dist/cjs/BaseLogger.js:181
                                    source = source?.replace(regEx, this.settings.maskPlaceholder);

problem with non string values

@terehov
Copy link
Contributor

terehov commented Dec 20, 2022

Ok, looks like a lack of tests. I'll add some tests and fix it. Thank you 👍

@terehov terehov reopened this Dec 20, 2022
@terehov
Copy link
Contributor

terehov commented Dec 20, 2022

I'll fix the other issues tomorrow and release a new version afterwards.

@terehov
Copy link
Contributor

terehov commented Dec 21, 2022

V4.6.0 is out that fixes this and adds more tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants