Skip to content

Commit 34bbbc8

Browse files
[FIX] config manager bugs and improve error handling
1 parent e6791f0 commit 34bbbc8

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

config/core.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,5 +350,5 @@ func Changed(o, n any) bool {
350350
func (m *manager) set(appConfig Config) {
351351
mutex.Lock()
352352
defer mutex.Unlock()
353-
cm.config = appConfig
353+
m.config = appConfig
354354
}

config/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (m *manager) watch(onChange func(fsnotify.Event)) error {
7070
}
7171
}()
7272

73-
return m.watcher.Add(configFile)
73+
return m.watcher.Add(filepath.Clean(filepath.Dir(configFile)))
7474
}
7575

7676
// save saves the configuration to the file

config/unmarshal.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,33 +151,38 @@ func setFieldValue(field reflect.Value, value interface{}) error {
151151
}
152152
// Handle signed integers from YAML (convert to unsigned if non-negative)
153153
if i, ok := value.(int); ok {
154-
if i >= 0 {
155-
field.SetUint(uint64(i))
154+
if i < 0 {
155+
return fmt.Errorf("negative integer %d cannot be converted to unsigned", i)
156156
}
157+
field.SetUint(uint64(i))
157158
return nil
158159
}
159160
if i, ok := value.(int64); ok {
160-
if i >= 0 {
161-
field.SetUint(uint64(i))
161+
if i < 0 {
162+
return fmt.Errorf("negative integer %d cannot be converted to unsigned", i)
162163
}
164+
field.SetUint(uint64(i))
163165
return nil
164166
}
165167
if i, ok := value.(int32); ok {
166-
if i >= 0 {
167-
field.SetUint(uint64(i))
168+
if i < 0 {
169+
return fmt.Errorf("negative integer %d cannot be converted to unsigned", i)
168170
}
171+
field.SetUint(uint64(i))
169172
return nil
170173
}
171174
if i, ok := value.(int16); ok {
172-
if i >= 0 {
173-
field.SetUint(uint64(i))
175+
if i < 0 {
176+
return fmt.Errorf("negative integer %d cannot be converted to unsigned", i)
174177
}
178+
field.SetUint(uint64(i))
175179
return nil
176180
}
177181
if i, ok := value.(int8); ok {
178-
if i >= 0 {
179-
field.SetUint(uint64(i))
182+
if i < 0 {
183+
return fmt.Errorf("negative integer %d cannot be converted to unsigned", i)
180184
}
185+
field.SetUint(uint64(i))
181186
return nil
182187
}
183188
if str, ok := value.(string); ok {

web/jrpc/jrpc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ var (
9494
errRequestMustBePointer = apperror.NewError("request must be a pointer")
9595
errNilRequest = apperror.NewError("nil request")
9696
errExpectedProtoMessage = apperror.NewError("expected proto.Message for request")
97+
errExpectedError = apperror.NewError("expected error type in method return value")
9798

9899
// Cached reflection types to avoid repeated type operations
99100
contextType = reflect.TypeOf((*context.Context)(nil)).Elem()
@@ -540,7 +541,7 @@ func (s *Service) call(ctx context.Context, service, method string, req proto.Me
540541
var ok bool
541542
err, ok = e.(error)
542543
if !ok {
543-
return nil, errExpectedProtoMessage
544+
return nil, errExpectedError
544545
}
545546
}
546547

0 commit comments

Comments
 (0)