{"record":{"id":"c0a2d2784670667e","repo":"googleapis/mcp-toolbox","slug":"invalid-document-path-must-have-an-even-number-of","errorCode":null,"errorMessage":"invalid document path: must have an even number of segments (e.g., 'collection/doc'), got %d segments","messagePattern":"invalid document path: must have an even number of segments \\(e\\.g\\., 'collection/doc'\\), got (.+?) segments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/firestore/util/validator.go","lineNumber":85,"sourceCode":"\t\treturn fmt.Errorf(\"path must be relative (e.g., '%s'), not absolute (matching pattern: ^projects/[^/]+/databases/[^/]+/documents/)\", example)\n\t}\n\n\t// Split the path using strings.Split to preserve empty segments\n\tsegments := strings.Split(path, \"/\")\n\n\t// Check for empty result\n\tif len(segments) == 0 {\n\t\treturn fmt.Errorf(\"%s path cannot be empty or contain only slashes\", pathTypeName)\n\t}\n\n\t// Check segment count based on path type\n\tsegmentCount := len(segments)\n\tif pathType == CollectionPath && segmentCount%2 == 0 {\n\t\t// Collection paths must have an odd number of segments\n\t\treturn fmt.Errorf(\"invalid collection path: must have an odd number of segments (e.g., 'collection' or 'collection/doc/subcollection'), got %d segments\", segmentCount)\n\t} else if pathType == DocumentPath && segmentCount%2 != 0 {\n\t\t// Document paths must have an even number of segments\n\t\treturn fmt.Errorf(\"invalid document path: must have an even number of segments (e.g., 'collection/doc'), got %d segments\", segmentCount)\n\t}\n\n\t// Validate each segment\n\tfor i, segment := range segments {\n\t\tisCollectionSegment := (i % 2) == 0\n\t\tif err := validateSegment(segment, isCollectionSegment); err != nil {\n\t\t\treturn fmt.Errorf(\"invalid segment at position %d (%s): %w\", i+1, segment, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// validateSegment validates a single path segment\nfunc validateSegment(segment string, isCollection bool) error {\n\tsegmentType := \"document ID\"\n\tif isCollection {\n\t\tsegmentType = \"collection ID\"","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/firestore/util/validator.go#L67-L103","documentation":"Parity guard in the shared Firestore path validator: a document path must have an even number of segments (alternating collection/document pairs); an odd count means the path ends on a collection, not a document.","triggerScenarios":"Thrown at internal/tools/firestore/util/validator.go:85 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use an even-segment document path like 'users/alice'","Append the document ID if the path currently stops at a collection"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}