googleapis/mcp-toolbox · error
invalid segment at position %d (%s): %w
Error message
invalid segment at position %d (%s): %w
What it means
Wrap in the shared Firestore path validator: one specific segment failed segment-level validation; the position, the segment text, and the wrapped reason (empty, whitespace, '.'/'..', or reserved '__' prefix) are included.
Source
Thrown at internal/tools/firestore/util/validator.go:92
if len(segments) == 0 {
return fmt.Errorf("%s path cannot be empty or contain only slashes", pathTypeName)
}
// Check segment count based on path type
segmentCount := len(segments)
if pathType == CollectionPath && segmentCount%2 == 0 {
// Collection paths must have an odd number of segments
return fmt.Errorf("invalid collection path: must have an odd number of segments (e.g., 'collection' or 'collection/doc/subcollection'), got %d segments", segmentCount)
} else if pathType == DocumentPath && segmentCount%2 != 0 {
// Document paths must have an even number of segments
return fmt.Errorf("invalid document path: must have an even number of segments (e.g., 'collection/doc'), got %d segments", segmentCount)
}
// Validate each segment
for i, segment := range segments {
isCollectionSegment := (i % 2) == 0
if err := validateSegment(segment, isCollectionSegment); err != nil {
return fmt.Errorf("invalid segment at position %d (%s): %w", i+1, segment, err)
}
}
return nil
}
// validateSegment validates a single path segment
func validateSegment(segment string, isCollection bool) error {
segmentType := "document ID"
if isCollection {
segmentType = "collection ID"
}
// Check for empty segment
if segment == "" {
return fmt.Errorf("segment cannot be empty")
}
View on GitHub (pinned to 8cc6e09de2)
Solutions
- Fix the segment at the reported position per the wrapped reason
- Avoid empty segments (double slashes), whitespace, dot segments, and '__'-prefixed names
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/tools/firestore/util/validator.go:92 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/b3bfef55cfb49403.
Report an issue: GitHub.