Repository navigation
feat(storage): append troubleshooting hints to fetch/TLS and 401 errors - #9875
thiyaguk09 wants to merge 3 commits into
Conversation
… 401 errors Appends actionable CPU starvation troubleshooting hints to native fetch/undici connection or TLS handshake timeouts and 401 Invalid Credentials errors while preserving original error prototypes, stack traces, and cause properties. Also documents troubleshooting guidance in README.md and adds unit tests in test/storage-transport.ts.
There was a problem hiding this comment.
Code Review
This pull request introduces error augmentation to append troubleshooting hints for native fetch/TLS timeouts and 401 Invalid Credentials errors, particularly targeting issues seen in constrained environments like Kubernetes. It adds a troubleshooting section to the README, implements the augmentError utility to safely append hints without losing error metadata (even for frozen objects), integrates this utility across several modules, and adds comprehensive unit tests. The review feedback correctly identifies a potential runtime crash in storage-transport.ts where directly mutating err.code on a frozen error object would throw a TypeError in strict mode, and suggests wrapping the assignment in a try/catch block.
Guards err.code, err.message, and err.errors assignments in decorateError via setErrorProperty so frozen or read-only error objects do not throw TypeError in strict mode while preserving prototype, symbol keys, stack, and cause.
|
/Gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces error augmentation functionality to append helpful troubleshooting hints (such as CPU starvation or token expiration warnings) to native fetch/TLS timeouts and 401 Invalid Credentials errors. It updates resumable-upload.ts, storage-transport.ts, and transfer-manager.ts to utilize these new utilities, documents the troubleshooting steps in the README, and adds comprehensive unit tests. The review feedback highlights two key improvement opportunities in util.ts: first, ensuring that all copied descriptors (including accessors) are marked as configurable when cloning frozen or non-configurable error objects to prevent runtime TypeErrors; second, making the wrapped fetch error detection more robust by removing the strict outer message check.
…h errors
Marks accessor descriptors as configurable when cloning frozen errors in setErrorProperty and removes the strict outer message check when detecting GaxiosError-wrapped TypeError('fetch failed') errors.
Description
Appends CPU starvation hints to fetch/TLS timeout and 401 storage errors.
Impact
Helps Kubernetes users diagnose event-loop starvation behind timeouts and expired tokens.
Changes
augmentErrorandappendErrorHintinhandwritten/storage/src/util.tsto append troubleshooting hints without rewrapping errors or losing original prototypes, stack traces, orcauseproperties:fetch/undicitimeouts (TypeError: fetch failedwithcause.code === 'UND_ERR_CONNECT_TIMEOUT'orcause.message.includes('TLS'), both direct andGaxiosError-wrapped).401 Invalid Credentialsresponses (err.code === 401orerr.status === 401).augmentErrorintoStorageTransport#makeRequest(handwritten/storage/src/storage-transport.ts),Upload#makeRequest/Upload#makeRequestStream/Upload#responseHandler(handwritten/storage/src/resumable-upload.ts), andXMLMultiPartUploadHelper(handwritten/storage/src/transfer-manager.ts).handwritten/storage/README.mddetailing event-loop starvation in constrained Kubernetes pods and recommended mitigations.Testing
handwritten/storage/test/storage-transport.tsverifying:fetch failederrors withUND_ERR_CONNECT_TIMEOUTand TLS handshake cause messages include the CPU starvation hint while preservingTypeErrorprototype,stack, andcause.GaxiosError-wrappedfetch failederrors include the CPU starvation hint while preservingGaxiosErrorprototype andcause.fetch failederrors with unrelated causes (e.g.,ECONNREFUSED) are left unchanged.401responses include the in-flight token expiration hint while preservingGaxiosErrorprototype,stack, andcause.stack, andcauseintact.pnpm test, andpnpm run lintinhandwritten/storage.