@@ -152,7 +152,7 @@ func (d *DaVinciGenerator) buildData(data any, parsedIntf map[string]interface{}
152152 return err
153153 }
154154 default :
155- return fmt .Errorf ("Unknown data type: %T" , data )
155+ return fmt .Errorf ("unknown data type: %T" , data )
156156 }
157157
158158 return nil
@@ -180,7 +180,7 @@ func (d *DaVinciGenerator) buildDataSingleFlow(flow davinci.Flow, parsedIntf map
180180 for _ , variable := range flow .Variables {
181181
182182 if variable .Context == nil || variable .Fields == nil || variable .Fields .Type == nil {
183- return fmt .Errorf ("Potentially corrupt DaVinci export file. Variable %s is missing required fields" , variable .Name )
183+ return fmt .Errorf ("potentially corrupt DaVinci export file. Variable %s is missing required fields" , variable .Name )
184184 }
185185
186186 reg := regexp .MustCompile (`^([a-zA-Z0-9-_]*)[[#]{2}.+]*$` )
@@ -195,7 +195,7 @@ func (d *DaVinciGenerator) buildDataSingleFlow(flow davinci.Flow, parsedIntf map
195195 // matches[1] is the first capture group
196196 variableName = matches [1 ]
197197 } else {
198- return fmt .Errorf ("No match found for variable name parsing: %s" , variable .Name )
198+ return fmt .Errorf ("no match found for variable name parsing: %s" , variable .Name )
199199 }
200200
201201 resourceName := sanitiseResourceName (variableName )
@@ -261,7 +261,7 @@ func (d *DaVinciGenerator) buildDataSingleFlow(flow davinci.Flow, parsedIntf map
261261 }) {
262262 connectionProperties , err := getConnectionProperties (* nodeData .ConnectorID )
263263 if err != nil {
264- return fmt .Errorf ("Failed to get connection properties for connector ID %s: %s" , * nodeData .ConnectorID , err )
264+ return fmt .Errorf ("failed to get connection properties for connector ID %s: %s" , * nodeData .ConnectorID , err )
265265 }
266266
267267 d .ConnectionsData = append (d .ConnectionsData , connectionData {
@@ -289,7 +289,7 @@ func (d *DaVinciGenerator) buildDataSingleFlow(flow davinci.Flow, parsedIntf map
289289 subflowID := nodeData .Properties .SubFlowID .Value
290290
291291 if subflowID .Label == nil || subflowID .Value == nil {
292- return fmt .Errorf ("Potentially corrupt DaVinci export file. Subflow connector with ID %s is missing required fields" , * nodeData .ID )
292+ return fmt .Errorf ("potentially corrupt DaVinci export file. Subflow connector with ID %s is missing required fields" , * nodeData .ID )
293293 }
294294
295295 if ! slices .ContainsFunc (subflowLinks , func (v flowSubflowLink ) bool {
@@ -453,7 +453,12 @@ func (d *DaVinciGenerator) writeBaseVars(version string, overwrite bool) error {
453453 if err != nil {
454454 return err
455455 }
456- defer outputFile .Close ()
456+ defer func () {
457+ if err := outputFile .Close (); err != nil {
458+ l := logger .Get ()
459+ l .Error ().Err (err ).Msg ("Failed to close file" )
460+ }
461+ }()
457462
458463 err = hclTemplate .Execute (outputFile , nil )
459464 if err != nil {
@@ -494,7 +499,12 @@ func (d *DaVinciGenerator) writeBaseVersions(version string, overwrite bool) err
494499 if err != nil {
495500 return err
496501 }
497- defer outputFile .Close ()
502+ defer func () {
503+ if err := outputFile .Close (); err != nil {
504+ l := logger .Get ()
505+ l .Error ().Err (err ).Msg ("Failed to close file" )
506+ }
507+ }()
498508
499509 err = hclTemplate .Execute (outputFile , nil )
500510 if err != nil {
@@ -535,7 +545,12 @@ func (d *DaVinciGenerator) writeVariables(version string, overwrite bool) error
535545 if err != nil {
536546 return err
537547 }
538- defer outputFile .Close ()
548+ defer func () {
549+ if err := outputFile .Close (); err != nil {
550+ l := logger .Get ()
551+ l .Error ().Err (err ).Msg ("Failed to close file" )
552+ }
553+ }()
539554
540555 for _ , variableData := range d .VariablesData {
541556 err = hclTemplate .Execute (outputFile , variableData )
@@ -578,7 +593,12 @@ func (d *DaVinciGenerator) writeVariableVars(version string, overwrite bool) err
578593 if err != nil {
579594 return err
580595 }
581- defer outputFile .Close ()
596+ defer func () {
597+ if err := outputFile .Close (); err != nil {
598+ l := logger .Get ()
599+ l .Error ().Err (err ).Msg ("Failed to close file" )
600+ }
601+ }()
582602
583603 for _ , variableData := range d .VariablesData {
584604 err = hclTemplate .Execute (outputFile , variableData )
@@ -621,7 +641,12 @@ func (d *DaVinciGenerator) writeConnections(version string, overwrite bool) erro
621641 if err != nil {
622642 return err
623643 }
624- defer outputFile .Close ()
644+ defer func () {
645+ if err := outputFile .Close (); err != nil {
646+ l := logger .Get ()
647+ l .Error ().Err (err ).Msg ("Failed to close file" )
648+ }
649+ }()
625650
626651 for _ , connectionData := range d .ConnectionsData {
627652 err = hclTemplate .Execute (outputFile , connectionData )
@@ -664,7 +689,12 @@ func (d *DaVinciGenerator) writeConnectionsPropertyVars(version string, overwrit
664689 if err != nil {
665690 return err
666691 }
667- defer outputFile .Close ()
692+ defer func () {
693+ if err := outputFile .Close (); err != nil {
694+ l := logger .Get ()
695+ l .Error ().Err (err ).Msg ("Failed to close file" )
696+ }
697+ }()
668698
669699 for _ , connectionData := range d .ConnectionsData {
670700 err = hclTemplate .Execute (outputFile , connectionData )
@@ -706,7 +736,12 @@ func (d *DaVinciGenerator) writeFlows(version string, overwrite bool) error {
706736 if err != nil {
707737 return err
708738 }
709- defer outputFile .Close ()
739+ defer func () {
740+ if err := outputFile .Close (); err != nil {
741+ l := logger .Get ()
742+ l .Error ().Err (err ).Msg ("Failed to close file" )
743+ }
744+ }()
710745
711746 for _ , flowData := range d .FlowsData {
712747 err = hclTemplate .Execute (outputFile , flowData )
@@ -748,7 +783,12 @@ func (d *DaVinciGenerator) writeFlowVars(version string, overwrite bool) error {
748783 if err != nil {
749784 return err
750785 }
751- defer outputFile .Close ()
786+ defer func () {
787+ if err := outputFile .Close (); err != nil {
788+ l := logger .Get ()
789+ l .Error ().Err (err ).Msg ("Failed to close file" )
790+ }
791+ }()
752792
753793 for _ , flowData := range d .FlowsData {
754794 err = hclTemplate .Execute (outputFile , flowData )
@@ -790,7 +830,12 @@ func (d *DaVinciGenerator) writeFlowOutputs(version string, overwrite bool) erro
790830 if err != nil {
791831 return err
792832 }
793- defer outputFile .Close ()
833+ defer func () {
834+ if err := outputFile .Close (); err != nil {
835+ l := logger .Get ()
836+ l .Error ().Err (err ).Msg ("Failed to close file" )
837+ }
838+ }()
794839
795840 for _ , flowData := range d .FlowsData {
796841 err = hclTemplate .Execute (outputFile , flowData )
@@ -832,7 +877,12 @@ func (d *DaVinciGenerator) writeReadme(version string, overwrite bool) error {
832877 if err != nil {
833878 return err
834879 }
835- defer outputFile .Close ()
880+ defer func () {
881+ if err := outputFile .Close (); err != nil {
882+ l := logger .Get ()
883+ l .Error ().Err (err ).Msg ("Failed to close file" )
884+ }
885+ }()
836886
837887 err = readmeTemplate .Execute (outputFile , d )
838888 if err != nil {
@@ -865,12 +915,12 @@ func (d *DaVinciGenerator) writeAsset(flowAsset flowAssetData) error {
865915
866916 fileData , err := json .MarshalIndent (flowAsset .flowMap , "" , " " )
867917 if err != nil {
868- return fmt .Errorf ("Cannot marshal asset data: %s" , err )
918+ return fmt .Errorf ("cannot marshal asset data: %s" , err )
869919 }
870920
871921 err = os .WriteFile (fmt .Sprintf ("%s/%s" , d .outputPath , flowAsset .path ), fileData , 0600 )
872922 if err != nil {
873- return fmt .Errorf ("Cannot write asset file %s: %s" , flowAsset .path , err )
923+ return fmt .Errorf ("cannot write asset file %s: %s" , flowAsset .path , err )
874924 }
875925
876926 return nil
0 commit comments