Skip to content

Commit

Permalink
allow the error handling function to return better error message
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <[email protected]>
  • Loading branch information
vsoch committed Dec 22, 2023
1 parent 0b70113 commit c6edf43
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ RUN apt-get update \
RUN groupadd -g ${USER_GID} ${USERNAME} && \
adduser --disabled-password --uid ${USER_UID} --gid ${USER_GID} --gecos "" ${USERNAME} && \
echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers
USER $USERNAME

# TODO clone flux-sched here / just remove from build when we can?
17 changes: 9 additions & 8 deletions resource/reapi/bindings/go/src/fluxcli/reapi_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ func NewReapiClient() *ReapiClient {

// Given an integer return code, convert to go error
// Also provide a meaningful string to the developer user
func retvalToError(code int, message string) error {
func (cli *ReapiClient) retvalToError(code int, message string) error {
if code == 0 {
return nil
}
return fmt.Errorf(message+" %d", code)
msg := cli.GetErrMsg()
return fmt.Errorf(message+":%s %d", msg, code)
}

// HasContext exposes the private ctx, telling the caller if it is set
Expand Down Expand Up @@ -69,7 +70,7 @@ func (cli *ReapiClient) InitContext(jgf string, options string) (err error) {
),
)

return retvalToError(fluxerr, "issue initializing resource api client")
return cli.retvalToError(fluxerr, "issue initializing resource api client")
}

// MatchAllocate matches a jobspec to the "best" resources and either allocate
Expand Down Expand Up @@ -110,7 +111,7 @@ func (cli *ReapiClient) MatchAllocate(

allocated = C.GoString(r)

err = retvalToError(fluxerr, "issue resource api client matching allocate")
err = cli.retvalToError(fluxerr, "issue resource api client matching allocate")
return reserved, allocated, at, overhead, jobid, err

}
Expand Down Expand Up @@ -143,7 +144,7 @@ func (cli *ReapiClient) UpdateAllocate(jobid int, r string) (at int64, overhead

r_out = C.GoString(tmp_rout)

err = retvalToError(fluxerr, "issue resource api client updating allocate")
err = cli.retvalToError(fluxerr, "issue resource api client updating allocate")
return at, overhead, r_out, err
}

Expand All @@ -160,7 +161,7 @@ func (cli *ReapiClient) Cancel(jobid int64, noent_ok bool) (err error) {
fluxerr := (int)(C.reapi_cli_cancel((*C.struct_reapi_cli_ctx)(cli.ctx),
(C.ulong)(jobid),
(C.bool)(noent_ok)))
return retvalToError(fluxerr, "issue resource api client cancel")
return cli.retvalToError(fluxerr, "issue resource api client cancel")
}

// Info gets the information on the allocation or reservation corresponding to jobid
Expand Down Expand Up @@ -188,7 +189,7 @@ func (cli *ReapiClient) Info(jobid int64) (reserved bool, at int64, overhead flo
(*C.long)(&at),
(*C.double)(&overhead)))

err = retvalToError(fluxerr, "issue resource api client info")
err = cli.retvalToError(fluxerr, "issue resource api client info")
return reserved, at, overhead, C.GoString(tmp_mode), err
}

Expand Down Expand Up @@ -218,7 +219,7 @@ func (cli *ReapiClient) Stat() (v int64, e int64,
(*C.double)(&max),
(*C.double)(&avg)))

err = retvalToError(fluxerr, "issue resource api client stat")
err = cli.retvalToError(fluxerr, "issue resource api client stat")
return v, e, jobs, load, min, max, avg, err
}

Expand Down

0 comments on commit c6edf43

Please sign in to comment.