{"record":{"id":"4bb3c822b31ee7fd","repo":"jdx/mise","slug":"glob-pattern-expands-to-more-than-max-brace-expan","errorCode":null,"errorMessage":"glob pattern expands to more than {MAX_BRACE_EXPANSIONS} alternatives: {pattern:?}","messagePattern":"glob pattern expands to more than (.+?) alternatives: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/task/task_source_checker.rs","lineNumber":145,"sourceCode":"                            return Ok(Some(nested));\n                        }\n                        group_start = None;\n                        branches.clear();\n                    }\n                }\n                _ => {}\n            }\n        }\n        if group_depth != 0 {\n            bail!(\"unclosed brace alternate in glob pattern {pattern:?}\");\n        }\n        Ok(None)\n    }\n\n    fn expand(pattern: &str, expanded: &mut Vec<String>) -> Result<()> {\n        let Some(group) = find_group(pattern)? else {\n            if expanded.len() >= MAX_BRACE_EXPANSIONS {\n                bail!(\n                    \"glob pattern expands to more than {MAX_BRACE_EXPANSIONS} alternatives: {pattern:?}\"\n                );\n            }\n            let mut literal = String::with_capacity(pattern.len());\n            let mut escaped = false;\n            let mut class_depth = 0;\n            for ch in pattern.chars() {\n                if escaped {\n                    escaped = false;\n                    literal.push(ch);\n                    continue;\n                }\n                if ch == '\\\\' && !cfg!(windows) {\n                    escaped = true;\n                    literal.push(ch);\n                    continue;\n                }\n                match ch {","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/task/task_source_checker.rs#L127-L163","documentation":"To bound memory/work, mise caps brace expansion at MAX_BRACE_EXPANSIONS alternatives. When expand() is about to record more alternatives than the cap (deeply or multiply nested brace groups), it bails instead of expanding, protecting against glob-bomb style inputs.","triggerScenarios":"Using a task glob whose brace groups multiply past the cap, e.g. `{a,b}/{a,b}/{a,b}/...` with enough nesting that the product of alternatives exceeds MAX_BRACE_EXPANSIONS.","commonSituations":"Auto-generated globs from many targets/flavors in task sources or outputs; accidentally writing nested alternations meant to be separate patterns; combinatorial matrices in monorepo task definitions.","solutions":["Split the giant glob into several smaller explicit patterns in the list","Reduce nesting depth of brace groups (flatten the product manually)","Replace alternations with wildcards where acceptable (e.g. `src/**` instead of enumerating)","Generate the explicit file list via a task script instead of one glob"],"exampleFix":"// before\nsources = [\"{a,b}/{a,b}/{a,b}/{a,b}/{a,b}/{a,b}/{a,b}/{a,b}/*.txt\"]\n// after\nsources = [\"a/**/*.txt\", \"b/**/*.txt\"]","handlingStrategy":"validation","validationCode":"python3 -c \"import sys,math;p=sys.argv[1];n=1;d=0\nfor c in p:\n  if c=='{': d+=1\n  elif c=='}': d-=1\n  elif c==',' and d==1: n+=1\nprint(n)\" \"$GLOB\"","typeGuard":null,"tryCatchPattern":"alts=$(python3 count_alts.py \"$GLOB\"); [ \"$alts\" -lt 100 ] && mise run build || { echo 'too many alternatives; split pattern' >&2; exit 1; }","preventionTips":["Avoid deeply nested brace groups","Split combinatorial globs into explicit pattern lists","Prefer wildcards over enumerating all variants","Generate file lists via scripts instead of giant globs"],"tags":["glob","tasks","limits"],"backgroundTag":"value-out-of-range","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}