@@ -85,15 +85,15 @@ func (p *PolicyToLint) AddError(path, message string, line int) {
8585func Lookup (absPath , config string , format bool ) (* PolicyToLint , error ) {
8686 resolvedPath , err := resourceloader .GetPathForResource (absPath )
8787 if err != nil {
88- return nil , fmt . Errorf ( "failed to resolve policy file: %w" , err )
88+ return nil , err
8989 }
9090
9191 fileInfo , err := os .Stat (resolvedPath )
9292 if err != nil {
9393 if os .IsNotExist (err ) {
9494 return nil , fmt .Errorf ("policy file does not exist: %s" , resolvedPath )
9595 }
96- return nil , fmt . Errorf ( "failed to stat file %q: %w" , resolvedPath , err )
96+ return nil , err
9797 }
9898 if fileInfo .IsDir () {
9999 return nil , fmt .Errorf ("expected a file but got a directory: %s" , resolvedPath )
@@ -142,14 +142,14 @@ func (p *PolicyToLint) loadReferencedRegoFiles(baseDir string) error {
142142
143143 resolvedPath , err := resourceloader .GetPathForResource (regoPath )
144144 if err != nil {
145- return fmt . Errorf ( "failed to resolve rego file %q: %w" , regoPath , err )
145+ return err
146146 }
147147 if _ , ok := seen [resolvedPath ]; ok {
148148 continue // avoid duplicates
149149 }
150150 seen [resolvedPath ] = struct {}{}
151151 if err := p .processFile (resolvedPath ); err != nil {
152- return fmt . Errorf ( "failed to load referenced rego file %q: %w" , resolvedPath , err )
152+ return err
153153 }
154154 }
155155 }
@@ -160,7 +160,7 @@ func (p *PolicyToLint) loadReferencedRegoFiles(baseDir string) error {
160160func (p * PolicyToLint ) processFile (filePath string ) error {
161161 content , err := os .ReadFile (filePath )
162162 if err != nil {
163- return fmt . Errorf ( "reading %s: %w" , filepath . Base ( filePath ), err )
163+ return err
164164 }
165165
166166 ext := strings .ToLower (filepath .Ext (filePath ))
@@ -197,7 +197,7 @@ func (p *PolicyToLint) Validate() {
197197func (p * PolicyToLint ) validateYAMLFile (file * File ) {
198198 var policy v1.Policy
199199 if err := unmarshal .FromRaw (file .Content , unmarshal .RawFormatYAML , & policy , true ); err != nil {
200- p .AddError (file .Path , fmt . Sprintf ( "failed to parse/validate: %v" , err ) , 0 )
200+ p .AddError (file .Path , "failed to parse/validate policy" , 0 )
201201 return
202202 }
203203
@@ -207,7 +207,7 @@ func (p *PolicyToLint) validateYAMLFile(file *File) {
207207 if p .Format {
208208 var root yaml.Node
209209 if err := yaml .Unmarshal (file .Content , & root ); err != nil {
210- p .AddError (file .Path , fmt . Sprintf ( "failed to parse YAML: %v" , err ) , 0 )
210+ p .AddError (file .Path , "failed to parse YAML" , 0 )
211211 return
212212 }
213213
@@ -222,13 +222,13 @@ func (p *PolicyToLint) validateYAMLFile(file *File) {
222222 defer enc .Close ()
223223
224224 if err := enc .Encode (& root ); err != nil {
225- p .AddError (file .Path , fmt . Sprintf ( "failed to encode YAML: %v" , err ), 0 )
225+ p .AddError (file .Path , err . Error ( ), 0 )
226226 return
227227 }
228228
229229 outYAML := buf .Bytes ()
230230 if err := os .WriteFile (file .Path , outYAML , 0600 ); err != nil {
231- p .AddError (file .Path , fmt . Sprintf ( "failed to write updated file: %v" , err ), 0 )
231+ p .AddError (file .Path , err . Error ( ), 0 )
232232 } else {
233233 if err := os .WriteFile (file .Path , outYAML , 0600 ); err != nil {
234234 p .AddError (file .Path , fmt .Sprintf ("failed to save updated file: %v" , err ), 0 )
@@ -260,7 +260,7 @@ func (p *PolicyToLint) validateRegoFile(file *File) {
260260
261261 if p .Format && formatted != original {
262262 if err := os .WriteFile (file .Path , []byte (formatted ), 0600 ); err != nil {
263- p .AddError (file .Path , fmt . Sprintf ( "failed to auto-format: %v" , err ), 0 )
263+ p .AddError (file .Path , err . Error ( ), 0 )
264264 } else {
265265 file .Content = []byte (formatted )
266266 }
@@ -286,7 +286,7 @@ func (p *PolicyToLint) validateAndFormatRego(content, path string) string {
286286func (p * PolicyToLint ) applyOPAFmt (content , file string ) string {
287287 formatted , err := format .SourceWithOpts (file , []byte (content ), format.Opts {})
288288 if err != nil {
289- p .AddError (file , "Auto -formatting failed" , 0 )
289+ p .AddError (file , "auto -formatting failed" , 0 )
290290 return content
291291 }
292292 return string (formatted )
@@ -352,7 +352,7 @@ func (p *PolicyToLint) runRegalLinter(filePath, content string) {
352352
353353 report , err := lntr .Lint (context .Background ())
354354 if err != nil {
355- p .AddError (filePath , fmt . Sprintf ( "linting failed: %v" , err ), 0 )
355+ p .AddError (filePath , err . Error ( ), 0 )
356356 return
357357 }
358358
0 commit comments