-
Notifications
You must be signed in to change notification settings - Fork 1
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
Hotfix/key thrown #110
Conversation
Signed-off-by: shahar-Y <[email protected]>
Signed-off-by: shahar-Y <[email protected]>
…ate #107 Signed-off-by: shahar-Y <[email protected]>
Signed-off-by: shahar-Y <[email protected]>
There was a problem hiding this 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?
src/file/file.model.ts
Outdated
} else { | ||
next(); | ||
} | ||
}; | ||
|
||
function getMongoErrorIndices(error: MongoError) : string { | ||
const indicesRegex : RegExp = new RegExp(/index\:\ (?:.*\.)?\$?(?:([_a-z0-9]*)(?:_\d*)|([_a-z0-9]*))\s*dup key/i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WTF is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added documentation
src/file/file.model.ts
Outdated
const indicesMatch : RegExpMatchArray = error.message.match(indicesRegex); | ||
let indexName : string = indicesMatch[1] || indicesMatch[2]; | ||
|
||
const re : RegExp = new RegExp('_1_', 'g'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WTF is this?
There was a problem hiding this comment.
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(/{(.*?)}/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WTF is this?
There was a problem hiding this comment.
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'), ' '); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WTF is this?
There was a problem hiding this comment.
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]>
The regex is taken from this mongoose issue: Automattic/mongoose#2129 |
src/file/file.model.ts
Outdated
if (error.name === 'MongoError' && error.code === 11000) { | ||
next(new KeyAlreadyExistsError(this.key)); | ||
const retMessage : string = getMongoErrorIndices(error); | ||
next(new KeyAlreadyExistsError(retMessage)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Signed-off-by: shahar-Y <[email protected]>
There was a problem hiding this 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.
Signed-off-by: shahar-Y <[email protected]>
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