diff --git a/instance.go b/instance.go index 18eab97..4d16511 100644 --- a/instance.go +++ b/instance.go @@ -260,6 +260,11 @@ func (i *Instance) managerSysProc() (*syscall.SysProcAttr, error) { mgr, _, err := i.DetermineManager() if err != nil { + var pIscErr *ParametersISCNotExistError + if errors.As(err, &pIscErr) { + log.WithError(pIscErr).Debug("cannot determine manager") + return nil, nil + } return nil, err } @@ -644,11 +649,27 @@ func (i *Instance) ExecuteString(namespace string, code string) (string, error) return i.Execute(namespace, b) } +type ParametersISCNotExistError struct { + dir string + err error +} + +func (e *ParametersISCNotExistError) Error() string { + return fmt.Sprintf("parameters.isc not found in %s. err: %s", e.dir, e.err.Error()) +} + +func (e *ParametersISCNotExistError) Unwrap() error { + return e.err +} + // ReadParametersISC will read the current instances parameters ISC file into a simple data structure. // It returns the ParametersISC data structure and any error encountered. func (i *Instance) ReadParametersISC() (ParametersISC, error) { f, err := parameterReader(i.Directory, iscParametersFile) if err != nil { + if errors.Is(err, os.ErrNotExist) { + return nil, &ParametersISCNotExistError{dir: i.Directory, err: err} + } return nil, err } defer f.Close() diff --git a/instance_test.go b/instance_test.go index ab5b780..5ace185 100644 --- a/instance_test.go +++ b/instance_test.go @@ -21,6 +21,7 @@ import ( "context" "fmt" "io" + "os" "os/user" "syscall" "time" @@ -192,6 +193,7 @@ var _ = Describe("Instance", func() { }) }) }) + Describe("DetermineISCDatFileName", func() { Context("The product is Cache", func() { It("Returns the correct DAT filename", func() { @@ -550,4 +552,23 @@ var _ = Describe("Instance", func() { }) }) }) + + Describe("Update", func() { + // To test instance updates when running somewhere that doesn't actually have access to the + // parameters.isc file, such as `iscenv` wrapping `csession` or `iris` + Context("Valid qlist without parameters.isc", func() { + BeforeEach(func() { + parameterReader = func(directory string, file string) (io.ReadCloser, error) { + return nil, os.ErrNotExist + } + instance, err = InstanceFromQList(cacheqlist) + Expect(err).ToNot(HaveOccurred()) + }) + + It("Does not return an error", func() { + err := instance.Update() + Expect(err).NotTo(HaveOccurred()) + }) + }) + }) })