Skip to content

Commit

Permalink
fix(mssql): match aggregate errors (#14784)
Browse files Browse the repository at this point in the history
* fix(mssql): match aggregate errors

* fix(mssql): wrap for loops in if statements

Co-authored-by: Sascha Depold <sdepold@users.noreply.github.com>
  • Loading branch information
WikiRik and sdepold committed Aug 8, 2022
1 parent 088a3fe commit 00c1019
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/dialects/mssql/query.js
Expand Up @@ -351,6 +351,20 @@ export class MsSqlQuery extends AbstractQuery {
});
}

if (err.errors) {
for (const error of err.errors) {
match = error.message.match(/Could not create constraint or index. See previous errors./);
if (match && match.length > 0) {
return new sequelizeErrors.ForeignKeyConstraintError({
fields: null,
index: match[1],
cause: error,
stack: errStack,
});
}
}
}

match = err.message.match(/Could not drop constraint. See previous errors./);
if (match && match.length > 0) {
let constraint = err.sql.match(/(?:constraint|index) \[(.+?)]/i);
Expand All @@ -367,6 +381,26 @@ export class MsSqlQuery extends AbstractQuery {
});
}

if (err.errors) {
for (const error of err.errors) {
match = error.message.match(/Could not drop constraint. See previous errors./);
if (match && match.length > 0) {
let constraint = err.sql.match(/(?:constraint|index) \[(.+?)]/i);
constraint = constraint ? constraint[1] : undefined;
let table = err.sql.match(/table \[(.+?)]/i);
table = table ? table[1] : undefined;

return new sequelizeErrors.UnknownConstraintError({
message: match[1],
constraint,
table,
cause: error,
stack: errStack,
});
}
}
}

return new sequelizeErrors.DatabaseError(err, { stack: errStack });
}

Expand Down

0 comments on commit 00c1019

Please sign in to comment.