Skip to content

Prevent CloudFlare Workers breakage if getColorDepth is not available #1742

Open
@LSeuffert

Description

@LSeuffert

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

===

Ran into a bug that prevents from deploying on Cloudflare Workers due to getColorDepth being improperly polyfilled. Polyfill should probably be updated but this seems like something that can silently fail as its only for colors.

I ran into this when trying to use gmail API and it looks like others have also ran into this.

googleapis/js-genai#324
https://www.answeroverflow.com/m/1355156041402421248

Not sure if there's a better way to patch this but here is the diff that solved my problem:

diff --git a/node_modules/google-logging-utils/build/src/colours.js b/node_modules/google-logging-utils/build/src/colours.js
index 5132d72..9aed37b 100644
--- a/node_modules/google-logging-utils/build/src/colours.js
+++ b/node_modules/google-logging-utils/build/src/colours.js
@@ -28,10 +28,14 @@ class Colours {
      * @returns true if the stream should have colourization enabled
      */
     static isEnabled(stream) {
-        return (stream.isTTY &&
-            (typeof stream.getColorDepth === 'function'
-                ? stream.getColorDepth() > 2
-                : true));
+        try {
+            return (stream.isTTY &&
+                (typeof stream.getColorDepth === 'function'
+                    ? stream.getColorDepth() > 2
+                    : true));
+        } catch (error) {
+            return false;
+        }
     }
     static refresh() {
         Colours.enabled = Colours.isEnabled(process.stderr);

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

Labels

size: sPull request size is small.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions