From f1503edfdeeec29c6e5429375a5f00afea98f2a0 Mon Sep 17 00:00:00 2001 From: James Cor Date: Mon, 5 Jun 2023 11:56:52 -0700 Subject: [PATCH] detailed and formatted error --- .../merge/violations_unique_prolly.go | 2 +- .../doltcore/sqle/dsess/transactions.go | 40 ++++++++++--------- .../enginetest/dolt_transaction_queries.go | 27 ++++++++++--- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/go/libraries/doltcore/merge/violations_unique_prolly.go b/go/libraries/doltcore/merge/violations_unique_prolly.go index 0117c63ad1..0742b34ae1 100644 --- a/go/libraries/doltcore/merge/violations_unique_prolly.go +++ b/go/libraries/doltcore/merge/violations_unique_prolly.go @@ -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{} diff --git a/go/libraries/doltcore/sqle/dsess/transactions.go b/go/libraries/doltcore/sqle/dsess/transactions.go index 165eb876a4..0b1080994f 100644 --- a/go/libraries/doltcore/sqle/dsess/transactions.go +++ b/go/libraries/doltcore/sqle/dsess/transactions.go @@ -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, ", ")) } } diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_transaction_queries.go b/go/libraries/doltcore/sqle/enginetest/dolt_transaction_queries.go index 502dcab19d..ebd07816d6 100755 --- a/go/libraries/doltcore/sqle/enginetest/dolt_transaction_queries.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_transaction_queries.go @@ -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", }, }, },