Commit b3bfbc6f by Hofls Committed by Carl Bergquist

Config: Show user-friendly error message instead of stack trace (#16564)

Fixes #16283
parent afd55cb4
package setting
import (
"gopkg.in/ini.v1"
"os"
"path"
"path/filepath"
"runtime"
"testing"
......@@ -189,4 +191,29 @@ func TestLoadingSettings(t *testing.T) {
So(cfg.RendererCallbackUrl, ShouldEqual, "http://myserver/renderer/")
})
})
Convey("Test reading string values from .ini file", t, func() {
iniFile, err := ini.Load(path.Join(HomePath, "pkg/setting/testdata/invalid.ini"))
So(err, ShouldBeNil)
Convey("If key is found - should return value from ini file", func() {
value, err := valueAsString(iniFile.Section("server"), "alt_url", "")
So(err, ShouldBeNil)
So(value, ShouldEqual, "https://grafana.com/")
})
Convey("If key is not found - should return default value", func() {
value, err := valueAsString(iniFile.Section("server"), "extra_url", "default_url_val")
So(err, ShouldBeNil)
So(value, ShouldEqual, "default_url_val")
})
Convey("In case of panic - should return user-friendly error", func() {
value, err := valueAsString(iniFile.Section("server"), "root_url", "")
So(err.Error(), ShouldEqual, "Invalid value for key 'root_url' in configuration file")
So(value, ShouldEqual, "")
})
})
}
[server]
root_url = %(protocol)s://%(domain)s:%(port)s/grafana/
alt_url = https://grafana.com/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment