mirror of
https://github.com/status-im/sourcecred.git
synced 2025-02-27 19:50:28 +00:00
mirror: add default typename-mismatch error message (#1610)
Summary: Previously, `_nontransactionallyRegisterObject` differed from its counterpart `registerObject` in two ways: the former does not enter a transaction, but it also requires a function to format an error message. The value provided by `registerObject` to the helper is a suitable default, so we can use it to decouple the transaction semantics from the error message. Test Plan: Existing tests suffice, retaining full coverage. wchargin-branch: mirror-default-typename-message
This commit is contained in:
parent
9539a18a67
commit
ba9cc43a39
@ -365,14 +365,7 @@ export class Mirror {
|
|||||||
+id: Schema.ObjectId,
|
+id: Schema.ObjectId,
|
||||||
|}): void {
|
|}): void {
|
||||||
_inTransaction(this._db, () => {
|
_inTransaction(this._db, () => {
|
||||||
this._nontransactionallyRegisterObject(object, (guess) => {
|
this._nontransactionallyRegisterObject(object);
|
||||||
const s = JSON.stringify;
|
|
||||||
const message =
|
|
||||||
`object ${s(object.id)} ` +
|
|
||||||
`looks like it should have type ${s(guess)}, ` +
|
|
||||||
`not ${s(object.typename)}`;
|
|
||||||
return message;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,11 +379,22 @@ export class Mirror {
|
|||||||
+typename: Schema.Typename,
|
+typename: Schema.Typename,
|
||||||
+id: Schema.ObjectId,
|
+id: Schema.ObjectId,
|
||||||
|},
|
|},
|
||||||
guessMismatchMessage: (guess: Schema.Typename) => string
|
guessMismatchMessage?: (guess: Schema.Typename) => string
|
||||||
): void {
|
): void {
|
||||||
const db = this._db;
|
const db = this._db;
|
||||||
const {typename, id} = object;
|
const {typename, id} = object;
|
||||||
|
|
||||||
|
if (guessMismatchMessage == null) {
|
||||||
|
guessMismatchMessage = (guess) => {
|
||||||
|
const s = JSON.stringify;
|
||||||
|
const message =
|
||||||
|
`object ${s(object.id)} ` +
|
||||||
|
`looks like it should have type ${s(guess)}, ` +
|
||||||
|
`not ${s(object.typename)}`;
|
||||||
|
return message;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const existingTypename = db
|
const existingTypename = db
|
||||||
.prepare("SELECT typename FROM objects WHERE id = ?")
|
.prepare("SELECT typename FROM objects WHERE id = ?")
|
||||||
.pluck()
|
.pluck()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user