Skip to content

Commit

Permalink
feat: added error prefix to avoid mixing with prisma errors
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Jun 20, 2023
1 parent 634ce67 commit 177a4f0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/handler/model-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function handleModelPayload(
const type = typeAlias.type as ts.TypeLiteralNode;

if (type.kind !== ts.SyntaxKind.TypeLiteral) {
throw new Error(`Provided object is not a type literal: ${type.getText()}`);
throw new Error(`prisma-json-types-generator: Provided object is not a type literal: ${type.getText()}`);
}

const scalarsField = type.members.find((m) => m.name?.getText() === 'scalars');
Expand All @@ -28,7 +28,7 @@ export async function handleModelPayload(
?.typeArguments?.[0] as ts.TypeLiteralNode;

if (!object) {
throw new Error(`Payload scalars could not be resolved: ${type.getText()}`);
throw new Error(`prisma-json-types-generator: Payload scalars could not be resolved: ${type.getText()}`);
}

replaceObject(model, object, nsName, replacer, typeAlias.name.getText(), useType);
Expand Down
4 changes: 2 additions & 2 deletions src/handler/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ export async function handleModule(
}

if (!signature.type) {
throw new Error(`No type found for field ${fieldName} at model ${typeAliasName}`);
throw new Error(`prisma-json-types-generator: No type found for field ${fieldName} at model ${typeAliasName}`);
}

const typename = field.documentation?.match(JSON_REGEX)?.[1];

if (!typename) {
throw new Error(
`No typename found for field ${fieldName} at model ${typeAliasName}`
`prisma-json-types-generator: No typename found for field ${fieldName} at model ${typeAliasName}`
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/handler/type-alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function handleTypeAlias(
return;
}

throw new Error(`Provided object is not a type literal: ${object.getText()}`);
throw new Error(`prisma-json-types-generator: Provided object is not a type literal: ${object.getText()}`);
}

replaceObject(model, object, nsName, replacer, typeAlias.name.getText(), useType);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/replace-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function replaceObject(
const signatureType = (member as ts.PropertySignature).type;

if (!typename || !signatureType) {
throw new Error(`Could not find typename or signature type for ${field.name}`);
throw new Error(`prisma-json-types-generator: Could not find typename or signature type for ${field.name}`);
}

replaceSignature(
Expand Down
4 changes: 2 additions & 2 deletions src/on-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export async function onGenerate(options: GeneratorOptions) {

if (!prismaClientOptions) {
throw new Error(
'Could not find client generator options, are you using prisma-client-js before prisma-json-types-generator?'
'prisma-json-types-generator: Could not find client generator options, are you using prisma-client-js before prisma-json-types-generator?'
);
}

if (!prismaClientOptions.output?.value) {
throw new Error(
'prisma client output not found: ' + JSON.stringify(prismaClientOptions, null, 2)
'prisma-json-types-generator: prisma client output not found: ' + JSON.stringify(prismaClientOptions, null, 2)
);
}

Expand Down

0 comments on commit 177a4f0

Please sign in to comment.