@@ -105,18 +105,21 @@ func main() {
105105 continue
106106 }
107107 fmt .Println ("Generating documentation for:" , target )
108- updateDocumentation (target , path , docPath )
108+ if err := updateDocumentation (target , path , docPath ); err != nil {
109+ fmt .Fprintln (os .Stderr , err )
110+ os .Exit (1 )
111+ }
109112 }
110113}
111114
112- func updateDocumentation (target , path , docPath string ) {
115+ func updateDocumentation (target , path , docPath string ) error {
113116 // Get the important information from the compiler.
114117 cmd := exec .Command ("tinygo" , "info" , target )
115118 outBytes , err := cmd .Output ()
116119 if err != nil {
117- fmt .Fprintln (os .Stderr , "could not run tinygo:" , err )
118- os .Exit (1 )
120+ return fmt .Errorf ("could not run tinygo: %v" , err )
119121 }
122+
120123 var buildTags []string
121124 var goos , goarch , goroot string
122125 for _ , line := range strings .Split (string (outBytes ), "\n " ) {
@@ -138,8 +141,7 @@ func updateDocumentation(target, path, docPath string) {
138141 }
139142 }
140143 if len (buildTags ) == 0 || goos == "" || goarch == "" || goroot == "" {
141- fmt .Fprintln (os .Stderr , "could not find all needed properties (build tags, GOOS, GOARCH, GOROOT)" )
142- os .Exit (1 )
144+ return fmt .Errorf ("could not find all needed properties (build tags, GOOS, GOARCH, GOROOT)" )
143145 }
144146
145147 // Get the list of files that would be compiled for this package.
@@ -154,24 +156,26 @@ func updateDocumentation(target, path, docPath string) {
154156
155157 // Do some sanity checking.
156158 if len (pkgs [0 ].Errors ) != 0 {
159+ fmt .Fprintf (os .Stderr , " sanity check failed with %d error(s)\n " , len (pkgs [0 ].Errors ))
157160 for _ , err := range pkgs [0 ].Errors {
158- fmt .Fprintln (os .Stderr , err )
161+ fmt .Fprintf (os .Stderr , " * %v \n " , err )
159162 }
160- os .Exit (1 )
163+ return nil
164+ //os.Exit(1)
161165 }
162166 pkg := pkgs [0 ]
163167
164168 err = writeMachinePackageDoc (path , target , pkg )
165169 if err != nil {
166- fmt .Fprintln (os .Stderr , "error:" , err )
167- os .Exit (1 )
170+ return fmt .Errorf ("error on write machine package doc: %v" , err )
168171 }
169172
170173 err = updateBoardDocumentation (docPath , pkg , buildTags )
171174 if err != nil {
172- fmt .Fprintln (os .Stderr , "error:" , err )
173- os .Exit (1 )
175+ return fmt .Errorf ("error on update board documentation: %v" , err )
174176 }
177+
178+ return nil
175179}
176180
177181func writeMachinePackageDoc (path , target string , pkg * packages.Package ) error {
0 commit comments