Skip to content

Commit f6c01e0

Browse files
committed
api: skip printing files with errors
Without this commit, we'd also end up doing a nil pointer access when attempting to print an unparsed file.
1 parent 173681f commit f6c01e0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

api.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,23 @@ func Compile(opts Options) *Result {
237237
wg.Go(func() error {
238238
// XXX: this is the wrong file name
239239
source := c.sourcesByIndex[idx]
240-
c.result.mu.Lock()
241-
defer c.result.mu.Unlock()
240+
ast := c.astsByIndex[idx]
241+
if source == nil || ast == nil {
242+
// Skip attempting to print if there was a problem reading/parsing this file
243+
// in the first place.
244+
return nil
245+
}
242246

243-
out, err := printer.Print(c.astsByIndex[idx], printer.Options{
247+
out, err := printer.Print(ast, printer.Options{
244248
OriginalSource: source,
245249
})
246250
if err != nil {
247251
c.addError(err)
248252
return nil
249253
}
250254

255+
c.result.mu.Lock()
256+
defer c.result.mu.Unlock()
251257
c.result.Files[source.Path] = out
252258
return nil
253259
})

0 commit comments

Comments
 (0)