@@ -26,21 +26,58 @@ func (z *Readme) Preset() {
2626}
2727
2828func (z * Readme ) genDoc (path string , doc string , c app_control.Control ) error {
29+ l := c .Log ()
30+
2931 if c .Feature ().IsTest () {
32+ l .Debug ("Generating README to stdout (test mode)" )
3033 out := es_stdout .NewDefaultOut (c .Feature ())
31- _ , _ = fmt .Fprintln (out , doc )
34+ if out == nil {
35+ l .Error ("Failed to create stdout output" )
36+ return fmt .Errorf ("failed to create stdout output" )
37+ }
38+ _ , err := fmt .Fprintln (out , doc )
39+ if err != nil {
40+ l .Error ("Failed to write README to stdout" , esl .Error (err ))
41+ return err
42+ }
3243 return nil
3344 } else {
34- return os .WriteFile (path , []byte (doc ), 0644 )
45+ l .Debug ("Writing README to file" , esl .String ("path" , path ))
46+ err := os .WriteFile (path , []byte (doc ), 0644 )
47+ if err != nil {
48+ l .Error ("Failed to write README file" , esl .Error (err ), esl .String ("path" , path ))
49+ return err
50+ }
51+ l .Debug ("README file written successfully" , esl .String ("path" , path ))
52+ return nil
3553 }
3654}
3755
3856func (z * Readme ) Exec (c app_control.Control ) error {
3957 l := c .Log ()
4058 l .Info ("Generating README" , esl .String ("path" , z .Path .Path ()))
59+
60+ // Add defensive error handling for CI environment
61+ defer func () {
62+ if r := recover (); r != nil {
63+ l .Error ("README generation panicked" , esl .Any ("panic" , r ))
64+ }
65+ }()
66+
67+ // Generate documentation sections with error handling
4168 sec := dc_readme .New (dc_index .MediaRepository , c .Messages (), false )
69+ if sec == nil {
70+ l .Error ("Failed to create README sections" )
71+ return fmt .Errorf ("failed to create README sections" )
72+ }
73+
4274 doc := dc_section .Generate (dc_index .MediaRepository , dc_section .LayoutPage , c .Messages (), sec )
43-
75+ if doc == "" {
76+ l .Error ("Generated README document is empty" )
77+ return fmt .Errorf ("generated README document is empty" )
78+ }
79+
80+ l .Debug ("README document generated" , esl .Int ("length" , len (doc )))
4481 return z .genDoc (z .Path .Path (), doc , c )
4582}
4683
0 commit comments