aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorMichal Siedlaczek <michal@siedlaczek.me>2024-01-25 17:21:11 -0500
committerRobin Jarry <robin@jarry.cc>2024-01-25 23:32:56 +0100
commit0a0ab6da9e2644371041c4246eac91f9fa18514f (patch)
treebc90370ce644bc7a3316ed1463d94985e7e1d625 /config
parent21f38698bd58b796e53ed5e9f8f11925f48331b3 (diff)
downloadaerc-0a0ab6da9e2644371041c4246eac91f9fa18514f.tar.gz
config: print file path in error message
In case of a config parsing error, print the file path of the file in which the error occurred. Fixes: https://todo.sr.ht/~rjarry/aerc/218 Signed-off-by: Michal Siedlaczek <michal@siedlaczek.me> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'config')
-rw-r--r--config/accounts.go32
-rw-r--r--config/binds.go29
-rw-r--r--config/config.go44
3 files changed, 63 insertions, 42 deletions
diff --git a/config/accounts.go b/config/accounts.go
index 1afa77c4..ac0a5444 100644
--- a/config/accounts.go
+++ b/config/accounts.go
@@ -120,18 +120,7 @@ const (
var Accounts []*AccountConfig
-func parseAccounts(root string, accts []string, filename string) error {
- if filename == "" {
- filename = path.Join(root, "accounts.conf")
- err := checkConfigPerms(filename)
- if errors.Is(err, os.ErrNotExist) {
- // No config triggers account configuration wizard
- return nil
- } else if err != nil {
- return err
- }
- }
-
+func parseAccountsFromFile(root string, accts []string, filename string) error {
log.Debugf("Parsing accounts configuration from %s", filename)
file, err := ini.LoadSources(ini.LoadOptions{
@@ -188,6 +177,25 @@ If you want to disable STARTTLS, append +insecure to the schema.
return nil
}
+func parseAccounts(root string, accts []string, filename string) error {
+ if filename == "" {
+ filename = path.Join(root, "accounts.conf")
+ err := checkConfigPerms(filename)
+ if errors.Is(err, os.ErrNotExist) {
+ // No config triggers account configuration wizard
+ return nil
+ } else if err != nil {
+ return err
+ }
+ }
+
+ if err := parseAccountsFromFile(root, accts, filename); err != nil {
+ return fmt.Errorf("%s: %w", filename, err)
+ }
+
+ return nil
+}
+
func ParseAccountConfig(name string, section *ini.Section) (*AccountConfig, error) {
account := AccountConfig{
Name: name,
diff --git a/config/binds.go b/config/binds.go
index bedc6d9a..b65aa1ab 100644
--- a/config/binds.go
+++ b/config/binds.go
@@ -101,16 +101,7 @@ func defaultBindsConfig() *BindingConfig {
var Binds = defaultBindsConfig()
-func parseBinds(root string, filename string) error {
- if filename == "" {
- filename = path.Join(root, "binds.conf")
- if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) {
- fmt.Printf("%s not found, installing the system default\n", filename)
- if err := installTemplate(root, "binds.conf"); err != nil {
- return err
- }
- }
- }
+func parseBindsFromFile(root string, filename string) error {
log.Debugf("Parsing key bindings configuration from %s", filename)
binds, err := ini.LoadSources(ini.LoadOptions{
KeyValueDelimiters: "=",
@@ -155,6 +146,24 @@ func parseBinds(root string, filename string) error {
return nil
}
+func parseBinds(root string, filename string) error {
+ if filename == "" {
+ filename = path.Join(root, "binds.conf")
+ if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) {
+ fmt.Printf("%s not found, installing the system default\n", filename)
+ if err := installTemplate(root, "binds.conf"); err != nil {
+ return err
+ }
+ }
+ }
+
+ if err := parseBindsFromFile(root, filename); err != nil {
+ return fmt.Errorf("%s: %w", filename, err)
+ }
+
+ return nil
+}
+
func LoadBindingSection(sec *ini.Section) (*KeyBindings, error) {
bindings := NewKeyBindings()
for key, value := range sec.KeysHash() {
diff --git a/config/config.go b/config/config.go
index 1efbf896..61ac041e 100644
--- a/config/config.go
+++ b/config/config.go
@@ -77,31 +77,13 @@ func installTemplate(root, name string) error {
return nil
}
-func LoadConfigFromFile(
- root *string, accts []string, filename, bindPath, acctPath string,
-) error {
- if root == nil {
- _root := xdg.ConfigPath("aerc")
- root = &_root
- }
- if filename == "" {
- filename = path.Join(*root, "aerc.conf")
- // if it doesn't exist copy over the template, then load
- if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) {
- fmt.Printf("%s not found, installing the system default\n", filename)
- if err := installTemplate(*root, "aerc.conf"); err != nil {
- return err
- }
- }
- }
-
+func parseConf(filename string) error {
file, err := ini.LoadSources(ini.LoadOptions{
KeyValueDelimiters: "=",
}, filename)
if err != nil {
return err
}
-
if err := parseGeneral(file); err != nil {
return err
}
@@ -132,13 +114,35 @@ func LoadConfigFromFile(
if err := parseTemplates(file); err != nil {
return err
}
+ return nil
+}
+
+func LoadConfigFromFile(
+ root *string, accts []string, filename, bindPath, acctPath string,
+) error {
+ if root == nil {
+ _root := xdg.ConfigPath("aerc")
+ root = &_root
+ }
+ if filename == "" {
+ filename = path.Join(*root, "aerc.conf")
+ // if it doesn't exist copy over the template, then load
+ if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) {
+ fmt.Printf("%s not found, installing the system default\n", filename)
+ if err := installTemplate(*root, "aerc.conf"); err != nil {
+ return err
+ }
+ }
+ }
+ if err := parseConf(filename); err != nil {
+ return fmt.Errorf("%s: %w", filename, err)
+ }
if err := parseAccounts(*root, accts, acctPath); err != nil {
return err
}
if err := parseBinds(*root, bindPath); err != nil {
return err
}
-
return nil
}