Skip to content
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

Hotfix/key thrown #110

Merged
merged 8 commits into from
Jul 22, 2019
Merged

Hotfix/key thrown #110

merged 8 commits into from
Jul 22, 2019

Conversation

Shahar-Y
Copy link
Contributor

Changed the way duplicate key errors are treated, using regex. Now the errors are more precise.
Fixed the option of the error showing undefined (#90)
Manually tested with docker, it works.
Closes #90, #107

@Shahar-Y Shahar-Y added the bug Something isn't working label Jul 21, 2019
@Shahar-Y Shahar-Y self-assigned this Jul 21, 2019
@Shahar-Y Shahar-Y changed the base branch from master to develop July 21, 2019 11:48
Copy link
Collaborator

@omerzamir omerzamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does all this lines doing?????????????????????????????????????????
WTF is this?

} else {
next();
}
};

function getMongoErrorIndices(error: MongoError) : string {
const indicesRegex : RegExp = new RegExp(/index\:\ (?:.*\.)?\$?(?:([_a-z0-9]*)(?:_\d*)|([_a-z0-9]*))\s*dup key/i);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WTF is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added documentation

const indicesMatch : RegExpMatchArray = error.message.match(indicesRegex);
let indexName : string = indicesMatch[1] || indicesMatch[2];

const re : RegExp = new RegExp('_1_', 'g');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WTF is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added documentation

const re : RegExp = new RegExp('_1_', 'g');
indexName = indexName.replace(re, ', ');

const valuesRE : RegExp = new RegExp(/{(.*?)}/);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WTF is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added documentation

const valuesRE : RegExp = new RegExp(/{(.*?)}/);
const valuesMatch : RegExpMatchArray = error.message.match(valuesRE);
let values : string = valuesMatch[0];
values = values.replace(new RegExp(' : ', 'g'), ' ');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WTF is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added documentation

Signed-off-by: shahar-Y <[email protected]>
@Shahar-Y
Copy link
Contributor Author

The regex is taken from this mongoose issue: Automattic/mongoose#2129
Checked it both with a single index an multiple indices

if (error.name === 'MongoError' && error.code === 11000) {
next(new KeyAlreadyExistsError(this.key));
const retMessage : string = getMongoErrorIndices(error);
next(new KeyAlreadyExistsError(retMessage));
Copy link
Contributor

@yonatandt yonatandt Jul 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should create a different error for cases where the compound indexes already exist. We can accidentally confuse it with the key field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to 'UniqueIndexExistsError'

await FileService.create(bucket, 'tmp1', USER.id, 'text', null, KEY);
await FileService.create(bucket, 'tmp2', USER.id, 'text', null, KEY)
.should.eventually.be.rejectedWith(KeyAlreadyExistsError);
});

});

describe('#updateById', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does updateById tests related to this issue/hotfix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created tests that were missing and are related to this issue

omerzamir
omerzamir previously approved these changes Jul 22, 2019
Copy link
Collaborator

@omerzamir omerzamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shahar doesn't know what is code is doing, my comments are not accepted. I wont review this code, do whatever you like.

@Shahar-Y Shahar-Y merged commit 77e7485 into develop Jul 22, 2019
@Shahar-Y Shahar-Y deleted the hotfix/key-thrown branch July 22, 2019 10:42
@meateam meateam locked as resolved and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants