Mitya
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
CDCloudflare Developers
•Created by Mitya on 1/22/2024 in #workers-help
"CODE_MOVED for unknown code block" bug?
16 replies
CDCloudflare Developers
•Created by Mitya on 1/19/2024 in #pages-help
Pointing subdomain (of non-CF domain) to pages site gives SSL error
11 replies
CDCloudflare Developers
•Created by Mitya on 1/17/2024 in #workers-help
Does anyone have a working example of evaluating JavaScript via WASM?
(This is a spin-off from this thread, which ultimately asks a different question and has become quite lengthy.)
I need to evaluate some JavaScript, but understand that
eval()
/ new Function()
is blocked on workers. I understand my only route to evalulation is via WASM.
But I'm struggling to implement a working example of JS evaluation via WASM in Workers. I'm completely new to WASM and am focusing on packages that do the heavy lifting for you. Here's what I've tried, using quickjs-emscripten:
This throws no error but simply never gets into the callback.
I've also tried wasm-jseval, via:
But this errors - it seems the package seems to think I'm working in the browser, as the error pertains to it trying to access location.href
.
So does anyone have a working cut-and-paste version of evaluating JS via a package like this I could use?
I'd be most grateful!3 replies
CDCloudflare Developers
•Created by Mitya on 1/16/2024 in #workers-help
How can I enable support for `eval()` in Workers?
Yes yes I know all the caveats about
eval()
but it's essential for my use-case. When running in dev mode (but with --remote
i.e. running on CF architecture) I get:
I've read this but didn't fully understand what to action from it. Could someone please advise? Thank you!50 replies
CDCloudflare Developers
•Created by Mitya on 1/12/2024 in #workers-help
Occasional "error on remote worker" errors
1 replies
CDCloudflare Developers
•Created by Mitya on 1/8/2024 in #workers-help
DB sometimes returns rows, sometimes returns nothing
I wanted to raise this formally although I've been discussing it in #hyperdrive-beta , as I'm not sure where in the CF stack the issue lies.
Basically a single query in my app, among hundreds, sometimes returns rows and sometimes returns this:
All other queries work fine, as I say. So I'm sat here refreshing and endpoint and sometimes seeing data and sometimes not (with no code changes).
This is happening while running my app locally (with
--remote
) so HD is being used. So I assume this is a HD issue, though perhaps it's at a Workers/Wrangler level for all I know. I could disable HD caching, but then that presumably defeats the point of HD?
Any help is greatly appreciated as this is blocking me at the mo! Thanks in advance.5 replies