@@ -14,8 +14,37 @@ import (
1414
1515// InstallRuntimeStrict installs a runtime with strict path handling and validation
1616func InstallRuntimeStrict (name string , runtimeInfo * plugins.RuntimeInfo ) error {
17+ logger .Info ("InstallRuntimeStrict called" , logrus.Fields {"runtime" : name , "runtimeInfo_nil" : runtimeInfo == nil })
18+
19+ // If runtimeInfo is nil, try to add and process the runtime
20+ if runtimeInfo == nil {
21+ logger .Warn ("RuntimeInfo is nil, attempting to add and process runtime" , logrus.Fields {"runtime" : name })
22+ defaultVersions := plugins .GetRuntimeVersions ()
23+ logger .Debug ("Default versions map" , logrus.Fields {"defaultVersions" : defaultVersions })
24+ version , ok := defaultVersions [name ]
25+ if ! ok {
26+ logger .Error ("No default version found for runtime" , logrus.Fields {"runtime" : name })
27+ return fmt .Errorf ("no default version found for runtime %s" , name )
28+ }
29+ logger .Info ("Adding runtime to config" , logrus.Fields {"runtime" : name , "version" : version })
30+ if err := Config .AddRuntimes ([]plugins.RuntimeConfig {{Name : name , Version : version }}); err != nil {
31+ logger .Error ("Failed to add runtime to config" , logrus.Fields {"runtime" : name , "error" : err .Error ()})
32+ return fmt .Errorf ("failed to add runtime %s: %w" , name , err )
33+ }
34+ logger .Info ("Fetching runtimeInfo from config after add" , logrus.Fields {"runtime" : name })
35+ runtimeInfo = Config .Runtimes ()[name ]
36+ if runtimeInfo == nil {
37+ logger .Error ("Failed to process runtime after adding (runtimeInfo is still nil)" , logrus.Fields {"runtime" : name })
38+ return fmt .Errorf ("failed to process runtime %s after adding" , name )
39+ }
40+ logger .Info ("runtimeInfo successfully created" , logrus.Fields {"runtime" : name , "version" : runtimeInfo .Version , "installDir" : runtimeInfo .InstallDir , "downloadURL" : runtimeInfo .DownloadURL , "binaries" : runtimeInfo .Binaries })
41+ }
42+
43+ logger .Info ("Proceeding with runtime installation" , logrus.Fields {"runtime" : name , "version" : runtimeInfo .Version })
44+
1745 // Create target directory if it doesn't exist
1846 if err := os .MkdirAll (runtimeInfo .InstallDir , utils .DefaultDirPerms ); err != nil {
47+ logger .Error ("Failed to create installation directory" , logrus.Fields {"runtime" : name , "dir" : runtimeInfo .InstallDir , "error" : err .Error ()})
1948 return fmt .Errorf ("failed to create installation directory: %w" , err )
2049 }
2150
@@ -28,6 +57,7 @@ func InstallRuntimeStrict(name string, runtimeInfo *plugins.RuntimeInfo) error {
2857
2958 archivePath , err := utils .DownloadFile (runtimeInfo .DownloadURL , Config .RuntimesDirectory ())
3059 if err != nil {
60+ logger .Error ("Failed to download runtime archive" , logrus.Fields {"runtime" : name , "url" : runtimeInfo .DownloadURL , "error" : err .Error ()})
3161 return fmt .Errorf ("failed to download runtime archive: %w" , err )
3262 }
3363
@@ -40,6 +70,7 @@ func InstallRuntimeStrict(name string, runtimeInfo *plugins.RuntimeInfo) error {
4070
4171 archive , err := os .Open (archivePath )
4272 if err != nil {
73+ logger .Error ("Failed to open archive" , logrus.Fields {"runtime" : name , "archive" : archivePath , "error" : err .Error ()})
4374 return fmt .Errorf ("failed to open archive: %w" , err )
4475 }
4576 defer archive .Close ()
@@ -51,16 +82,19 @@ func InstallRuntimeStrict(name string, runtimeInfo *plugins.RuntimeInfo) error {
5182 err = utils .ExtractTarGz (archive , Config .RuntimesDirectory ())
5283 }
5384 if err != nil {
85+ logger .Error ("Failed to extract runtime archive" , logrus.Fields {"runtime" : name , "archive" : archivePath , "error" : err .Error ()})
5486 return fmt .Errorf ("failed to extract runtime archive: %w" , err )
5587 }
5688
5789 // Set executable permissions on binaries
5890 logger .Info ("Setting binary permissions" , logrus.Fields {
59- "runtime" : name ,
60- "version" : runtimeInfo .Version ,
91+ "runtime" : name ,
92+ "version" : runtimeInfo .Version ,
93+ "binaries" : runtimeInfo .Binaries ,
6194 })
6295
6396 for binaryName , binaryPath := range runtimeInfo .Binaries {
97+ logger .Debug ("Checking binary existence" , logrus.Fields {"runtime" : name , "binary" : binaryName , "path" : binaryPath })
6498 // Skip if binary doesn't exist yet
6599 if _ , err := os .Stat (binaryPath ); os .IsNotExist (err ) {
66100 logger .Debug ("Binary not found, skipping" , logrus.Fields {
@@ -72,12 +106,14 @@ func InstallRuntimeStrict(name string, runtimeInfo *plugins.RuntimeInfo) error {
72106
73107 // Set executable permissions
74108 if err := os .Chmod (binaryPath , 0755 ); err != nil {
109+ logger .Error ("Failed to set permissions for binary" , logrus.Fields {"runtime" : name , "binary" : binaryName , "path" : binaryPath , "error" : err .Error ()})
75110 return fmt .Errorf ("failed to set permissions for binary %s: %w" , binaryName , err )
76111 }
77112 }
78113
79114 // Verify installation
80115 if ! Config .IsRuntimeInstalled (name , runtimeInfo ) {
116+ logger .Error ("Runtime installed but binaries are not available" , logrus.Fields {"runtime" : name , "version" : runtimeInfo .Version })
81117 return fmt .Errorf ("runtime %s was installed but binaries are not available" , name )
82118 }
83119
@@ -88,6 +124,7 @@ func InstallRuntimeStrict(name string, runtimeInfo *plugins.RuntimeInfo) error {
88124
89125 // Update codacy.yaml with the new runtime
90126 if err := updateRuntimeInCodacyYaml (name , runtimeInfo .Version ); err != nil {
127+ logger .Error ("Failed to update codacy.yaml with runtime" , logrus.Fields {"runtime" : name , "error" : err .Error ()})
91128 return fmt .Errorf ("failed to update codacy.yaml with runtime %s: %w" , name , err )
92129 }
93130
0 commit comments