github.com/DataDog/datadog-agent/pkg/security/secl@v0.55.0-devel.0.20240517055856-10c4965fea94/model/errors.go (about)

     1  // Unless explicitly stated otherwise all files in this repository are licensed
     2  // under the Apache License Version 2.0.
     3  // This product includes software developed at Datadog (https://www.datadoghq.com/).
     4  // Copyright 2016-present Datadog, Inc.
     5  
     6  // Package model holds model related files
     7  package model
     8  
     9  import (
    10  	"errors"
    11  	"fmt"
    12  )
    13  
    14  var (
    15  	// ErrNotEnoughData is returned when the buffer is too small to unmarshal the event
    16  	ErrNotEnoughData = errors.New("not enough data")
    17  
    18  	// ErrNotEnoughSpace is returned when the provided buffer is too small to marshal the event
    19  	ErrNotEnoughSpace = errors.New("not enough space")
    20  
    21  	// ErrStringArrayOverflow returned when there is a string array overflow
    22  	ErrStringArrayOverflow = errors.New("string array overflow")
    23  
    24  	// ErrNonPrintable returned when a string contains non printable char
    25  	ErrNonPrintable = errors.New("non printable")
    26  
    27  	// ErrIncorrectDataSize is returned when the data read size doesn't correspond to the expected one
    28  	ErrIncorrectDataSize = errors.New("incorrect data size")
    29  )
    30  
    31  // ErrInvalidKeyPath is returned when inode or mountid are not valid
    32  type ErrInvalidKeyPath struct {
    33  	Inode   uint64
    34  	MountID uint32
    35  }
    36  
    37  func (e *ErrInvalidKeyPath) Error() string {
    38  	return fmt.Sprintf("invalid inode/mountID couple: %d/%d", e.Inode, e.MountID)
    39  }
    40  
    41  // ErrProcessMissingParentNode used when the lineage is incorrect in term of pid/ppid
    42  type ErrProcessMissingParentNode struct {
    43  	PID         uint32
    44  	PPID        uint32
    45  	ContainerID string
    46  }
    47  
    48  func (e *ErrProcessMissingParentNode) Error() string {
    49  	return fmt.Sprintf("parent node missing: PID(%d), PPID(%d), ID(%s)", e.PID, e.PPID, e.ContainerID)
    50  }
    51  
    52  // ErrProcessWrongParentNode used when the lineage is correct in term of pid/ppid but an exec parent is missing
    53  type ErrProcessWrongParentNode struct {
    54  	PID         uint32
    55  	PPID        uint32
    56  	ContainerID string
    57  }
    58  
    59  func (e *ErrProcessWrongParentNode) Error() string {
    60  	return fmt.Sprintf("wrong parent node: PID(%d), PPID(%d), ID(%s)", e.PID, e.PPID, e.ContainerID)
    61  }
    62  
    63  // ErrProcessIncompleteLineage used when the lineage is incorrect in term of pid/ppid
    64  type ErrProcessIncompleteLineage struct {
    65  	PID         uint32
    66  	PPID        uint32
    67  	ContainerID string
    68  }
    69  
    70  func (e *ErrProcessIncompleteLineage) Error() string {
    71  	return fmt.Sprintf("parent node missing: PID(%d), PPID(%d), ID(%s)", e.PID, e.PPID, e.ContainerID)
    72  }
    73  
    74  // ErrNoProcessContext defines an error for event without process context
    75  var ErrNoProcessContext = errors.New("process context not resolved")
    76  
    77  // ErrProcessBrokenLineage returned when a process lineage is broken
    78  type ErrProcessBrokenLineage struct {
    79  	Err error
    80  }
    81  
    82  // Unwrap implements the error interface
    83  func (e *ErrProcessBrokenLineage) Unwrap() error {
    84  	return e.Err
    85  }
    86  
    87  // Error implements the error interface
    88  func (e *ErrProcessBrokenLineage) Error() string {
    89  	return fmt.Sprintf("broken process lineage: %v", e.Err)
    90  }