{"record":{"id":"a945f5df3d7a284b","repo":"Tencent/WeKnora","slug":"invalid-oss-file-path-s","errorCode":null,"errorMessage":"invalid OSS file path: %s","messagePattern":"invalid OSS file path: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/file/oss.go","lineNumber":139,"sourceCode":"\tclient, err := newOSSClient(endpoint, region, accessKey, secretKey)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\texists, err := client.IsBucketExist(ctx, bucketName)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to check OSS bucket: %w\", err)\n\t}\n\tif !exists {\n\t\treturn fmt.Errorf(\"bucket %q does not exist or is not accessible\", bucketName)\n\t}\n\treturn nil\n}\n\n// parseOssFilePath extracts bucket and object key from: oss://{bucket}/{objectKey}\nfunc parseOssFilePath(filePath string) (bucketName string, objectKey string, err error) {\n\tif !strings.HasPrefix(filePath, ossScheme) {\n\t\treturn \"\", \"\", fmt.Errorf(\"invalid OSS file path: %s\", filePath)\n\t}\n\n\trest := strings.TrimPrefix(filePath, ossScheme)\n\tparts := strings.SplitN(rest, \"/\", 2)\n\tif len(parts) != 2 || parts[0] == \"\" || parts[1] == \"\" {\n\t\treturn \"\", \"\", fmt.Errorf(\"invalid OSS file path: %s\", filePath)\n\t}\n\treturn parts[0], parts[1], nil\n}\n\n// CheckConnectivity verifies OSS is reachable and the main bucket exists.\nfunc (s *ossFileService) CheckConnectivity(ctx context.Context) error {\n\tcheckCtx, cancel := context.WithTimeout(ctx, 10*time.Second)\n\tdefer cancel()\n\n\texists, err := s.client.IsBucketExist(checkCtx, s.bucketName)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to check OSS bucket: %w\", err)","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/file/oss.go#L121-L157","documentation":"parseOssFilePath validates that a file reference uses the OSS URI scheme oss://{bucket}/{objectKey} before extracting bucket and key. This error is returned when the string does not start with the 'oss://' prefix, so no bucket/key can be parsed. It indicates the caller passed a raw path, URL, or incorrectly constructed identifier instead of a proper OSS URI.","triggerScenarios":"Calling CopyFile, GetFile, DeleteFile, or GetFileURL with a path that lacks the oss:// prefix, e.g. 'mybucket/dir/file.txt', '/local/path/file.txt', 'https://bucket.oss-cn.aliyuncs.com/key', or an empty string.","commonSituations":"Storing bare object keys or full HTTP URLs in the database instead of OSS URIs; legacy records created before the oss:// scheme was adopted; user-supplied file references not normalized; constructing the path with the wrong constant prefix.","solutions":["Inspect the exact filePath value in the error message and ensure it starts with 'oss://'","Normalize stored references: if you have a bare key, wrap it as fmt.Sprintf(\"oss://%s/%s\", bucket, key)","Migrate legacy DB rows to the oss:// scheme, or add a migration shim that prefixes missing schemes before calling the service","Reject/fix user input at the API boundary by validating the oss:// prefix before invoking the service"],"exampleFix":"// before\nsvc.GetFile(ctx, \"my-knowledge/file.pdf\")\n// after\nsvc.GetFile(ctx, fmt.Sprintf(\"oss://%s/%s\", bucketName, \"my-knowledge/file.pdf\"))","handlingStrategy":"validation","validationCode":"func isValidOssPath(p string) bool {\n    rest, ok := strings.CutPrefix(p, \"oss://\")\n    if !ok { return false }\n    bucket, key, found := strings.Cut(rest, \"/\")\n    return found && bucket != \"\" && key != \"\"\n}\nif !isValidOssPath(filePath) { return fmt.Errorf(\"invalid OSS path: %q\", filePath) }","typeGuard":"func isOssPath(s string) bool { return strings.HasPrefix(s, \"oss://\") }","tryCatchPattern":"bucket, key, err := parseOssFilePath(filePath)\nif err != nil {\n    return fmt.Errorf(\"cannot resolve file %q: %w\", filePath, err)\n}","preventionTips":["Always persist full oss://bucket/key URIs, never bare keys or HTTP URLs","Centralize path construction in one helper that always emits the oss:// scheme","Validate the scheme at the API boundary before calling the file service"],"tags":["oss","path-validation","input-validation"],"backgroundTag":"invalid-oss-path","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}