@@ -399,39 +399,39 @@ func fastParseTitleFromReader(r io.Reader) (string, error) {
399399}
400400
401401// extractWorkflowNameFromFile extracts the workflow name from a file's H1 header
402- func extractWorkflowNameFromFile (filePath string ) (title string , err error ) {
402+ func extractWorkflowNameFromFile (filePath string ) (string , error ) {
403403 fd , err := os .Open (filePath )
404404 if err != nil {
405405 return "" , err
406406 }
407- defer func () {
408- if closeErr := fd .Close (); closeErr != nil && err == nil {
409- err = fmt .Errorf ("failed to close workflow file %s: %w" , filePath , closeErr )
410- }
411- }()
412407
413- title , err = fastParseTitleFromReader (fd )
408+ title , err : = fastParseTitleFromReader (fd )
414409 if err != nil {
410+ _ = fd .Close ()
415411 return "" , err
416412 }
417- if title != "" {
418- return title , nil
419- }
420413
421- // No H1 header found, generate default name from filename
422- baseName := filepath .Base (filePath )
423- baseName = strings .TrimSuffix (baseName , filepath .Ext (baseName ))
424- baseName = strings .ReplaceAll (baseName , "-" , " " )
414+ if title == "" {
415+ // No H1 header found, generate default name from filename
416+ baseName := filepath .Base (filePath )
417+ baseName = strings .TrimSuffix (baseName , filepath .Ext (baseName ))
418+ baseName = strings .ReplaceAll (baseName , "-" , " " )
425419
426- // Capitalize first letter of each word
427- words := strings .Fields (baseName )
428- for i , word := range words {
429- if len (word ) > 0 {
430- words [i ] = strings .ToUpper (word [:1 ]) + word [1 :]
420+ // Capitalize first letter of each word
421+ words := strings .Fields (baseName )
422+ for i , word := range words {
423+ if len (word ) > 0 {
424+ words [i ] = strings .ToUpper (word [:1 ]) + word [1 :]
425+ }
431426 }
427+ title = strings .Join (words , " " )
428+ }
429+
430+ if closeErr := fd .Close (); closeErr != nil {
431+ return title , fmt .Errorf ("failed to close workflow file %s: %w" , filePath , closeErr )
432432 }
433433
434- return strings . Join ( words , " " ) , nil
434+ return title , nil
435435}
436436
437437// extractEngineIDFromFrontmatter extracts the engine ID from a parsed frontmatter map.
0 commit comments