mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-23 02:40:49 -05:00
Add detailed error messaging when dolt_ignore rules conflict.
This commit is contained in:
@@ -127,7 +127,21 @@ func toAddVErr(err error) errhand.VerboseError {
|
||||
}
|
||||
|
||||
return bdr.Build()
|
||||
case doltdb.IsDoltIgnoreInConflict(err):
|
||||
tbl := doltdb.DoltIgnoreConflictTableName(err)
|
||||
truePatterns := doltdb.DoltIgnoreConflictTruePatterns(err)
|
||||
falsePatterns := doltdb.DoltIgnoreConflictFalsePatterns(err)
|
||||
bdr := errhand.BuildDError("error: the table %s matches conflicting patterns in dolt_ignore", tbl)
|
||||
|
||||
for _, pattern := range truePatterns {
|
||||
bdr.AddDetails("ignored: %s", pattern)
|
||||
}
|
||||
|
||||
for _, pattern := range falsePatterns {
|
||||
bdr.AddDetails("not ignored: %s", pattern)
|
||||
}
|
||||
|
||||
return bdr.Build()
|
||||
default:
|
||||
return errhand.BuildDError("Unknown error").AddCause(err).Build()
|
||||
}
|
||||
|
||||
@@ -170,3 +170,48 @@ func GetUnreachableRootCause(err error) error {
|
||||
|
||||
return rvu.Cause
|
||||
}
|
||||
|
||||
type DoltIgnoreConflict struct {
|
||||
Table string
|
||||
TruePatterns []string
|
||||
FalsePatterns []string
|
||||
}
|
||||
|
||||
func (dc DoltIgnoreConflict) Error() string {
|
||||
return fmt.Sprintf("dolt_ignore has multiple conflicting rules for %s", dc.Table)
|
||||
}
|
||||
|
||||
func IsDoltIgnoreInConflict(err error) bool {
|
||||
_, ok := err.(DoltIgnoreConflict)
|
||||
return ok
|
||||
}
|
||||
|
||||
func DoltIgnoreConflictTableName(err error) string {
|
||||
dc, ok := err.(DoltIgnoreConflict)
|
||||
|
||||
if !ok {
|
||||
panic("Must validate with IsDoltIgnoreInConflict before calling DoltIgnoreConflictTableName")
|
||||
}
|
||||
|
||||
return dc.Table
|
||||
}
|
||||
|
||||
func DoltIgnoreConflictTruePatterns(err error) []string {
|
||||
dc, ok := err.(DoltIgnoreConflict)
|
||||
|
||||
if !ok {
|
||||
panic("Must validate with IsDoltIgnoreInConflict before calling DoltIgnoreConflictTruePatterns")
|
||||
}
|
||||
|
||||
return dc.TruePatterns
|
||||
}
|
||||
|
||||
func DoltIgnoreConflictFalsePatterns(err error) []string {
|
||||
dc, ok := err.(DoltIgnoreConflict)
|
||||
|
||||
if !ok {
|
||||
panic("Must validate with IsDoltIgnoreInConflict before calling DoltIgnoreConflictFalsePatterns")
|
||||
}
|
||||
|
||||
return dc.FalsePatterns
|
||||
}
|
||||
|
||||
@@ -137,7 +137,25 @@ func resolveConflictingPatterns(trueMatches, falseMatches []string, tableName st
|
||||
if len(falseMatchesToRemove) == len(falseMatches) {
|
||||
return true, nil
|
||||
}
|
||||
return false, fmt.Errorf("dolt_ignore has multiple conflicting rules for %s", tableName)
|
||||
|
||||
// There's a conflict. Remove the less specific patterns so that only the conflict remains.
|
||||
|
||||
var conflictingTrueMatches []string
|
||||
var conflictingFalseMatches []string
|
||||
|
||||
for _, trueMatch := range trueMatches {
|
||||
if _, ok := trueMatchesToRemove[trueMatch]; !ok {
|
||||
conflictingTrueMatches = append(conflictingTrueMatches, trueMatch)
|
||||
}
|
||||
}
|
||||
|
||||
for _, falseMatch := range falseMatches {
|
||||
if _, ok := trueMatchesToRemove[falseMatch]; !ok {
|
||||
conflictingFalseMatches = append(conflictingFalseMatches, falseMatch)
|
||||
}
|
||||
}
|
||||
|
||||
return false, DoltIgnoreConflict{Table: tableName, TruePatterns: conflictingTrueMatches, FalsePatterns: conflictingFalseMatches}
|
||||
}
|
||||
|
||||
func (ip *IgnorePatterns) IsTableNameIgnored(tableName string) (bool, error) {
|
||||
|
||||
Reference in New Issue
Block a user