1
0
mirror of https://github.com/opencontainers/runc.git synced 2026-10-23 19:49:01 +03:00

libct: use errors.AsType

Simplify error type inspection. For the benefits, see
e.g. https://antonz.org/accepted/errors-astype/.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2026-08-19 10:55:16 -07:00
parent f5243689a5
commit 70e2e30a18
3 changed files with 3 additions and 6 deletions

View File

@@ -1214,8 +1214,7 @@ func ignoreTerminateErrors(err error) error {
// The (*Cmd).Wait documentation says: "If the command fails to run
// or doesn't complete successfully, the error is of type *ExitError".
// Filter out such errors (like "exit status 1" or "signal: killed").
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
if _, ok := errors.AsType[*exec.ExitError](err); ok {
return nil
}
if errors.Is(err, os.ErrProcessDone) {

View File

@@ -49,8 +49,7 @@ func (p *restoredProcess) wait() (*os.ProcessState, error) {
// maybe use --exec-cmd in criu
err := p.cmd.Wait()
if err != nil {
var exitErr *exec.ExitError
if !errors.As(err, &exitErr) {
if _, ok := errors.AsType[*exec.ExitError](err); !ok {
return nil, err
}
}

View File

@@ -42,8 +42,7 @@ func testTransitions(t *testing.T, initialState containerState, valid []containe
if err == nil {
t.Fatal("transition should fail")
}
var stErr *stateTransitionError
if !errors.As(err, &stErr) {
if _, ok := errors.AsType[*stateTransitionError](err); !ok {
t.Fatal("expected stateTransitionError")
}
})