Mitya
CDCloudflare Developers
•Created by Mitya on 1/9/2025 in #workers-help
Hyperdrive fails to connect in `scheduled()` (but works over HTTP)
8 replies
CDCloudflare Developers
•Created by Mitya on 1/6/2025 in #workers-help
"SyntaxError: Unexpected end of JSON input" in wrangler-dist/cli.js
This has happened a few times recently for me, after making some innocuous code changes. Restarting my PC seems to get rid of it, but it's annoying and I'm not sure what's causing it. Anyone any idea? Thanks in advance.
18 replies
CDCloudflare Developers
•Created by Mitya on 1/6/2025 in #workers-help
With the `scheduled` handler, what's the difference between waitUntil and just using async/await?
Is it necessary to use
waitUntil()
when I could just use good old async/await to delay termination of the worker?20 replies
CDCloudflare Developers
•Created by Mitya on 1/4/2025 in #workers-help
Another worker vs. workflow for background work?
We need to vectorise some user input to our worker, and my idea was to have a separate worker, via a binding, that could do this task without holding up the main worker that receives user input and gives output. I can do this via
waitUntil()
. However I just discovered Workflows and this sounds like much the same thing, suited to the task. Which would be better in my case and what are the key considerations?
Thank you.2 replies
CDCloudflare Developers
•Created by Mitya on 12/12/2024 in #workers-help
Can AI Functions work effectively with multiple inputs that it needs to iterate over?
I have a simple AI Function setup that's working. It extracts a couple of bits of info from the user message and returns them as arguments for my function. So far, so simple.
What I'm struggling to do (and this may not be possible) is to get it to perform well with multiple inputs.
Suppose my user message was this - a JSON-formatted array of user messages, and I wanted to extract the sentiment and categories for each one:
I'm struggling to sest up the
tools
> parameters
> properties
section such that it can report on each message in the input. I've tried something like:
Sometimes this sort of works and at other times it just gives nonsensical responses or breaks down. I've also tried asking it to give me an object of params per message, like so:
...but this rarely works out well. Is there a better way here?1 replies
CDCloudflare Developers
•Created by Mitya on 12/12/2024 in #general-help
Why isn't my cname showing up in DNS checkers?
5 replies
CDCloudflare Developers
•Created by Mitya on 7/25/2024 in #workers-help
Bug in Wrangler - it randomly adds [object Object] to console.log()'d string output
I think I've raised this before but didn't get anywhere.
There's a really weird bug in Wrangler (presumably) whereby, when you
console.log()
something, if it's over a certain lenght (unclear), Wrangler malforms it and swaps parts of it out for [object Object]
.
So you'll get something like:
Is a fix planned for this? It makes debugging quite difficult. The only way I've found to get round it is to do console.log(encodeURIComponent())
, which seems to avoid the problem.4 replies
CDCloudflare Developers
•Created by Mitya on 7/21/2024 in #workers-help
With function calls, are system messages or description properties preferable to instruct AI?
I realise that title is not super clear. Basically I've found that both of the following function calls produce the same result. One users a
type=system
message to instruct AI, while the other omits this and instead provides description
properties. If I do neither approach, I get erroneous/extra results from just the two bits asked for (fruit + vegetable). Which is preferable, according to how this functionality is designed?
Version 1 - with system message
Version 2: with description properties
Thank you in advance.4 replies
CDCloudflare Developers
•Created by Mitya on 7/20/2024 in #workers-help
AI embedded functions calls - how can my function influence the AI response?
I'm playing around with CF AI Functions and came up with this. The user message passed to AI hints at a fruit, AI infers the fruit as an orange, and sends "orange" to my function. So far, so good.
What I don't know is how to get my function to influence the response. As you can see, my function returns "**", which I thought might implicitly form the AI's response. It doesn't; AI responds in its own wording. Is what I'm trying to do possible?
1 replies
CDCloudflare Developers
•Created by Mitya on 6/21/2024 in #workers-help
Can I write a data URI to an R2 bucket?
Is it possible to write to an R2 bucket with a base64 data URI i.e.
? That fails (it creates a text file with literally that content), but perhaps there's a way to encode the file contents first such that R2 accepts it?
7 replies
CDCloudflare Developers
•Created by Mitya on 6/21/2024 in #workers-help
How to validate a file upload in Workers before saving it to R2?
I've spent ages trying to resolve this. I know how to upload a file and save it to R2. What I can't figure out is best practice to validate the file first.
Lots of resources out there say use something like Formiddable, but I can't believe I need a third-party library just to enforce things like "must be a PDF" or "must be under 100kb".
I know the Workers R2 API allows the stipulation of conditions on PUT operations, but these conditions don't seem to relate to the sort of conditions I mention above.
So what's best practice here?
11 replies
CDCloudflare Developers
•Created by Mitya on 6/17/2024 in #workers-help
All of a sudden Wrangler keeps opening a browser tab and asking for account access?
20 replies
CDCloudflare Developers
•Created by Mitya on 5/24/2024 in #workers-help
Deployment via GH Action sometimes gives error about NPX failing with "exit code 1"
3 replies
CDCloudflare Developers
•Created by Mitya on 5/8/2024 in #workers-help
Looking for a really simple explanation of durable objects vs. workers
One problem I repeatedly find with CF docs is that they're not very friendly and seem to assume a lot of knowledge already. I would love to see each product overview have an intro video or something that really explains what the thing is. The docs seem to jump straight into highly technical concepts.
With this in mind, what is the relationship between durable objects and workers? Right now I have a worker which powers a chatbot. Users talk to our system via a web interface and our system (i.e. the worker) responds.
I'm keen to learn more of the CF ecosystem and would like to see which parts of it might fit into our stack and improve it. Are durable objects their own thing, or are they used in conjunction with workers?
I know this is a very basic question, but I appreciate any help!
31 replies
CDCloudflare Developers
•Created by Mitya on 4/19/2024 in #workers-help
Getting `TypeError: fetch failed` errors
Another error I'm getting today. Again, I'm developing locally but with
--remote
. It happens randomly. Any thoughts?
2 replies
CDCloudflare Developers
•Created by Mitya on 4/19/2024 in #workers-help
Workers randomly throwing 502 "bad gateway" responses while developing locally with `--remote`
There are so many seemingly random errors thrown by workers while developing locally that the experience can be a drag (I've raised most of these in previous threads here.)
Today, I've started getting 502s every now and then. When this happens, I have no choice but to restart the Worker and then the exact same request succeeds.
In case it's relevant, I'm developing with the
--remote
flag for reasons that are outside this topic.
Nothing in my app throws this error explicitly or outputs HTML, so I assume this response is coming directly from CF.
Any thoughts here? Thank you.3 replies
CDCloudflare Developers
•Created by Mitya on 4/17/2024 in #workers-help
Strange issue with `console.log()` omitting members of objects
I'm using Itty Router with CF Workers. For some reason, when working locally and I run
console.log(req)
(in middleware, obviously) the vast majority of the members of that object are not shown.
For example, if I run:
...all I get logged is:
However, if I run:
...I get:
That's just one example of missing data. There's also a Headers
object that I know is there because I can call req.headers.get('my-header')
and it works.
Any thoughts as to what's going on here?6 replies
CDCloudflare Developers
•Created by Mitya on 3/25/2024 in #workers-help
GH secrets aren't coming through to my worker
Well, some are. But I added some new ones 4 hours ago and when I go to CF > Workers > my worker > settings > variables, the ones I added are not listed.
I'm definitely looking at the right branch/corresponding worker environment.
In GH > settings > secrets > actions, I can see all my secrets, including those I added today. If I go inspect
.github/workflows/wrangler-action.yml
I have added my secrets to those that were already there, i.e.
As I say, previous secrets have come through. Do I need to do something e.g. forcibly restart my worker somehow?3 replies
CDCloudflare Developers
•Created by Mitya on 3/5/2024 in #workers-help
How do you enable support for async local storage?
If I try to import
node:async_hooks
I get an error:
- My TOML has node_compat = true
- The ALS docs don't say anything about prerequisites to support ALS
- platform
is not a documented config property that I can see
- This page says I can enable ALS by adding compatibility_flags = [ "nodejs_als" ]
in the TOML but that raises the error _"No such compatibility flag: nodejsals"35 replies
CDCloudflare Developers
•Created by Mitya on 1/24/2024 in #workers-help
Confusing advice about secrets and Wrangler
From what I can tell, it does not make sense to put sensitive data in the TOML file because this would be committed.
CF acknowledges this by suggesting we use
.dev.vars
for local, and secrets for production.
However, when adding secrets (via the dashboard), CF then says it "recommend[s] updating your wrangler.toml file to keep your local development environment in sync."
So this advice seems to be contradictory.
A related issue is that, as far as I know, local DB connection strings for Hyperdrives must be specified in TOML, not .dev.vars
(the latter didn't work for me). So this necessitates having two TOML files - one production, one local - the local one being denoted via the --config
param, because putting the connection string in the main TOML would mean committing DB credentials.
Am I right in all the above, or can anyone clarify anything I'm missing?8 replies