{"record":{"id":"1819c464df325379","repo":"Tencent/WeKnora","slug":"invalid-resource-reference","errorCode":null,"errorMessage":"invalid resource reference","messagePattern":"invalid resource reference","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/resource.go","lineNumber":115,"sourceCode":"\t\t\tLifecycle:        lifecycle,\n\t\t}\n\t\tif err := s.repo.Create(ctx, resource); err == nil {\n\t\t\treturn types.BuildResourcePath(handle), nil\n\t\t} else if !strings.Contains(strings.ToLower(err.Error()), \"unique\") {\n\t\t\treturn \"\", err\n\t\t}\n\t\texisting, lookupErr := s.repo.GetByTenantLocation(ctx, tenantID, locationHash)\n\t\tif lookupErr == nil && existing != nil {\n\t\t\treturn types.BuildResourcePath(existing.Handle), nil\n\t\t}\n\t}\n\treturn \"\", fmt.Errorf(\"failed to allocate unique resource handle\")\n}\n\nfunc (s *resourceCatalog) Resolve(ctx context.Context, reference string) (*types.StoredResource, error) {\n\thandle, ok := types.ParseResourcePath(reference)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid resource reference\")\n\t}\n\tresource, err := s.repo.GetByHandle(ctx, handle)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif resource == nil {\n\t\treturn nil, fmt.Errorf(\"resource not found\")\n\t}\n\treturn resource, nil\n}\n\nfunc (s *resourceCatalog) ResolvePath(ctx context.Context, value string) (string, *types.StoredResource, error) {\n\tif _, ok := types.ParseResourcePath(value); !ok {\n\t\treturn value, nil, nil\n\t}\n\tresource, err := s.Resolve(ctx, value)\n\tif err != nil {\n\t\treturn \"\", nil, err","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/resource.go#L97-L133","documentation":"Resolve validates the incoming reference string through types.ParseResourcePath before doing any repo lookup. A reference that is not a well-formed catalog resource path (e.g. a raw provider path or arbitrary string) is rejected with this error. It is an input-validation error, thrown before any database access.","triggerScenarios":"Passing a raw provider file path, empty string, or any string lacking the catalog handle format to Resolve (directly or via ResolvePath, Bind, Release, MarkDeleted, CreateAccessGrant).","commonSituations":"Storing/transporting raw storage paths instead of the resource:// style handle; legacy code paths that predate the catalog; trimming/serialization corrupting the reference.","solutions":["Use the value returned from Register (types.BuildResourcePath output) rather than a raw storage path","Run types.ParseResourcePath on the reference before the call to fail fast","For legacy raw paths, route through the Register/lookup flow to obtain a valid handle","Check for encoding/truncation when persisting or passing references between services"],"exampleFix":"// before\nres, err := catalog.Resolve(ctx, \"s3://bucket/obj\")\n// after\nhandle, ok := types.ParseResourcePath(\"s3://bucket/obj\")\nif !ok {\n    return fmt.Errorf(\"not a catalog reference\")\n}\nres, err := catalog.Resolve(ctx, types.BuildResourcePath(handle))","handlingStrategy":"validation","validationCode":"if _, ok := types.ParseResourcePath(reference); !ok { return fmt.Errorf(\"invalid reference: %q\", reference) }","typeGuard":"func isResourceReference(s string) bool { _, ok := types.ParseResourcePath(s); return ok }","tryCatchPattern":"res, err := catalog.Resolve(ctx, ref)\nif err != nil && strings.Contains(err.Error(), \"invalid resource reference\") {\n    return fmt.Errorf(\"%w: %q\", ErrBadReference, ref)\n}","preventionTips":["Persist the exact string returned by Register, never a reconstructed path","Add ParseResourcePath validation at API boundaries","Migrate legacy raw paths through Register before use","Log the offending reference to catch format regressions early"],"tags":["input-validation","resource-reference"],"backgroundTag":"invalid-resource-reference","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}