MCPcopy Create free account
hub / github.com/github/gh-aw / validateMountsSyntax

Function validateMountsSyntax

pkg/workflow/sandbox_validation.go:30–67  ·  view source on GitHub ↗

validateMountsSyntax validates that mount strings follow the correct syntax Expected format: "source:destination:mode" where mode is either "ro" or "rw"

(mounts []string)

Source from the content-addressed store, hash-verified

28// validateMountsSyntax validates that mount strings follow the correct syntax
29// Expected format: "source:destination:mode" where mode is either "ro" or "rw"
30func validateMountsSyntax(mounts []string) error {
31 return validateMountEntries(mounts, func(i int, parts mountParts) {
32 sandboxValidationLog.Printf("Validated mount %d: source=%s, dest=%s, mode=%s", i, parts.source, parts.dest, parts.mode)
33 }, func(i int, mount string, parts mountParts, kind mountValidationKind) error {
34 switch kind {
35 case mountValidationFormatError:
36 return NewValidationError(
37 fmt.Sprintf("sandbox.mounts[%d]", i),
38 mount,
39 "mount syntax must follow 'source:destination:mode' format with exactly 3 colon-separated parts",
40 fmt.Sprintf("Use the format 'source:destination:mode'.\n\nExample:\nsandbox:\n mounts:\n - \"/host/path:/container/path:ro\"\n\nSee: %s", constants.DocsSandboxURL),
41 )
42 case mountValidationModeError:
43 return NewValidationError(
44 fmt.Sprintf("sandbox.mounts[%d].mode", i),
45 parts.mode,
46 "mount mode must be 'ro' (read-only) or 'rw' (read-write)",
47 fmt.Sprintf("Change the mount mode to either 'ro' or 'rw'.\n\nExample:\nsandbox:\n mounts:\n - \"/host/path:/container/path:ro\" # read-only\n - \"/host/path:/container/path:rw\" # read-write\n\nSee: %s", constants.DocsSandboxURL),
48 )
49 case mountValidationEmptySource:
50 return NewValidationError(
51 fmt.Sprintf("sandbox.mounts[%d].source", i),
52 mount,
53 "source path cannot be empty",
54 fmt.Sprintf("Provide a valid source path.\n\nExample:\nsandbox:\n mounts:\n - \"/host/path:/container/path:ro\"\n\nSee: %s", constants.DocsSandboxURL),
55 )
56 case mountValidationEmptyDestination:
57 return NewValidationError(
58 fmt.Sprintf("sandbox.mounts[%d].destination", i),
59 mount,
60 "destination path cannot be empty",
61 fmt.Sprintf("Provide a valid destination path.\n\nExample:\nsandbox:\n mounts:\n - \"/host/path:/container/path:ro\"\n\nSee: %s", constants.DocsSandboxURL),
62 )
63 default:
64 return fmt.Errorf("internal error: unsupported mount validation kind %d for sandbox mount %q", kind, mount)
65 }
66 })
67}
68
69// validateSandboxConfig validates the sandbox configuration
70// Returns an error if the configuration is invalid

Callers 2

TestValidateMountsSyntaxFunction · 0.85
validateSandboxConfigFunction · 0.85

Calls 4

validateMountEntriesFunction · 0.85
NewValidationErrorFunction · 0.70
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 1

TestValidateMountsSyntaxFunction · 0.68