Browse Source

Check unhandled errors (#128)

Matthias Loibl 3 years ago
parent
commit
31da225309
2 changed files with 16 additions and 4 deletions
  1. 2 1
      main.go
  2. 14 3
      routers/install.go

+ 2 - 1
main.go

@@ -8,6 +8,7 @@
8 8
 package main
9 9
 
10 10
 import (
11
+	"log"
11 12
 	"os"
12 13
 	"runtime"
13 14
 
@@ -38,5 +39,5 @@ func main() {
38 39
 		cmd.CmdAdmin,
39 40
 	}
40 41
 	app.Flags = append(app.Flags, []cli.Flag{}...)
41
-	app.Run(os.Args)
42
+	log.Fatal(app.Run(os.Args))
42 43
 }

+ 14 - 3
routers/install.go

@@ -345,7 +345,12 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
345 345
 	cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")
346 346
 	cfg.Section("security").Key("SECRET_KEY").SetValue(base.GetRandomString(15))
347 347
 
348
-	os.MkdirAll(filepath.Dir(setting.CustomConf), os.ModePerm)
348
+	err := os.MkdirAll(filepath.Dir(setting.CustomConf), os.ModePerm)
349
+	if err != nil {
350
+		ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
351
+		return
352
+	}
353
+
349 354
 	if err := cfg.SaveTo(setting.CustomConf); err != nil {
350 355
 		ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
351 356
 		return
@@ -375,8 +380,14 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
375 380
 		}
376 381
 
377 382
 		// Auto-login for admin
378
-		ctx.Session.Set("uid", u.ID)
379
-		ctx.Session.Set("uname", u.Name)
383
+		if err := ctx.Session.Set("uid", u.ID); err != nil {
384
+			ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
385
+			return
386
+		}
387
+		if err := ctx.Session.Set("uname", u.Name); err != nil {
388
+			ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
389
+			return
390
+		}
380 391
 	}
381 392
 
382 393
 	log.Info("First-time run install finished!")