You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improvements & refactoring of get_file_contents (#1582)
* Improvements & refactoring of get_file_contents
* Fix logical path when file or directory not found
* Fix comment
* Docs update
* Do file matching when raw API returns error
returnutils.NewToolResultError("file content SHA is nil, if a directory was requested, path parameters should end with a trailing slash '/'"), nil, nil
// file content or file SHA is nil which means it's a directory
708
+
r, err:=json.Marshal(dirContent)
743
709
iferr!=nil {
744
-
returnutils.NewToolResultError(fmt.Sprintf("failed to marshal matching files: %s", err)), nil, nil
710
+
returnutils.NewToolResultError("failed to marshal response"), nil, nil
745
711
}
746
-
resolvedRefs, err:=json.Marshal(rawOpts)
747
-
iferr!=nil {
748
-
returnutils.NewToolResultError(fmt.Sprintf("failed to marshal resolved refs: %s", err)), nil, nil
749
-
}
750
-
returnutils.NewToolResultError(fmt.Sprintf("Resolved potential matches in the repository tree (resolved refs: %s, matching files: %s), but the raw content API returned an unexpected status code %d.", string(resolvedRefs), string(matchingFilesJSON), rawAPIResponseCode)), nil, nil
returnutils.NewToolResultError("Failed to get file contents. The path does not point to a file or directory, or the file does not exist in the repository."), nil, nil
715
+
returnutils.NewToolResultError("failed to get file contents"), nil, nil
754
716
})
755
717
756
718
returntool, handler
@@ -2115,3 +2077,35 @@ func UnstarRepository(getClient GetClientFn, t translations.TranslationHelperFun
returnutils.NewToolResultError(fmt.Sprintf("failed to marshal matching files: %s", err)), nil, nil
2100
+
}
2101
+
resolvedRefs, err:=json.Marshal(rawOpts)
2102
+
iferr!=nil {
2103
+
returnutils.NewToolResultError(fmt.Sprintf("failed to marshal resolved refs: %s", err)), nil, nil
2104
+
}
2105
+
ifrawAPIResponseCode>0 {
2106
+
returnutils.NewToolResultText(fmt.Sprintf("Resolved potential matches in the repository tree (resolved refs: %s, matching files: %s), but the content API returned an unexpected status code %d.", string(resolvedRefs), string(matchingFilesJSON), rawAPIResponseCode)), nil, nil
2107
+
}
2108
+
returnutils.NewToolResultText(fmt.Sprintf("Resolved potential matches in the repository tree (resolved refs: %s, matching files: %s).", string(resolvedRefs), string(matchingFilesJSON))), nil, nil
2109
+
}
2110
+
returnutils.NewToolResultError("Failed to get file contents. The path does not point to a file or directory, or the file does not exist in the repository."), nil, nil
0 commit comments