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] Inspect Polyfill Does Not Gracefully Handle Invalid Dates #266

Open
Brittank88 opened this issue Sep 30, 2023 · 3 comments
Open
Labels
bug Something isn't working

Comments

@Brittank88
Copy link

Describe the Bug
In the case of an invalid date present inside an object that is being logged, the polyfill throws:
image

To Reproduce

  1. Create an object containing an invalid date.
  2. Attempt to log the object with tslog.

Expected Behaviour
I believe that logging should be able to continue without failing hard on invalid data of any kind; what the browser does is show these sorts of invalid dates in particular as Invalid Date - pretty simple.

Screenshots
image

Additional context
N/A

Node.js Version
v18.17.0

OS incl. Version
Windows 10

@Brittank88 Brittank88 added the bug Something isn't working label Sep 30, 2023
@terehov
Copy link
Contributor

terehov commented Sep 30, 2023

Can you provide some code so that I can reproduce your example? Thank you

@Brittank88
Copy link
Author

This is the most concise reproduction I can think of:

import { Logger } from "tslog";

(new Logger()).info({ invalidDate: new Date(NaN) });

@Brittank88
Copy link
Author

This is a patch I'm using in the meantime:

diff --git a/node_modules/tslog/dist/cjs/runtime/browser/util.inspect.polyfil.js b/node_modules/tslog/dist/cjs/runtime/browser/util.inspect.polyfil.js
index a18d789..8d772eb 100644
--- a/node_modules/tslog/dist/cjs/runtime/browser/util.inspect.polyfil.js
+++ b/node_modules/tslog/dist/cjs/runtime/browser/util.inspect.polyfil.js
@@ -78,7 +78,7 @@ function isError(e) {
     return isObject(e) && (objectToString(e) === "[object Error]" || e instanceof Error);
 }
 function isDate(d) {
-    return isObject(d) && objectToString(d) === "[object Date]";
+    return isObject(d) && objectToString(d) === "[object Date]" && !isNaN(d.valueOf());
 }
 function objectToString(o) {
     return Object.prototype.toString.call(o);

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