Skip to content

Commit

Permalink
Fix error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiSherman committed Nov 22, 2024
1 parent 6479912 commit 99b1317
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
8 changes: 6 additions & 2 deletions drizzle-seed/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ const seedFunc = async (

await seedSqlite(db, sqliteSchema, options, refinements);
} else {
throw new Error('given db is not supported.');
throw new Error(
'The drizzle-seed package currently supports only PostgreSQL, MySQL, and SQLite databases. Please ensure your database is one of these supported types',
);
}

return;
Expand Down Expand Up @@ -434,7 +436,9 @@ export async function reset<
await resetSqlite(db, sqliteSchema);
}
} else {
throw new Error('given db is not supported.');
throw new Error(
'The drizzle-seed package currently supports only PostgreSQL, MySQL, and SQLite databases. Please ensure your database is one of these supported types',
);
}
}

Expand Down
12 changes: 6 additions & 6 deletions drizzle-seed/src/services/GeneratorsWrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ export class GenerateValuesFromArray extends AbstractGenerator<
const { values } = this.params;
const { maxRepeatedValuesCount, notNull, isUnique } = this;
if (values.length === 0) {
throw new Error('values length equals zero.');
throw new Error('Values length equals zero.');
}

if (
typeof values[0] === 'object'
&& !(values as { weight: number; values: any[] }[]).every((val) => val.values.length !== 0)
) {
throw new Error('one of weighted values length equals zero.');
throw new Error('One of weighted values length equals zero.');
}

if (
Expand Down Expand Up @@ -169,7 +169,7 @@ export class GenerateValuesFromArray extends AbstractGenerator<
&& maxRepeatedValuesCount * allValuesCount < count)
)
) {
throw new Error("(maxRepeatedValuesCount * values.length) < count. can't fill notNull column with null values.");
throw new Error("Can't fill notNull column with null values.");
}

if (
Expand All @@ -183,7 +183,7 @@ export class GenerateValuesFromArray extends AbstractGenerator<
))
)
) {
throw new Error("maxRepeatedValuesCount can't be greater than 1 if column is unique.");
throw new Error("Can't be greater than 1 if column is unique.");
}

if (
Expand All @@ -193,14 +193,14 @@ export class GenerateValuesFromArray extends AbstractGenerator<
)
) {
// console.log(maxRepeatedValuesCount, values.length, allValuesCount, count)
throw new Error('there are no enough values to fill unique column.');
throw new Error('There are no enough values to fill unique column.');
}
}

init({ count, seed }: { count: number; seed: number }) {
if (this.params.isUnique !== undefined) {
if (this.params.isUnique === false && this.isUnique === true) {
throw new Error('specifying non unique generator to unique column.');
throw new Error('Specifying non unique generator to unique column.');
}

this.isUnique = this.params.isUnique;
Expand Down
4 changes: 3 additions & 1 deletion drizzle-seed/src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const sumArray = (weights: number[]) => {
export const getWeightedIndices = (weights: number[], accuracy = 100) => {
const weightsSum = sumArray(weights);
if (weightsSum !== 1) {
throw new Error(`sum of all weights don't equal to 1; ${weightsSum} !== 1`);
throw new Error(
`The weights for the Weighted Random feature must add up to exactly 1. Please review your weights to ensure they total 1 before proceeding`,
);
}

// const accuracy = 100;
Expand Down
8 changes: 5 additions & 3 deletions drizzle-seed/src/tests/pg/generatorsTest/generators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ test('valuesFromArray unique generator test', async () => {
},
},
})),
).rejects.toThrow('there are no enough values to fill unique column.');
).rejects.toThrow('There are no enough values to fill unique column.');

await expect(
seed(db, { valuesFromArrayUniqueTable: schema.valuesFromArrayUniqueTable }, { seed: 1 }).refine((funcs) => ({
Expand All @@ -552,7 +552,7 @@ test('valuesFromArray unique generator test', async () => {
},
},
})),
).rejects.toThrow('there are no enough values to fill unique column.');
).rejects.toThrow('There are no enough values to fill unique column.');
});

test('intPrimaryKey generator test', async () => {
Expand Down Expand Up @@ -1368,5 +1368,7 @@ test('weightedRandom with unique gens generator test', async () => {
},
},
})),
).rejects.toThrow("sum of all weights don't equal to 1; 1.1 !== 1");
).rejects.toThrow(
'The weights for the Weighted Random feature must add up to exactly 1. Please review your weights to ensure they total 1 before proceeding',
);
});

0 comments on commit 99b1317

Please sign in to comment.