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

fix(useLogger): remove '<empty string>', allow any args/string substitution #510

Merged
merged 4 commits into from
Mar 30, 2024

Conversation

andretchen0
Copy link
Contributor

@andretchen0 andretchen0 commented Jan 13, 2024

Closes #508

Problem

useLogger().logError was logging <empty string> if only one argument was provided.

Solution

Remove the special case for error || '' below. Instead, let console.error handle all the arguments as it does by default.

console.error(`${logPrefix} ${message}`, error || '')

Problem

Console string substitution was not working with useLogger().logError and useLogger().logWarning.

Solution

If the first arg is a string, concatenate the logPrefix to the first arg. And allow any type (including strings, numbers) for subsequent args.

Otherwise, avoid coercing the first argument to a string, as this will incorrectly trigger string substitution.


Problem

Could not console.error or console.warn any type, or any number of arguments. (E.g., console.warn accepts 1 to n number of arguments, which can be any object, but userLogger().logWarning only accepted 1 string.)

Solution

Type check to enforce at least 1 argument but allow many. Allow any type of argument.

Copy link

netlify bot commented Jan 13, 2024

Deploy Preview for tresjs-docs ready!

Name Link
🔨 Latest commit 541284f
🔍 Latest deploy log https://app.netlify.com/sites/tresjs-docs/deploys/660832dbc0b32f0009473457
😎 Deploy Preview https://deploy-preview-510--tresjs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@andretchen0 andretchen0 removed the request for review from alvarosabu January 13, 2024 11:32
@andretchen0 andretchen0 marked this pull request as ready for review January 13, 2024 12:58
@alvarosabu alvarosabu added the p1-chore Doesn't change end-user code behavior (priority) label Mar 30, 2024
@andretchen0 andretchen0 merged commit 3163714 into main Mar 30, 2024
7 checks passed
@andretchen0 andretchen0 deleted the fix/useLogger branch March 30, 2024 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p1-chore Doesn't change end-user code behavior (priority)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

useLogger().logError("single arg") logs <empty string>
2 participants