#Postgres example cause Invalid Encoding error

1 messages · Page 1 of 1 (latest)

last roost
#

After updated to Bun 0.5.0, and using example code provided in the blog post cause an Invalid Encoding error cause from node:crypto

Code from: https://bun.sh/blog/bun-v0.5.0#sockets-using-node-tls-and-node-net

import postgres from "postgres";

const sql = postgres();
const [{ version }] = await sql`SELECT version()`;

console.log(version); // "PostgreSQL 14.2 ..."

At first I suspect that it might happens because connection error or unreachable or something, however I can use psql cli to connect to Postgres (as shown in 2nd picture)

To reproduce:
Using Docker to setup postgres:

docker run -p 5432:5432 -e POSTGRES_PASSWORD=12345678 -d postgres

Connect to postgres:

psql -h localhost -p 5432 -U postgres bun

Inside postgres cli, create database name bun:

CREATE DATABASE bun;
exit

Create file name index.ts with the following content:

import postgres from 'postgres'

const sql = postgres('postgres://postgres:12345678@localhost:5432/bun')

console.log(await sql`SELECT version();`)

Run the script and there should be a connection error.

This happens on both MacOS and WSL2 (Debian).

Tested machines:

MacOS:
Machine: Apple Silicon M1 Max
OS: MacOS Ventura 13.0.1
uname -a: Darwin Salt.local 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct 9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000 arm64

WSL:
Machine: AMD Ryzen 5 3500x
OS: Debian GNU/Linux 11 (Windows 11 WSL)
uname -a: Linux Chiffon 5.15.79.1-microsoft-standard-WSL2 #1 SMP Wed Nov 23 01:01:46 UTUC 2022 x86_64 GNU/Linux

Bun

Support for npm workspaces, DNS lookups, database drivers, and lots of improvements to bun install.

final dirge
#

oh no i thought i fixed this

#

alright i am confused

#

are you sure it's running in bun v0.5

last roost
#

I’m confidence it’s 0.5, I can run Redis and even reinstall Bun thrice on both machine

final dirge
#

figured it out

#

will push a patch release tonight

last roost
#

May I ask if the fix meant to be in 0.5.1 or after.
Just curious, if for later then please don't rush + no pressure on it, I'm ok to opt into canary anytime.

final dirge
#

in 0.5.1

#

Is it not?

last roost
#

I'm afraid not

#

Both on macOS and WSL2

final dirge
#

what version of postgres?

#

the npm package

#

also

#

can you go in that code in node_modules

#

and console.log

#

the inputEnc

last roost
#

Using postgres 3.3.3.
Also the weird thing is that there's no inputEnc in node_modules/postgres and there's only 1017 line while error is at line 1211.
Is this Bun generated code?

final dirge
#

oh

#

yeah

#

that code is in bun's crypto module