@@ -136,29 +136,56 @@ func DownloadMountImageWorker(manifest *ankabuffer.Manifest, bin int, fragment s
136136 feedbackWg .Wait ()
137137}
138138
139- func GetLatestLauncherVersion (release string ) string {
139+ func GetLatestLauncherVersion (release string ) ( string , error ) {
140140 versionResponse , err := http .Get ("https://cytrus.cdn.ankama.com/cytrus.json" )
141141 if err != nil {
142- log .Fatal (err )
142+ return "" , fmt .Errorf ("failed to fetch cytrus.json: %w" , err )
143+ }
144+ defer versionResponse .Body .Close ()
145+
146+ // Check HTTP status code
147+ if versionResponse .StatusCode != http .StatusOK {
148+ return "" , fmt .Errorf ("cytrus.json returned HTTP %d" , versionResponse .StatusCode )
143149 }
144150
145151 versionBody , err := io .ReadAll (versionResponse .Body )
146152 if err != nil {
147- log . Fatal ( err )
153+ return "" , fmt . Errorf ( "failed to read cytrus.json response: %w" , err )
148154 }
149155
150156 var versionJson map [string ]interface {}
151157 err = json .Unmarshal (versionBody , & versionJson )
152158 if err != nil {
153- log . Fatal ( err )
159+ return "" , fmt . Errorf ( "failed to parse cytrus.json: %w" , err )
154160 }
155161
156- games := versionJson ["games" ].(map [string ]interface {})
157- dofus := games ["dofus" ].(map [string ]interface {})
158- platform := dofus ["platforms" ].(map [string ]interface {})
159- windows := platform ["windows" ].(map [string ]interface {})
162+ // Safe type assertions with error checking
163+ games , ok := versionJson ["games" ].(map [string ]interface {})
164+ if ! ok {
165+ return "" , fmt .Errorf ("cytrus.json: 'games' field not found or invalid type" )
166+ }
167+
168+ dofus , ok := games ["dofus" ].(map [string ]interface {})
169+ if ! ok {
170+ return "" , fmt .Errorf ("cytrus.json: 'games.dofus' field not found or invalid type" )
171+ }
160172
161- return windows [release ].(string )
173+ platforms , ok := dofus ["platforms" ].(map [string ]interface {})
174+ if ! ok {
175+ return "" , fmt .Errorf ("cytrus.json: 'platforms' field not found or invalid type" )
176+ }
177+
178+ windows , ok := platforms ["windows" ].(map [string ]interface {})
179+ if ! ok {
180+ return "" , fmt .Errorf ("cytrus.json: 'windows' platform not found or invalid type" )
181+ }
182+
183+ version , ok := windows [release ].(string )
184+ if ! ok {
185+ return "" , fmt .Errorf ("cytrus.json: version for release '%s' not found or invalid type" , release )
186+ }
187+
188+ return version , nil
162189}
163190
164191func touchFileIfNotExists (fileName string ) error {
@@ -304,7 +331,11 @@ func Download(releaseChannel string, version string, dir string, clean bool, ful
304331 if manifestPath == "" || clean {
305332 cytrusPrefix := "6.0_"
306333 if version == "latest" {
307- version = GetLatestLauncherVersion (releaseChannel )
334+ var err error
335+ version , err = GetLatestLauncherVersion (releaseChannel )
336+ if err != nil {
337+ return err
338+ }
308339 } else {
309340 // ATT: prefix changes with cytrus updates
310341 if ! strings .HasPrefix (version , cytrusPrefix ) {
0 commit comments