googleapis / googleapis/google-cloud-node

Prevent CloudFlare Workers breakage if getColorDepth is not available

Open
#7,684 3 comments 1 reaction 1 assignee Claimed by @feywind View on GitHub
library: google-cloud-node-core size: s type: bug
Dominant language
TypeScript
Stars
3.2k
Forks
712
Avg merge
2d 3h
Merged PRs (30d)
99

Description

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used [patch-package](https://github.com/ds300/patch-package) to patch `google-logging-utils@0.0.2` 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.

https://github.com/googleapis/js-genai/issues/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
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](https://github.com/ds300/patch-package/issues/296).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.