Skip to content

Commit

Permalink
home: imp err msg
Browse files Browse the repository at this point in the history
  • Loading branch information
schzhn committed Jun 21, 2023
1 parent 29cfc7a commit 304389a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion internal/home/clients.go
Expand Up @@ -212,7 +212,7 @@ func (clients *clientsContainer) addFromConfig(

err = o.BlockedServices.Validate()
if err != nil {
return fmt.Errorf("clients: %w", err)
return fmt.Errorf("clients: init client blocked services %q: %w", cli.Name, err)
}

cli.BlockedServices = o.BlockedServices.Clone()
Expand Down
10 changes: 2 additions & 8 deletions internal/home/dns.go
Expand Up @@ -414,15 +414,9 @@ func applyAdditionalFiltering(clientIP net.IP, clientID string, setts *filtering
log.Debug("%s: using settings for client %q (%s; %q)", pref, c.Name, clientIP, clientID)

if c.UseOwnBlockedServices {
// TODO(e.burkov): Get rid of this crutch.
svcs := c.BlockedServices.IDs
if svcs == nil {
svcs = []string{}
}

if !c.BlockedServices.Schedule.Contains(time.Now()) {
Context.filters.ApplyBlockedServicesList(setts, svcs)
log.Debug("%s: services for client %q set: %s", pref, c.Name, svcs)
Context.filters.ApplyBlockedServicesList(setts, c.BlockedServices.IDs)
log.Debug("%s: services for client %q set: %s", pref, c.Name, c.BlockedServices.IDs)
}
}

Expand Down
17 changes: 10 additions & 7 deletions internal/home/upgrade.go
Expand Up @@ -1197,7 +1197,7 @@ func upgradeSchema20to21(diskConf yobj) (err error) {
// 'schedule':
// 'time_zone': 'Local'
func upgradeSchema21to22(diskConf yobj) (err error) {
log.Printf("Upgrade yaml: 21 to 22")
log.Println("Upgrade yaml: 21 to 22")
diskConf["schema_version"] = 22

const field = "blocked_services"
Expand All @@ -1223,18 +1223,21 @@ func upgradeSchema21to22(diskConf yobj) (err error) {
}

for _, val := range persistent {
c, k := val.(yobj)
if !k {
var c yobj
c, ok = val.(yobj)
if !ok {
return fmt.Errorf("unexpected type of client: %T", val)
}

blockedVal, k := c[field]
if !k {
var blockedVal any
blockedVal, ok = c[field]
if !ok {
continue
}

services, k := blockedVal.(yarr)
if !k {
var services yarr
services, ok = blockedVal.(yarr)
if !ok {
return fmt.Errorf("unexpected type of blocked: %T", blockedVal)
}

Expand Down

0 comments on commit 304389a

Please sign in to comment.