schemix icon indicating copy to clipboard operation
schemix copied to clipboard

RangeError: Invalid array length

Open zygopleural opened this issue 1 year ago • 4 comments

Node version: 18.17.0 Schemix version: 1.14.0

Getting this error on a fresh install

node_modules/schemix/dist/modules/PrismaModel.js:204
        var paddings = Array(mostTokens).fill(0);
                       ^

RangeError: Invalid array length
    at PrismaModel.parseFields (node_modules/schemix/dist/modules/PrismaModel.js:204:24)
    at Immediate.<anonymous> (node_modules/schemix/dist/modules/PrismaModel.js:163:27)
    at process.processImmediate (node:internal/timers:476:21)

zygopleural avatar Sep 11 '23 11:09 zygopleural

This is also happening to me occasionally. Rerunning the script a few times gets the error to go away somehow

brianferri avatar Mar 19 '24 10:03 brianferri

@zygopleural I've written a small script to take care of it until it gets looked into:

#!/bin/bash
# {PROJECT}/prisma/prisma.build
EXECUTOR=bun
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

ok() { # Print a green [OK]
    local string="$1"
    echo -e "\033[1;32m[OK]\033[0m $string"
}

info() { # Print a cyan [INFO]
    local string="$1"
    echo -e "\033[1;36m[INFO]\033[0m $string"
}

prepend() {
    local string="$1"
    local file="$2"
    printf '%s\n%s' "$string" "$(cat $file)" >$file
}

info "Building prisma schema..."

# Sometimes the script fails inexplicably, so we try until it works
while ! $EXECUTOR $DIR/builder.ts 2> /dev/null; do
    sleep 0.1
done

prepend "// DO NOT MODIFY THIS FILE MANUALLY
// This file was autogenerated by schemix in \`./${DIR##*/}/builder.ts\`.
// Use the TS scripts in \`./${DIR##*/}/models/\` to modify the schema
// run \`$EXECUTOR db:generate\` to rebuild the schema
" "${DIR}/schema.prisma"

ok "Prisma schema built successfully"

my predb:generate does chmod +x ./prisma/prisma.build && ./prisma/prisma.build ~~db:generate just runs prisma generate with some private utils, change according to your needs~~

which calls:

// {PROJECT}/prisma/builder.ts
import { createSchema } from 'schemix';

createSchema({
    basePath: __dirname,
    datasource: {
        provider: 'postgresql',
        url: { env: 'DATABASE_URL' }
    },
    generator: {
        provider: 'prisma-client-js'
    }
}).export(__dirname, 'schema');

until it goes through

brianferri avatar Mar 19 '24 14:03 brianferri

Very interesting, could be a race condition. Once I have the time, I'll take a look!

ridafkih avatar Mar 20 '24 02:03 ridafkih

+1 Happens about 10-20% of the time for me

andreasbroch2 avatar May 31 '24 08:05 andreasbroch2