github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/schemadsl/compiler/errors.go (about) 1 package compiler 2 3 import ( 4 "strconv" 5 6 "github.com/authzed/spicedb/pkg/schemadsl/input" 7 ) 8 9 // BaseCompilerError defines an error with contains the base message of the issue 10 // that occurred. 11 type BaseCompilerError struct { 12 error 13 BaseMessage string 14 } 15 16 type errorWithNode struct { 17 error 18 node *dslNode 19 errorSourceCode string 20 } 21 22 // ErrorWithContext defines an error which contains contextual information. 23 type ErrorWithContext struct { 24 BaseCompilerError 25 SourceRange input.SourceRange 26 Source input.Source 27 ErrorSourceCode string 28 } 29 30 func (ewc ErrorWithContext) Unwrap() error { 31 return ewc.BaseCompilerError 32 } 33 34 // DetailsMetadata returns the metadata for details for this error. 35 func (ewc ErrorWithContext) DetailsMetadata() map[string]string { 36 startLine, startCol, err := ewc.SourceRange.Start().LineAndColumn() 37 if err != nil { 38 return map[string]string{} 39 } 40 41 endLine, endCol, err := ewc.SourceRange.End().LineAndColumn() 42 if err != nil { 43 return map[string]string{} 44 } 45 46 return map[string]string{ 47 "start_line_number": strconv.Itoa(startLine), 48 "start_column_position": strconv.Itoa(startCol), 49 "end_line_number": strconv.Itoa(endLine), 50 "end_column_position": strconv.Itoa(endCol), 51 "source_code": ewc.ErrorSourceCode, 52 } 53 }