mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-15 10:40:41 -07:00
Merge pull request #769 from nats-io/config-report-pos-always
Include source of configuration error by default
This commit is contained in:
File diff suppressed because it is too large
Load Diff
70
server/configs/multiple_errors.conf
Normal file
70
server/configs/multiple_errors.conf
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
authorization {
|
||||
user = foo
|
||||
pass = bar
|
||||
token = quux
|
||||
}
|
||||
|
||||
http_port = 8222
|
||||
|
||||
monitoring = 8222
|
||||
|
||||
write_deadline = 5
|
||||
|
||||
accounts {
|
||||
synadia {
|
||||
exports = [
|
||||
{ stream: "synadia.>" }
|
||||
]
|
||||
|
||||
# Malformed nkeys
|
||||
nkey = "OC5GRL36RQV7MJ2GT6WQSCKDKJKYTK4T2LGLWJ2SEJKRDHFOQQWGGFQL"
|
||||
|
||||
users [
|
||||
{
|
||||
# Malformed nkeys
|
||||
nkey = "OCARKS2E3KVB7YORL2DG34XLT7PUCOL2SVM7YXV6ETHLW6Z46UUJ2VZ3"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
#
|
||||
# + nats < synadia
|
||||
#
|
||||
nats {
|
||||
# Malformed nkeys
|
||||
nkey = "ODRZ42QBM7SXQDXXTSVWT2WLLFYOQGAFC4TO6WOAXHEKQHIXR4HFYJDS"
|
||||
|
||||
users [
|
||||
{
|
||||
# Malformed nkeys
|
||||
nkey = "OD6AYQSOIN2IN5OGC6VQZCR4H3UFMIOXSW6NNS6N53CLJA4PB56CEJJI"
|
||||
}
|
||||
]
|
||||
|
||||
imports = [
|
||||
{ stream: { account: "synadia", subject: "synadia.>" }, prefix: "imports.nats" }
|
||||
]
|
||||
}
|
||||
|
||||
# + cncf < synadia
|
||||
cncf {
|
||||
nkey = "AD4YRVUJF2KASKPGRMNXTYKIYSCB3IHHB4Y2ME6B2PDIV5QJ23C2ZRIT"
|
||||
|
||||
users [
|
||||
{
|
||||
nkey = "UB57IEMPG4KOTPFV5A66QKE2HZ3XBXFHVRCCVMJEWKECMVN2HSH3VTSJ"
|
||||
}
|
||||
]
|
||||
|
||||
imports = [
|
||||
{ stream: { account: "synadia", subject: "synadia.>" }, prefix: "imports.cncf" }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
cluster {
|
||||
authorization {
|
||||
users = []
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,10 @@
|
||||
|
||||
package server
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrConnectionClosed represents an error condition on a closed connection.
|
||||
@@ -68,3 +71,73 @@ var (
|
||||
// ErrServiceImportAuthorization is returned when a service import is not authorized.
|
||||
ErrServiceImportAuthorization = errors.New("Service Import Not Authorized")
|
||||
)
|
||||
|
||||
// configErr is a configuration error.
|
||||
type configErr struct {
|
||||
token token
|
||||
reason string
|
||||
}
|
||||
|
||||
// Source reports the location of a configuration error.
|
||||
func (e *configErr) Source() string {
|
||||
return fmt.Sprintf("%s:%d:%d", e.token.SourceFile(), e.token.Line(), e.token.Position())
|
||||
}
|
||||
|
||||
// Error reports the location and reason from a configuration error.
|
||||
func (e *configErr) Error() string {
|
||||
if e.token != nil {
|
||||
return fmt.Sprintf("%s: %s", e.Source(), e.reason)
|
||||
}
|
||||
return e.reason
|
||||
}
|
||||
|
||||
// unknownConfigFieldErr is an error reported in pedantic mode.
|
||||
type unknownConfigFieldErr struct {
|
||||
configErr
|
||||
field string
|
||||
}
|
||||
|
||||
// Error reports that an unknown field was in the configuration.
|
||||
func (e *unknownConfigFieldErr) Error() string {
|
||||
return fmt.Sprintf("%s: unknown field %q", e.Source(), e.field)
|
||||
}
|
||||
|
||||
// configWarningErr is an error reported in pedantic mode.
|
||||
type configWarningErr struct {
|
||||
configErr
|
||||
field string
|
||||
}
|
||||
|
||||
// Error reports a configuration warning.
|
||||
func (e *configWarningErr) Error() string {
|
||||
return fmt.Sprintf("%s: invalid use of field %q: %s", e.Source(), e.field, e.reason)
|
||||
}
|
||||
|
||||
// processConfigErr is the result of processing the configuration from the server.
|
||||
type processConfigErr struct {
|
||||
errors []error
|
||||
warnings []error
|
||||
}
|
||||
|
||||
// Error returns the collection of errors separated by new lines,
|
||||
// warnings appear first then hard errors.
|
||||
func (e *processConfigErr) Error() string {
|
||||
var msg string
|
||||
for _, err := range e.Warnings() {
|
||||
msg += err.Error() + "\n"
|
||||
}
|
||||
for _, err := range e.Errors() {
|
||||
msg += err.Error() + "\n"
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
// Warnings returns the list of warnings.
|
||||
func (e *processConfigErr) Warnings() []error {
|
||||
return e.warnings
|
||||
}
|
||||
|
||||
// Errors returns the list of errors.
|
||||
func (e *processConfigErr) Errors() []error {
|
||||
return e.errors
|
||||
}
|
||||
|
||||
772
server/opts.go
772
server/opts.go
File diff suppressed because it is too large
Load Diff
@@ -1274,7 +1274,9 @@ func TestClusterPermissionsConfig(t *testing.T) {
|
||||
defer os.Remove(conf)
|
||||
opts, err := ProcessConfigFile(conf)
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing config file: %v", err)
|
||||
if cerr, ok := err.(*processConfigErr); ok && len(cerr.Errors()) > 0 {
|
||||
t.Fatalf("Error processing config file: %v", err)
|
||||
}
|
||||
}
|
||||
if opts.Cluster.Permissions == nil {
|
||||
t.Fatal("Expected cluster permissions to be set")
|
||||
|
||||
Reference in New Issue
Block a user