From c2ac7287d004e3c476f142a0a84e1f74398ea236 Mon Sep 17 00:00:00 2001 From: delvh Date: Wed, 5 Oct 2022 11:38:57 +0200 Subject: [PATCH 1/4] Fix and improve incorrect error messages --- modules/options/static.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/options/static.go b/modules/options/static.go index d9a6c8366405e..5a26d3ef218a7 100644 --- a/modules/options/static.go +++ b/modules/options/static.go @@ -32,12 +32,12 @@ func Dir(name string) ([]string, error) { customDir := path.Join(setting.CustomPath, "options", name) isDir, err := util.IsDir(customDir) if err != nil { - return []string{}, fmt.Errorf("Failed to check if custom directory %s is a directory. %v", err) + return []string{}, fmt.Errorf("Failed to check if custom directory %s is a directory. %w", customDir, err) } if isDir { files, err := util.StatDir(customDir, true) if err != nil { - return []string{}, fmt.Errorf("Failed to read custom directory. %v", err) + return []string{}, fmt.Errorf("Failed to read custom directory %s. %w", customDir, err) } result = append(result, files...) @@ -45,11 +45,10 @@ func Dir(name string) ([]string, error) { files, err := AssetDir(name) if err != nil { - return []string{}, fmt.Errorf("Failed to read embedded directory. %v", err) + return []string{}, fmt.Errorf("Failed to read embedded directory %s. %w", name, err) } result = append(result, files...) - return directories.AddAndGet(name, result), nil } From cc83a509b8fe2072009f8900b68e1107d0003447 Mon Sep 17 00:00:00 2001 From: delvh Date: Wed, 5 Oct 2022 11:40:29 +0200 Subject: [PATCH 2/4] Convert error messages to lowercase --- modules/options/static.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/options/static.go b/modules/options/static.go index 5a26d3ef218a7..3a0e66bf7dfc3 100644 --- a/modules/options/static.go +++ b/modules/options/static.go @@ -32,12 +32,12 @@ func Dir(name string) ([]string, error) { customDir := path.Join(setting.CustomPath, "options", name) isDir, err := util.IsDir(customDir) if err != nil { - return []string{}, fmt.Errorf("Failed to check if custom directory %s is a directory. %w", customDir, err) + return []string{}, fmt.Errorf("failed to check if custom directory %s is a directory. %w", customDir, err) } if isDir { files, err := util.StatDir(customDir, true) if err != nil { - return []string{}, fmt.Errorf("Failed to read custom directory %s. %w", customDir, err) + return []string{}, fmt.Errorf("failed to read custom directory %s. %w", customDir, err) } result = append(result, files...) @@ -45,7 +45,7 @@ func Dir(name string) ([]string, error) { files, err := AssetDir(name) if err != nil { - return []string{}, fmt.Errorf("Failed to read embedded directory %s. %w", name, err) + return []string{}, fmt.Errorf("failed to read embedded directory %s. %w", name, err) } result = append(result, files...) From f598f59246f631bc03783a39547f015f26dde426 Mon Sep 17 00:00:00 2001 From: delvh Date: Wed, 5 Oct 2022 12:53:50 +0200 Subject: [PATCH 3/4] Update copyright notice --- modules/options/static.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/options/static.go b/modules/options/static.go index 3a0e66bf7dfc3..a33878c4216b3 100644 --- a/modules/options/static.go +++ b/modules/options/static.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Gitea Authors. All rights reserved. +// Copyright 2016-2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. From 6dd69e954b3078c80668cbb4fa75250b652a126c Mon Sep 17 00:00:00 2001 From: delvh Date: Thu, 6 Oct 2022 00:00:19 +0200 Subject: [PATCH 4/4] Further improve error messages as per @zeripath Co-authored-by: zeripath --- modules/options/static.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/options/static.go b/modules/options/static.go index a33878c4216b3..4d60879be372a 100644 --- a/modules/options/static.go +++ b/modules/options/static.go @@ -1,4 +1,4 @@ -// Copyright 2016-2022 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -32,12 +32,12 @@ func Dir(name string) ([]string, error) { customDir := path.Join(setting.CustomPath, "options", name) isDir, err := util.IsDir(customDir) if err != nil { - return []string{}, fmt.Errorf("failed to check if custom directory %s is a directory. %w", customDir, err) + return []string{}, fmt.Errorf("unable to check if custom directory %q is a directory. %w", customDir, err) } if isDir { files, err := util.StatDir(customDir, true) if err != nil { - return []string{}, fmt.Errorf("failed to read custom directory %s. %w", customDir, err) + return []string{}, fmt.Errorf("unable to read custom directory %q. %w", customDir, err) } result = append(result, files...) @@ -45,7 +45,7 @@ func Dir(name string) ([]string, error) { files, err := AssetDir(name) if err != nil { - return []string{}, fmt.Errorf("failed to read embedded directory %s. %w", name, err) + return []string{}, fmt.Errorf("unable to read embedded directory %q. %w", name, err) } result = append(result, files...)