{"record":{"id":"76a32cb91404ca07","repo":"Tencent/WeKnora","slug":"memory-limit-cannot-be-negative","errorCode":null,"errorMessage":"memory limit cannot be negative","messagePattern":"memory limit cannot be negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sandbox/sandbox.go","lineNumber":382,"sourceCode":"// ValidateConfig validates sandbox configuration\nfunc ValidateConfig(config *Config) error {\n\tif config == nil {\n\t\treturn errors.New(\"config is nil\")\n\t}\n\n\tswitch config.Type {\n\tcase SandboxTypeDocker, SandboxTypeCube, SandboxTypeE2B, SandboxTypeDisabled:\n\t\t// Valid types\n\tdefault:\n\t\treturn errors.New(\"invalid sandbox type\")\n\t}\n\n\tif config.DefaultTimeout < 0 {\n\t\treturn errors.New(\"timeout cannot be negative\")\n\t}\n\n\tif config.MaxMemory < 0 {\n\t\treturn errors.New(\"memory limit cannot be negative\")\n\t}\n\n\tif config.MaxCPU < 0 {\n\t\treturn errors.New(\"CPU limit cannot be negative\")\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":364,"sourceCodeEnd":391,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/sandbox/sandbox.go#L364-L391","documentation":"ValidateConfig rejects a SandboxConfig whose MaxMemory is negative. Memory limits are non-negative byte counts; a negative value is meaningless and indicates a config or parsing mistake, so Manager creation fails.","triggerScenarios":"Passing a SandboxConfig with MaxMemory < 0 to NewManager or NewSessionBoundManager, e.g. from a negative number in a config file or a bad unit conversion / integer underflow.","commonSituations":"Entering '-512m' in a limits section; signed-int unit conversion that underflowed; copying an example with a flipped sign.","solutions":["Set MaxMemory to a non-negative byte count (0 = no limit), e.g. 512 << 20 for 512MiB.","Fix unit conversion/parsing code so memory values are parsed with checked/unsigned logic.","Validate MaxMemory >= 0 before constructing the Manager."],"exampleFix":"// before\ncfg.MaxMemory = -512 * 1024 * 1024\n// after\ncfg.MaxMemory = 512 * 1024 * 1024","handlingStrategy":"validation","validationCode":"if cfg.MaxMemory < 0 {\n    return fmt.Errorf(\"invalid sandbox config: MaxMemory=%d must be >= 0\", cfg.MaxMemory)\n}","typeGuard":null,"tryCatchPattern":"if err := sandbox.ValidateConfig(cfg); err != nil {\n    if strings.Contains(err.Error(), \"memory\") {\n        return fmt.Errorf(\"fix MaxMemory (got %d bytes)\", cfg.MaxMemory)\n    }\n    return err\n}","preventionTips":["Parse memory sizes with checked parsing (go-units style).","Keep memory limits as int64 byte counts; never subtract without clamping.","Document 0 = unlimited in config docs."],"tags":["go","sandbox","configuration","validation","memory"],"backgroundTag":"invalid-config-value","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}