Skip to content

Commit b45f433

Browse files
Copilothotlong
andcommitted
Improve error messages with concrete examples and valid options
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 150617a commit b45f433

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

packages/drivers/mongo/src/index.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ export class MongoDriver implements Driver, DriverInterface {
552552
};
553553

554554
default:
555-
throw new Error(`Unknown command type: ${(command as any).type}`);
555+
const validTypes = ['create', 'update', 'delete', 'bulkCreate', 'bulkUpdate', 'bulkDelete'];
556+
throw new Error(`Unknown command type: ${(command as any).type}. Valid types are: ${validTypes.join(', ')}`);
556557
}
557558
} catch (error: any) {
558559
return {
@@ -599,8 +600,13 @@ export class MongoDriver implements Driver, DriverInterface {
599600
case 'not':
600601
// NOT is not directly supported in the legacy filter format
601602
// MongoDB supports $not, but legacy array format doesn't have a NOT operator
602-
// We'll throw an error to indicate this limitation
603-
throw new Error('NOT filters are not supported in legacy filter format. Use native MongoDB queries with $not operator instead.');
603+
// Use native MongoDB queries with $not instead:
604+
// Example: { field: { $not: { $eq: value } } }
605+
throw new Error(
606+
'NOT filters are not supported in legacy filter format. ' +
607+
'Use native MongoDB queries with $not operator instead. ' +
608+
'Example: { field: { $not: { $eq: value } } }'
609+
);
604610

605611
default:
606612
return undefined;
@@ -616,8 +622,13 @@ export class MongoDriver implements Driver, DriverInterface {
616622
*/
617623
async execute(command: any, parameters?: any[], options?: any): Promise<any> {
618624
// MongoDB driver doesn't support raw command execution in the traditional SQL sense
619-
// This method is here for DriverInterface compatibility
620-
throw new Error('MongoDB driver does not support raw command execution. Use executeCommand() instead.');
625+
// Use executeCommand() instead for mutations (create/update/delete)
626+
// Example: await driver.executeCommand({ type: 'create', object: 'users', data: {...} })
627+
throw new Error(
628+
'MongoDB driver does not support raw command execution. ' +
629+
'Use executeCommand() for mutations or aggregate() for complex queries. ' +
630+
'Example: driver.executeCommand({ type: "create", object: "users", data: {...} })'
631+
);
621632
}
622633
}
623634

0 commit comments

Comments
 (0)