hyperledger/fabric · error

invalid path: %s

Error message

invalid path: %s

What it means

The Java platform's ValidatePath parses the raw chaincode path as a URL; if url.Parse fails or returns nil, it returns 'invalid path: %s'. Unlike other platforms, the path must at least be a parseable URI.

Source

Thrown at core/chaincode/platforms/java/platform.go:40

	"github.com/hyperledger/fabric/core/chaincode/platforms/util"
)

var logger = flogging.MustGetLogger("chaincode.platform.java")

// Platform for java chaincodes in java
type Platform struct{}

// Name returns the name of this platform
func (p *Platform) Name() string {
	return pb.ChaincodeSpec_JAVA.String()
}

// ValidatePath validates the java chaincode paths
func (p *Platform) ValidatePath(rawPath string) error {
	path, err := url.Parse(rawPath)
	if err != nil || path == nil {
		logger.Errorf("invalid chaincode path %s %v", rawPath, err)
		return fmt.Errorf("invalid path: %s", err)
	}

	return nil
}

func (p *Platform) ValidateCodePackage(code []byte) error {
	// File to be valid should match first RegExp and not match second one.
	filesToMatch := regexp.MustCompile(`^(/)?src/((src|META-INF)/.*|(build\.gradle|settings\.gradle|pom\.xml))`)
	filesToIgnore := regexp.MustCompile(`.*\.class$`)
	is := bytes.NewReader(code)
	gr, err := gzip.NewReader(is)
	if err != nil {
		return fmt.Errorf("failure opening codepackage gzip stream: %s", err)
	}
	tr := tar.NewReader(gr)

	for {
		header, err := tr.Next()

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Supply a plain, well-formed relative path (e.g. 'src/java-chaincode') without special characters.
  2. Escape or remove characters invalid in URLs (% not followed by hex, control chars).
  3. Trim whitespace from the path before submission.
  4. Check the peer logs — the same parse error is logged with details.

Example fix

// before
ValidatePath("my cc/path%zz")
// after
ValidatePath("my-cc/path")
Defensive patterns

Strategy: validation

Validate before calling

func validJavaPath(p string) bool {
	if p == "" { return false }
	_, err := url.Parse(p)
	return err == nil
}

Try / catch

if err := javaPlatform.ValidatePath(rawPath); err != nil {
	if strings.Contains(err.Error(), "invalid path") {
		// sanitize: trim whitespace, remove invalid URL characters
	}
}

Prevention

When it happens

Trigger: Calling ValidatePath with a malformed path string that url.Parse cannot handle, e.g. containing invalid characters like unescaped control chars, bad percent-encodings, or whitespace.

Common situations: Users passing Windows-style or shell-quoted paths, paths copied with trailing spaces, or strings containing characters URL parsing rejects.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/7314f46cda27eaf3. Report an issue: GitHub.