{"record":{"id":"11128b60b6fe049d","repo":"Tencent/WeKnora","slug":"failed-to-open-file-w-11128b","errorCode":null,"errorMessage":"failed to open file: %w","messagePattern":"failed to open file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/file/tos.go","lineNumber":182,"sourceCode":"\tparts := strings.SplitN(rest, \"/\", 2)\n\tif len(parts) != 2 || parts[0] == \"\" || parts[1] == \"\" {\n\t\treturn \"\", \"\", fmt.Errorf(\"invalid TOS file path: %s\", filePath)\n\t}\n\treturn parts[0], parts[1], nil\n}\n\nfunc (s *tosFileService) SaveFile(ctx context.Context, file *multipart.FileHeader, tenantID uint64, knowledgeID string) (string, error) {\n\text := filepath.Ext(file.Filename)\n\tobjectName := joinTOSObjectKey(\n\t\ts.pathPrefix,\n\t\tfmt.Sprintf(\"%d\", tenantID),\n\t\tknowledgeID,\n\t\tuuid.New().String()+ext,\n\t)\n\n\tsrc, err := file.Open()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to open file: %w\", err)\n\t}\n\tdefer src.Close()\n\n\tcontentType := file.Header.Get(\"Content-Type\")\n\tif contentType == \"\" {\n\t\tcontentType = utils.GetContentTypeByExt(ext)\n\t}\n\t_, err = s.client.PutObjectV2(ctx, &tos.PutObjectV2Input{\n\t\tPutObjectBasicInput: tos.PutObjectBasicInput{\n\t\t\tBucket:      s.bucketName,\n\t\t\tKey:         objectName,\n\t\t\tContentType: contentType,\n\t\t},\n\t\tContent: src,\n\t})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to upload file to TOS: %w\", err)\n\t}","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/file/tos.go#L164-L200","documentation":"Upload error in tosFileService.SaveFile: file.Open() on the received multipart.FileHeader failed, so the file content could never be read for the TOS PUT. The %w carries the underlying local I/O error; it is raised before any object-key upload request is made.","triggerScenarios":"Thrown at internal/application/service/file/tos.go:182 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the upload request","Avoid re-reading the multipart handle without re-opening","Check server temp storage health"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}