2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 01:57:19 +08:00

feat: 优化nginx解析器错误返回

This commit is contained in:
2025-04-14 15:46:11 +08:00
parent 99eb46c2a9
commit 044b3664ed

View File

@@ -2,6 +2,7 @@ package nginx
import (
"errors"
"fmt"
"slices"
"strings"
@@ -49,7 +50,7 @@ func (p *Parser) Find(key string) ([]config.IDirective, error) {
key = parts[i]
directives := block.FindDirectives(key)
if len(directives) == 0 {
return nil, errors.New("given key not found")
return nil, fmt.Errorf("given key %s not found", key)
}
if len(directives) > 1 {
return nil, errors.New("multiple directives found")
@@ -78,7 +79,7 @@ func (p *Parser) FindOne(key string) (config.IDirective, error) {
return nil, err
}
if len(directives) == 0 {
return nil, errors.New("given key not found")
return nil, fmt.Errorf("given key %s not found", key)
}
return directives[0], nil
@@ -97,10 +98,10 @@ func (p *Parser) Clear(key string) error {
for i := 0; i < len(parts); i++ {
directives := block.FindDirectives(parts[i])
if len(directives) == 0 {
return errors.New("given key not found")
return fmt.Errorf("given key %s not found", parts[i])
}
if len(directives) > 1 {
return errors.New("multiple directives found")
return fmt.Errorf("multiple directives found for %s", parts[i])
}
block, ok = directives[0].GetBlock().(*config.Block)
if !ok {
@@ -131,10 +132,10 @@ func (p *Parser) Set(key string, directives []*config.Directive) error {
for i := 0; i < len(parts); i++ {
sub := block.FindDirectives(parts[i])
if len(sub) == 0 {
return errors.New("given key not found")
return fmt.Errorf("given key %s not found", parts[i])
}
if len(sub) > 1 {
return errors.New("multiple directives found")
return fmt.Errorf("multiple directives found for %s", parts[i])
}
block, ok = sub[0].GetBlock().(*config.Block)
if !ok {