Skip to content

Commit

Permalink
Add a system of error report to not block the full parsing in case I …
Browse files Browse the repository at this point in the history
…make a mistake at some point.

Fixes #18
  • Loading branch information
jecisc committed Sep 21, 2024
1 parent cf58ed2 commit 62fba8d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Famix-Python-Importer/FamixPythonImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Class {
#name : 'FamixPythonImporter',
#superclass : 'Object',
#instVars : [
'visitor'
'visitor',
'errorReport'
],
#category : 'Famix-Python-Importer-Importer',
#package : 'Famix-Python-Importer',
Expand All @@ -26,6 +27,12 @@ FamixPythonImporter class >> import: aFileName [
import: aFileName
]

{ #category : 'accessing' }
FamixPythonImporter >> errorReport [

^ visitor errorReport
]

{ #category : 'api' }
FamixPythonImporter >> import: aFileName [

Expand All @@ -42,6 +49,9 @@ FamixPythonImporter >> import: aFileName [
self importFileReference: fileReference.

visitor solver resolveUnresolvedReferences.

self flag: #todo. "We should probably handle it another way in production."
self errorReport ifNotEmpty: [ self errorReport inspect ].

^ visitor model
]
Expand Down
13 changes: 13 additions & 0 deletions src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ Class {
#tag : 'Visitors'
}

{ #category : 'visiting' }
FamixPythonImporterVisitor >> acceptNode: aNode [

^ [ super acceptNode: aNode ]
on: Exception
do: [ :exception |
(exception isKindOf: Warning)
ifTrue: [
self errorReport addWarning: exception.
exception resume ]
ifFalse: [ self errorReport addError: exception ] ]
]

{ #category : 'visiting' }
FamixPythonImporterVisitor >> acceptNodes: aCollection [
"override to return the result of the visits"
Expand Down

0 comments on commit 62fba8d

Please sign in to comment.