-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conflict error for compound indexes is not correct #258
Comments
Since everybody has a different idea what "useful" means, most adapters don't customize database error messages. The best way to customize errors to your needs is by using Feathers error hooks. |
It is incorrect, it should say |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Apologies if the issue could not be resolved. FeathersJS ecosystem modules are community maintained so there may be a chance that there isn't anybody available to address the issue at the moment. For other ways to get help see here. |
Reminder to self to have a stab at a PR for this. Unless @daffl you really believe this is not an issue and the error message is correct (in which case, could you explain to me how I'm misreading it?) |
No, that's fair. Is that a problem in the conflict error handler part (https://github.com/feathersjs-ecosystem/feathers-mongoose/blob/master/lib/error-handler.js#L4)? |
Yes, I believe there's something wrong or incomplete with the regex there. |
@daffl I don't think it's possible to format the error message easily with simple regex. I have written an implementation of how to solve this particular bug that I describe in this issue, but it would not work for compound indexes with more than 2 fields and I believe my implementation would also fail in cases where the fields names contain both underscores and digits (e.g. You can have a look at it here https://github.com/cdimitroulas/feathers-mongoose/pull/1 In order to solve this properly, I think we would need to query for the index information (this is the approach that the |
Might make sense to make the Regex only apply to the simple case that it actually covers then. Parsing the error message probably wasn't a good idea to begin with (strangely it is what Mongoose appears to recommend in the issues related to that) but I don't want to make another breaking change for something that might make things less user friendly. |
OK, that makes sense. My only other suggestion would be to make the original error message from MongoDB available (maybe a property like |
@daffl ^ what do you think of my proposed idea? |
We probably could do the same thing the new Sequelize adapter is doing and add a hidden property with the original error (https://github.com/feathersjs-ecosystem/feathers-sequelize#migrating). |
It basically just adds the original error in a Symbol error property (see https://github.com/feathersjs-ecosystem/feathers-sequelize/blob/master/lib/utils.js) so it can be accessed and used in the server-side error handler. |
Steps to reproduce
firstId
andsecondId
field values and inspect the error message returned from mongoose. It will look something like this:firstId: ObjectId(\'5b891cf30d74a9432c0ee036\'), : ObjectId(\'587775b068194a6b3c818dce\') already exists.
Expected behavior
Feathers mongoose should handle a 1100 or 11001 MongoDB error and display a useful error message for the user of the library
Actual behavior
This works fine for regular indexes, but when there is a compound index the error message is rather
obscure.
System configuration
Tell us about the applicable parts of your setup.
Module versions (especially the part that's not working):
feathers-mongoose
: 6.1.2mongoose
: 4.13.14NodeJS version: 8.11.2
Operating System: Ubuntu 16.04
The text was updated successfully, but these errors were encountered: