Trevor
Trevor
Explore posts from servers
EDSEthan's dev spot
Created by Trevor on 10/8/2023 in #questions
BETH stack tutorial non-blocking: `pushToTenantDb` returns exit code of 1
Per the title this bit of code is causing a small problem:
onExit(subprocess, exitCode, signalCode, error) {
console.log({ exitCode, error }, "hi from tenant index");
unlinkSync(tempConfigPath);
if (exitCode === 0) {
resolve(void 0);
} else {
console.error("Error pushing to tenant db");
reject(error);
}
},
onExit(subprocess, exitCode, signalCode, error) {
console.log({ exitCode, error }, "hi from tenant index");
unlinkSync(tempConfigPath);
if (exitCode === 0) {
resolve(void 0);
} else {
console.error("Error pushing to tenant db");
reject(error);
}
},
The exitCode evaluates to 1 and the error evaluates to undefined. The tenant db is successfully created in Turso and the unlinkSync I think is working as well, so I'm not sure what's causing the exit code. Here's the error:
/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:48441
[0] return new LibsqlError(e.message, code, e);
[0] ^
[0]
[0] LibsqlError: HRANA_WEBSOCKET_ERROR: Unexpected server response: 502
[0] at mapHranaError (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:48441:12)
[0] at #openStream (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:48575:17)
[0] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[0] at async HranaClient.execute (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:48474:29)
[0] at async TursoSqlite.query (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:42938:21)
[0] at async fromDatabase3 (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:12938:23)
[0] at async sqlitePushIntrospect (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:51949:19)
[0] at async Command.<anonymous> (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:53436:31) {
[0] code: 'HRANA_WEBSOCKET_ERROR',
[0] [cause]: WebSocketError: Unexpected server response: 502
[0] at #onSocketError (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:48099:25)
[0] at _WebSocket.<anonymous> (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:48022:78)
[0] at callListener (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:45693:18)
[0] at _WebSocket.onError (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:45647:13)
[0] at _WebSocket.emit (node:events:513:28)
[0] at emitErrorAndClose (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:46607:17)
[0] at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
[0] }
[0]
[0] Node.js v18.13.0
[0] {
[0] exitCode: 1,
[0] error: undefined
[0] } hi from tenant index
[0] 2023-10-08T21:46:22.499ZUTC | POST /api/organization - 500 (4891 ms)
[0] Error pushing to tenant db
[0] 109 |
[0] 110 | let er0 = handleErrors[0](
[0] 111 | Object.assign(c, {
[0] 112 | error: error,
[0] 113 |
[0] 114 | code: error.code ?? error[ERROR_CODE] ?? "UNKNOWN"
[0] ^
[0] TypeError: undefined is not an object (evaluating 'error.code')
[0] at processTicksAndRejections (:55:76)
[0] POST - http://localhost:3000/api/organization failed
[1] unlink src/db/tenant/drizzle.config.ts
/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:48441
[0] return new LibsqlError(e.message, code, e);
[0] ^
[0]
[0] LibsqlError: HRANA_WEBSOCKET_ERROR: Unexpected server response: 502
[0] at mapHranaError (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:48441:12)
[0] at #openStream (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:48575:17)
[0] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[0] at async HranaClient.execute (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:48474:29)
[0] at async TursoSqlite.query (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:42938:21)
[0] at async fromDatabase3 (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:12938:23)
[0] at async sqlitePushIntrospect (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:51949:19)
[0] at async Command.<anonymous> (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:53436:31) {
[0] code: 'HRANA_WEBSOCKET_ERROR',
[0] [cause]: WebSocketError: Unexpected server response: 502
[0] at #onSocketError (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:48099:25)
[0] at _WebSocket.<anonymous> (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:48022:78)
[0] at callListener (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:45693:18)
[0] at _WebSocket.onError (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:45647:13)
[0] at _WebSocket.emit (node:events:513:28)
[0] at emitErrorAndClose (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/drizzle-kit/index.cjs:46607:17)
[0] at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
[0] }
[0]
[0] Node.js v18.13.0
[0] {
[0] exitCode: 1,
[0] error: undefined
[0] } hi from tenant index
[0] 2023-10-08T21:46:22.499ZUTC | POST /api/organization - 500 (4891 ms)
[0] Error pushing to tenant db
[0] 109 |
[0] 110 | let er0 = handleErrors[0](
[0] 111 | Object.assign(c, {
[0] 112 | error: error,
[0] 113 |
[0] 114 | code: error.code ?? error[ERROR_CODE] ?? "UNKNOWN"
[0] ^
[0] TypeError: undefined is not an object (evaluating 'error.code')
[0] at processTicksAndRejections (:55:76)
[0] POST - http://localhost:3000/api/organization failed
[1] unlink src/db/tenant/drizzle.config.ts
Noticing that that tenant db is indeed successfully getting pushed to Turso I wrapped the call to this function in the organization controller with a try catch and just logged out the error.
try {
await pushToTenantDb({
dbName: Name,
authToken: jwt,
});
} catch (e) {
console.log(e);
}
try {
await pushToTenantDb({
dbName: Name,
authToken: jwt,
});
} catch (e) {
console.log(e);
}
I still log the errors, but this pushes the tenant db to Turso and adds the record to the organization table. It also updates the user table as it should.
30 replies
EDSEthan's dev spot
Created by Trevor on 9/29/2023 in #questions
BETH stack tutorial blocked "Sync is not supported in databases opened in file mode."
After creating a Turso db and adding the needed .env variables running bun dev results in the follwing error.
$ concurrently "bun run --hot src/main.ts" "bun run uno:dev" "bun run liveReload"
[1] $ bunx --bun unocss --watch
[2] $ bunx beth-stack
[2] 🦊 Livereload running localhost:3001
[0] 73 | },
[0] 74 | });
[0] 75 | }
[0] 76 |
[0] 77 | sync() {
[0] 78 | databaseSyncSync.call(this.db);
[0] ^
[0] error: Sync is not supported in databases opened in file mode.
[0] at sync (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/libsql/index.js:78:4)
[0] at /Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/@libsql/client/lib-esm/sqlite3.js:93:14
[0] at sync (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/@libsql/client/lib-esm/sqlite3.js:91:17)
[0] at /Users/trevorfehrman/Documents/Code/Personal/beth-app/src/db/index.ts:23:6
at processTicksAndRejections (:55:76)
[0] 73 | },
[0] 74 | });
[0] 75 | }
[0] 76 |
[0] 77 | sync() {
[0] 78 | databaseSyncSync.call(this.db);
[0] ^
[0] error: Sync is not supported in databases opened in file mode.
[0] at sync (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/libsql/index.js:78:4)
[0] at /Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/@libsql/client/lib-esm/sqlite3.js:93:14
[0] at sync (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/@libsql/client/lib-esm/sqlite3.js:91:17)
[0] at /Users/trevorfehrman/Documents/Code/Personal/beth-app/src/db/index.ts:23:6
[0] at processTicksAndRejections (:55:76)
[1] unocss v0.55.7
[1] ◐ UnoCSS in watch mode...
[1] ℹ Watching for changes in src/**/*.{ts,tsx}
$ concurrently "bun run --hot src/main.ts" "bun run uno:dev" "bun run liveReload"
[1] $ bunx --bun unocss --watch
[2] $ bunx beth-stack
[2] 🦊 Livereload running localhost:3001
[0] 73 | },
[0] 74 | });
[0] 75 | }
[0] 76 |
[0] 77 | sync() {
[0] 78 | databaseSyncSync.call(this.db);
[0] ^
[0] error: Sync is not supported in databases opened in file mode.
[0] at sync (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/libsql/index.js:78:4)
[0] at /Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/@libsql/client/lib-esm/sqlite3.js:93:14
[0] at sync (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/@libsql/client/lib-esm/sqlite3.js:91:17)
[0] at /Users/trevorfehrman/Documents/Code/Personal/beth-app/src/db/index.ts:23:6
at processTicksAndRejections (:55:76)
[0] 73 | },
[0] 74 | });
[0] 75 | }
[0] 76 |
[0] 77 | sync() {
[0] 78 | databaseSyncSync.call(this.db);
[0] ^
[0] error: Sync is not supported in databases opened in file mode.
[0] at sync (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/libsql/index.js:78:4)
[0] at /Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/@libsql/client/lib-esm/sqlite3.js:93:14
[0] at sync (/Users/trevorfehrman/Documents/Code/Personal/beth-app/node_modules/@libsql/client/lib-esm/sqlite3.js:91:17)
[0] at /Users/trevorfehrman/Documents/Code/Personal/beth-app/src/db/index.ts:23:6
[0] at processTicksAndRejections (:55:76)
[1] unocss v0.55.7
[1] ◐ UnoCSS in watch mode...
[1] ℹ Watching for changes in src/**/*.{ts,tsx}
Nothing is getting served to localhost:3000 but a GET request to localhost:3001 returns a 404 not found <:honk_thonk:753870955234721821> I guess I have 2 questions: 1. Why is this command spinning something up on 3001? I've ensured there's nothing running on 3000. 2. It seems like the problem is in the libsql package within node modules. Not sure if this is related to issue I was having with Bun installing the wrong version of esbuild for my CPU architecture or if that's a coincidence. Once again, appreciate any thoughts anyone might have. Thanks!
45 replies
EDSEthan's dev spot
Created by Trevor on 9/28/2023 in #questions
BETH stack tutorial blocked with esbuild and rendering
No description
11 replies
TTCTheo's Typesafe Cult
Created by Trevor on 7/2/2023 in #questions
env-nextjs not able to find .env variables
At least I think that's what's going on. Here's what I have in env.ts
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const env = createEnv({
server: {
CLERK_SECRET_KEY: z.string(),
PLANETSCALE_DB: z.string(),
PLANETSCALE_DB_CERT_PATH: z.string(),
PLANETSCALE_DB_HOST: z.string(),
PLANETSCALE_DB_USERNAME: z.string(),
PLANETSCALE_DB_PASSWORD: z.string(),
PLANETSCALE_DB_URL: z.string(),
},
client: {
NEXT_PUBLIC_CLERK_SIGN_IN_URL: z.string(),
NEXT_PUBLIC_CLERK_SIGN_UP_URL: z.string(),
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: z.string(),
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string(),
},
// For Next.js >= 13.4.4, you only need to destructure client variables:
experimental__runtimeEnv: {
NEXT_PUBLIC_CLERK_SIGN_IN_URL: process.env.NEXT_PUBLIC_CLERK_SIGN_IN_URL,
NEXT_PUBLIC_CLERK_SIGN_UP_URL: process.env.NEXT_PUBLIC_CLERK_SIGN_UP_URL,
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: process.env.NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_PUBLISHABLE_KEY,
},
});
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const env = createEnv({
server: {
CLERK_SECRET_KEY: z.string(),
PLANETSCALE_DB: z.string(),
PLANETSCALE_DB_CERT_PATH: z.string(),
PLANETSCALE_DB_HOST: z.string(),
PLANETSCALE_DB_USERNAME: z.string(),
PLANETSCALE_DB_PASSWORD: z.string(),
PLANETSCALE_DB_URL: z.string(),
},
client: {
NEXT_PUBLIC_CLERK_SIGN_IN_URL: z.string(),
NEXT_PUBLIC_CLERK_SIGN_UP_URL: z.string(),
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: z.string(),
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string(),
},
// For Next.js >= 13.4.4, you only need to destructure client variables:
experimental__runtimeEnv: {
NEXT_PUBLIC_CLERK_SIGN_IN_URL: process.env.NEXT_PUBLIC_CLERK_SIGN_IN_URL,
NEXT_PUBLIC_CLERK_SIGN_UP_URL: process.env.NEXT_PUBLIC_CLERK_SIGN_UP_URL,
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: process.env.NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_PUBLISHABLE_KEY,
},
});
When I try to run a command that uses one of these variables (drizzle-kit push:mysql) the Zod parse fails and gives me this in the terminal:
❌ Invalid environment variables: {
CLERK_SECRET_KEY: [ 'Required' ],
PLANETSCALE_DB: [ 'Required' ],
PLANETSCALE_DB_CERT_PATH: [ 'Required' ],
PLANETSCALE_DB_HOST: [ 'Required' ],
PLANETSCALE_DB_USERNAME: [ 'Required' ],
PLANETSCALE_DB_PASSWORD: [ 'Required' ],
PLANETSCALE_DB_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_UP_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_PUBLISHABLE_KEY: [ 'Required' ]
}
❌ Invalid environment variables: {
CLERK_SECRET_KEY: [ 'Required' ],
PLANETSCALE_DB: [ 'Required' ],
PLANETSCALE_DB_CERT_PATH: [ 'Required' ],
PLANETSCALE_DB_HOST: [ 'Required' ],
PLANETSCALE_DB_USERNAME: [ 'Required' ],
PLANETSCALE_DB_PASSWORD: [ 'Required' ],
PLANETSCALE_DB_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_UP_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_PUBLISHABLE_KEY: [ 'Required' ]
}
My env variables are defined at the root of the same directory env.ts is in, .env.local I think this is saying it can't find them? Any help would be appreciated, I'm sure I'm missing something simple <:honk_thonk:753870955234721821>
49 replies