detailed and formatted error

This commit is contained in:
James Cor
2023-06-05 11:56:52 -07:00
parent b1d1ea80de
commit f1503edfde
3 changed files with 43 additions and 26 deletions

View File

@@ -163,7 +163,7 @@ func (m NullViolationMeta) ToString(ctx *sql.Context) (string, error) {
// CheckCVMeta holds metadata describing a check constraint violation.
type CheckCVMeta struct {
Name string `json:"Name"`
Expression string `jason:"Expression"`
Expression string `json:"Expression"`
}
var _ types.JSONValue = CheckCVMeta{}

View File

@@ -587,13 +587,13 @@ func (tx *DoltTransaction) validateWorkingSetForCommit(ctx *sql.Context, working
if err != nil {
return err
}
s += fmt.Sprintf("Type: Foreign Key Constraint Violation\n" +
"ForeignKey: %s,\n" +
"Table: %s,\n" +
"ReferencedTable: %s,\n" +
"Index: %s,\n" +
"ReferencedIndex: %s\n", m.ForeignKey, m.Table, m.ReferencedIndex, m.Index, m.ReferencedIndex)
s = fmt.Sprintf("\n" +
"Type: Foreign Key Constraint Violation\n" +
"\tForeignKey: %s,\n" +
"\tTable: %s,\n" +
"\tReferencedTable: %s,\n" +
"\tIndex: %s,\n" +
"\tReferencedIndex: %s", m.ForeignKey, m.Table, m.ReferencedIndex, m.Index, m.ReferencedIndex)
case prolly.ArtifactTypeUniqueKeyViol:
var m merge.UniqCVMeta
@@ -601,11 +601,10 @@ func (tx *DoltTransaction) validateWorkingSetForCommit(ctx *sql.Context, working
if err != nil {
return err
}
s += fmt.Sprintf(": %s,\n" +
"Table: %s,\n" +
"ReferencedTable: %s,\n" +
"Index: %s,\n" +
"ReferencedIndex: %s\n", m.ForeignKey, m.Table, m.ReferencedIndex, m.Index, m.ReferencedIndex)
s = fmt.Sprintf("\n" +
"Type: Unique Key Constraint Violation,\n" +
"\tName: %s,\n" +
"\tColumns: %v", m.Name, m.Columns)
case prolly.ArtifactTypeNullViol:
var m merge.NullViolationMeta
@@ -613,23 +612,25 @@ func (tx *DoltTransaction) validateWorkingSetForCommit(ctx *sql.Context, working
if err != nil {
return err
}
s = fmt.Sprintf("\n" +
"Type: Null Constraint Violation,\n" +
"\tColumns: %v", m.Columns)
case prolly.ArtifactTypeChkConsViol:
var m merge.CheckCVMeta
err = json.Unmarshal(meta.VInfo, &m)
if err != nil {
return err
}
default:
panic("json not implemented for artifact type")
s = fmt.Sprintf("\n" +
"Type: Check Constraint Violation,\n" +
"\tName: %s,\n" +
"\tExpression: %v", m.Name, m.Expression)
}
if err != nil {
return err
}
for k, v := range res {
s += fmt.Sprintf("%s: %s\n", k, v)
}
violations[i] = s
}
}
@@ -639,7 +640,8 @@ func (tx *DoltTransaction) validateWorkingSetForCommit(ctx *sql.Context, working
return rollbackErr
}
return fmt.Errorf("%s Constraint violations: %s", ErrUnresolvedConstraintViolationsCommit, strings.Join(violations, ", "))
return fmt.Errorf("%s\n" +
"Constraint violations: %s", ErrUnresolvedConstraintViolationsCommit, strings.Join(violations, ", "))
}
}

View File

@@ -1995,8 +1995,14 @@ var DoltConstraintViolationTransactionTests = []queries.TransactionTest{
ExpectedErrStr: "Committing this transaction resulted in a working set with constraint violations, transaction rolled back. " +
"This constraint violation may be the result of a previous merge or the result of transaction sequencing. " +
"Constraint violations from a merge can be resolved using the dolt_constraint_violations table before committing the transaction. " +
"To allow transactions to be committed with constraint violations from a merge or transaction sequencing set @@dolt_force_transaction_commit=1. " +
"Constraint violations: Columns: [parent_fk]\nOnDelete: RESTRICT\nReferencedColumns: [pk]\nReferencedIndex: \nTable: child\nForeignKey: 0050p5ek\nIndex: parent_fk\nOnUpdate: RESTRICT\nReferencedTable: parent\n",
"To allow transactions to be committed with constraint violations from a merge or transaction sequencing set @@dolt_force_transaction_commit=1.\n" +
"Constraint violations: \n" +
"Type: Foreign Key Constraint Violation\n" +
"\tForeignKey: 0050p5ek,\n" +
"\tTable: child,\n" +
"\tReferencedTable: ,\n" +
"\tIndex: parent_fk,\n" +
"\tReferencedIndex: ",
},
{
Query: "/* client b */ INSERT INTO child VALUES (1, 1);",
@@ -2025,8 +2031,11 @@ var DoltConstraintViolationTransactionTests = []queries.TransactionTest{
ExpectedErrStr: "Committing this transaction resulted in a working set with constraint violations, transaction rolled back. " +
"This constraint violation may be the result of a previous merge or the result of transaction sequencing. " +
"Constraint violations from a merge can be resolved using the dolt_constraint_violations table before committing the transaction. " +
"To allow transactions to be committed with constraint violations from a merge or transaction sequencing set @@dolt_force_transaction_commit=1. " +
"Constraint violations: Columns: [col1]\nName: col1\n",
"To allow transactions to be committed with constraint violations from a merge or transaction sequencing set @@dolt_force_transaction_commit=1.\n" +
"Constraint violations: \n" +
"Type: Unique Key Constraint Violation,\n" +
"\tName: col1,\n" +
"\tColumns: [col1]",
},
{
Query: "/* client a */ SELECT * from DOLT_CONSTRAINT_VIOLATIONS;",
@@ -2109,8 +2118,14 @@ var DoltConstraintViolationTransactionTests = []queries.TransactionTest{
ExpectedErrStr: "Committing this transaction resulted in a working set with constraint violations, transaction rolled back. " +
"This constraint violation may be the result of a previous merge or the result of transaction sequencing. " +
"Constraint violations from a merge can be resolved using the dolt_constraint_violations table before committing the transaction. " +
"To allow transactions to be committed with constraint violations from a merge or transaction sequencing set @@dolt_force_transaction_commit=1. " +
"Constraint violations: Table: child\nForeignKey: fk_name\nOnUpdate: RESTRICT\nReferencedTable: parent\nReferencedColumns: [v1]\nReferencedIndex: v1\nColumns: [v1]\nIndex: v1\nOnDelete: RESTRICT\n",
"To allow transactions to be committed with constraint violations from a merge or transaction sequencing set @@dolt_force_transaction_commit=1.\n" +
"Constraint violations: \n" +
"Type: Foreign Key Constraint Violation\n" +
"\tForeignKey: fk_name,\n" +
"\tTable: child,\n" +
"\tReferencedTable: v1,\n" +
"\tIndex: v1,\n" +
"\tReferencedIndex: v1",
},
},
},