Your worker created multiple branches of a single stream (for instance, by calling response.clone()

I am getting this when trying to use a cloudflare worker together with the uploadthing library. I have debugged in VS-code and the error is thrown here when uploadthing library calls the safeParseJSON function: https://github.com/pingdotgg/uploadthing/blob/ea0f3c96f5db2fa945592d5efc06bf84811c5525/packages/shared/src/utils.ts#L233 Here is link to my cloudflare worker: https://github.com/kristiankauffeld/uploadthing-cf-worker
4 Replies
kian
kian6mo ago
Seems like a valid warning - it clones but only tries to read the second branch in the event of an error.
kristiankauffeld
@kian it throws the warning even though I commented the cloning part out:
export async function safeParseJSON<T>(
input: string | ResponseEsque | RequestLike,
): Promise<T | Error> {
if (typeof input === "string") {
try {
return JSON.parse(input) as T;
} catch (err) {
console.error(`Error parsing JSON, got '${input}'`);
return new Error(`Error parsing JSON, got '${input}'`);
}
}

//const clonedRes = input.clone?.();
try {
return (await input.json()) as T;
} catch (err) {
//const text = (await input?.text()) ?? "unknown";
//const text = await input?.text()) ?? "unknown";
//console.error(`Error parsing JSON, got '${text}'`);
return new Error(`Error parsing JSON, got '${input}'`);
}
}
export async function safeParseJSON<T>(
input: string | ResponseEsque | RequestLike,
): Promise<T | Error> {
if (typeof input === "string") {
try {
return JSON.parse(input) as T;
} catch (err) {
console.error(`Error parsing JSON, got '${input}'`);
return new Error(`Error parsing JSON, got '${input}'`);
}
}

//const clonedRes = input.clone?.();
try {
return (await input.json()) as T;
} catch (err) {
//const text = (await input?.text()) ?? "unknown";
//const text = await input?.text()) ?? "unknown";
//console.error(`Error parsing JSON, got '${text}'`);
return new Error(`Error parsing JSON, got '${input}'`);
}
}
kian
kian6mo ago
Look for other usages of clone
kristiankauffeld
the only other place I can find a usage of clone is here, but the warning is thrown before this is reached: https://github.com/pingdotgg/uploadthing/blob/ea0f3c96f5db2fa945592d5efc06bf84811c5525/packages/uploadthing/src/sdk/utils.ts#L85
Want results from more Discord servers?
Add your server
More Posts
Preventing the creation of similar and fraudulent domainsHello, I am a representative of a shipping company that is very often under attack by fraudsters whoSimple Worker 403 fetching https://api.github.com/graphqlI've double and triple checked tokens, access, etc and verified working with Postman and Node ScriptHow to add DNS Records for .Pages.dev domainHow can i add dns records for cloudflare pages domainMonthly user quota management / rate limitingHi! I want to build a SaaS product and have an API available to clients (requests allowed via domainStore a JWT to be pulled from a workerI'm need a worker to attach a JWT in the headers of a call to a 3rd party API. This JWT should be repages functions The server running locally is abnormal 500I started pages functions locally through wrangler, which sends an http request and returns 500 to tRequest to URL on the same zone but in CNAME configurationHello, I have a weird behavior that I have an hard time debugging. I reach out my worker via my custAfter the Discord failure, a sharp increase in visits by 33% from Singapore (and the website is fromSince the Analitics failure on November 2-6, 2023, statistics show a huge number of visits to my webIs there a way to use `pg` in a Next.js project setup with `@cloudflare/next-on-pages?I have project that is setup following https://developers.cloudflare.com/pages/framework-guides/deplA record broken????ok so bascily i set an A record and it was working perfectly fine like going good with no issues but