{"record":{"id":"e5eccf6151a5d515","repo":"rtk-ai/rtk","slug":"trae-pretooluse-value-is-not-an-array","errorCode":null,"errorMessage":"Trae PreToolUse value is not an array","messagePattern":"Trae PreToolUse value is not an array","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/hooks/init.rs","lineNumber":5109,"sourceCode":"        .context(\"Trae hooks.json root must be an object\")?;\n    if root_object\n        .get(\"version\")\n        .is_some_and(|version| version != &serde_json::json!(1))\n    {\n        anyhow::bail!(\"Trae hooks.json version must be 1\");\n    }\n    if root_object\n        .get(\"hooks\")\n        .is_some_and(|hooks| !hooks.is_object())\n    {\n        anyhow::bail!(\"Trae hooks value is not an object\");\n    }\n    if root_object\n        .get(\"hooks\")\n        .and_then(|hooks| hooks.get(PRE_TOOL_USE_KEY))\n        .is_some_and(|pre_tool_use| !pre_tool_use.is_array())\n    {\n        anyhow::bail!(\"Trae PreToolUse value is not an array\");\n    }\n    Ok(())\n}\n\n/// Install RTK's Trae hook in every supplied target. All targets are read and\n/// parsed before any write, so malformed `.trae` or `.trae-cn` configuration\n/// cannot cause a partially-applied update.\nfn patch_trae_hooks_json_paths(paths: &[PathBuf], ctx: InitContext) -> Result<Vec<PatchResult>> {\n    struct PendingPatch {\n        path: PathBuf,\n        existed: bool,\n        serialized: String,\n    }\n\n    let mut results = Vec::with_capacity(paths.len());\n    let mut pending = Vec::new();\n    let mut applied: Vec<String> = Vec::new();\n","sourceCodeStart":5091,"sourceCodeEnd":5127,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/hooks/init.rs#L5091-L5127","documentation":"Trae hooks.json validation step three: if the `hooks` object contains a PreToolUse entry (`PRE_TOOL_USE_KEY`), its value must be a JSON array of hook commands. If it exists with another type (object, string, number), rtk bails because it appends its hook to that array and cannot merge into any other shape.","triggerScenarios":"Running `rtk init` for Trae where existing `.trae/hooks.json` has `hooks.PreToolUse` present but not an array (e.g. a single object instead of an array of hook entries).","commonSituations":"User or another tool wrote PreToolUse as a single hook object instead of an array; hand-edit flattened the list; template copied from a tool with a different hooks schema.","solutions":["Wrap the PreToolUse value in an array: `\"PreToolUse\": [<existing-hook>]`.","If unsure, back up the file, remove the PreToolUse key, and rerun `rtk init` so rtk writes a correct array entry.","Validate the JSON structure against a known-good Trae hooks.json before rerunning."],"exampleFix":"// before (.trae/hooks.json)\n{ \"version\": 1, \"hooks\": { \"PreToolUse\": { \"command\": \"foo\" } } }\n// after\n{ \"version\": 1, \"hooks\": { \"PreToolUse\": [ { \"command\": \"foo\" } ] } }","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction preToolUseIsArray(p = '.trae/hooks.json') {\n  if (!fs.existsSync(p)) return true;\n  const j = JSON.parse(fs.readFileSync(p, 'utf8'));\n  const v = j?.hooks?.PreToolUse;\n  return v === undefined || Array.isArray(v);\n}","typeGuard":"const preToolUseOk = (j) => j?.hooks?.PreToolUse === undefined || Array.isArray(j.hooks.PreToolUse);","tryCatchPattern":"match rtk init result { Err if msg contains 'PreToolUse value is not an array' => wrap the value in an array and retry }","preventionTips":["Always model PreToolUse as an array of hook objects, even for a single hook.","Lint .trae config files in CI with a structural check.","Reset to `{\"version\":1,\"hooks\":{}}` and let rtk init write the hook when unsure."],"tags":["json","schema-validation","trae","hooks"],"backgroundTag":"schema-validation-failed","analyzedSha":"0924356b4caba4989607227b7c8824d3d8098719","analyzedAt":"2026-09-19T19:25:29.612Z","contentChangedAt":"2026-09-19T19:25:29.612Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}