Skip to content

Prevent CloudFlare Workers breakage if getColorDepth is not available #1742

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

Open
LSeuffert opened this issue Apr 26, 2025 · 2 comments
Open
Assignees
Labels
size: s Pull request size is small.

Comments

@LSeuffert
Copy link

LSeuffert commented Apr 26, 2025

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.

@LSeuffert LSeuffert changed the title Don't fail isEnabled if color depth not available. Prevent CloudFlare Workers breakage if getColorDepth is not available Apr 26, 2025
@feywind feywind self-assigned this Apr 29, 2025
@feywind
Copy link
Contributor

feywind commented Apr 29, 2025

@LSeuffert I do agree with this change, thanks! Which particular check is causing the issue? I'm interested in making the checks more robust as well.

@feywind feywind added the size: s Pull request size is small. label Apr 29, 2025
@LSeuffert
Copy link
Author

@feywind It's the stream.getColorDepth() > 2 check.

Just for context, it throws Uncaught TypeError: Cannot convert object to primitive value because the Cloudflare Worker environment doesn't have process.stderr and mocks it instead. So, that's why we're getting an object back from getColorDepth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: s Pull request size is small.
Projects
None yet
Development

No branches or pull requests

2 participants