Skip to content

Commit

Permalink
🐛 revert error on non-existent package, service, and kernel.module
Browse files Browse the repository at this point in the history
This is in line with v8 and would otherwise break a number of existing queries. It is inconsistent with a few other resources (like `user`) and needs further alignment (as descriped in #1622)

Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus committed Sep 18, 2023
1 parent 72b59e2 commit cb5af62
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
7 changes: 6 additions & 1 deletion providers/os/resources/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,12 @@ func initKernelModule(runtime *plugin.Runtime, args map[string]*llx.RawData) (ma
if res, ok := kernel.moduleByName[name]; ok {
return nil, res, nil
}
return args, nil, nil

res := &mqlKernelModule{}
res.Name = plugin.TValue[string]{Data: name, State: plugin.StateIsSet}
res.Size.State = plugin.StateIsSet | plugin.StateIsNull
res.Loaded = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet}
return nil, res, nil
}

func (k *mqlKernelModule) id() (string, error) {
Expand Down
19 changes: 15 additions & 4 deletions providers/os/resources/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,23 @@ func initPackage(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[str
return nil, nil, err
}

x, found := packages.packagesByName[name]
if !found {
return nil, nil, errors.New("cannot find package " + name)
if res, ok := packages.packagesByName[name]; ok {
return nil, res, nil
}

return nil, x, nil
res := &mqlPackage{}
res.Name = plugin.TValue[string]{Data: name, State: plugin.StateIsSet}
res.Installed = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet}
res.Outdated = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet}
res.Version.State = plugin.StateIsSet | plugin.StateIsNull
res.Epoch.State = plugin.StateIsSet | plugin.StateIsNull
res.Available.State = plugin.StateIsSet | plugin.StateIsNull
res.Description.State = plugin.StateIsSet | plugin.StateIsNull
res.Arch.State = plugin.StateIsSet | plugin.StateIsNull
res.Format.State = plugin.StateIsSet | plugin.StateIsNull
res.Origin.State = plugin.StateIsSet | plugin.StateIsNull
res.Status.State = plugin.StateIsSet | plugin.StateIsNull
return nil, res, nil
}

func (p *mqlPackage) status() (string, error) {
Expand Down
15 changes: 11 additions & 4 deletions providers/os/resources/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ func initService(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[str
return nil, nil, err
}

srv := services.namedServices[name]
if srv == nil {
return nil, nil, errors.New("service '" + name + "' does not exist")
if srv, ok := services.namedServices[name]; ok {
return nil, srv, nil
}

return nil, srv, nil
res := &mqlService{}
res.Name = plugin.TValue[string]{Data: name, State: plugin.StateIsSet}
res.Description.State = plugin.StateIsSet | plugin.StateIsNull
res.Installed = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet}
res.Running = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet}
res.Enabled = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet}
res.Type.State = plugin.StateIsSet | plugin.StateIsNull
res.Enabled = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet}
return nil, res, nil
}

func (x *mqlService) id() (string, error) {
Expand Down

0 comments on commit cb5af62

Please sign in to comment.