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 committed 2026-08-19 11:35:29 -07:00
1 parent f5243689a5
commit 70e2e30a18
3 files changed
+3 -6

No files matched your search

+1 -2
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) {
+1 -2
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
}
}
+1 -2
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")
}
})