Skip to content

Commit 10c59d7

Browse files
authored
fix: azure: format not found error message correctly (#20)
Signed-off-by: Grant Linville <[email protected]>
1 parent e1a20d0 commit 10c59d7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/client/azure.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ func (a *azureProvider) DeleteFile(ctx context.Context, filePath string) error {
193193
}
194194

195195
func (a *azureProvider) OpenFile(ctx context.Context, filePath string, opt OpenOptions) (*File, error) {
196+
originalFilePath := filePath
196197
filePath = strings.TrimPrefix(filePath, "/")
197198
if err := a.validatePath(filePath); err != nil {
198199
return nil, err
@@ -203,7 +204,8 @@ func (a *azureProvider) OpenFile(ctx context.Context, filePath string, opt OpenO
203204
if err != nil {
204205
var storageErr *azcore.ResponseError
205206
if errors.As(err, &storageErr) && storageErr.StatusCode == 404 {
206-
return nil, newNotFoundError(fmt.Sprintf("%s://%s/%s", AzureProvider, a.containerName, a.dir), filePath)
207+
// We need to use the original file path here, because that is how the gptscript sdk will determine whether this is a not found error.
208+
return nil, newNotFoundError(fmt.Sprintf("%s://%s/%s", AzureProvider, a.containerName, a.dir), originalFilePath)
207209
}
208210
return nil, err
209211
}
@@ -270,6 +272,7 @@ func (a *azureProvider) WriteFile(ctx context.Context, fileName string, reader i
270272
}
271273

272274
func (a *azureProvider) StatFile(ctx context.Context, fileName string, opt StatOptions) (FileInfo, error) {
275+
originalFileName := fileName
273276
fileName = strings.TrimPrefix(fileName, "/")
274277
if err := a.validatePath(fileName); err != nil {
275278
return FileInfo{}, err
@@ -280,7 +283,8 @@ func (a *azureProvider) StatFile(ctx context.Context, fileName string, opt StatO
280283
if err != nil {
281284
var storageErr *azcore.ResponseError
282285
if errors.As(err, &storageErr) && storageErr.StatusCode == 404 {
283-
return FileInfo{}, newNotFoundError(fmt.Sprintf("%s://%s/%s", AzureProvider, a.containerName, a.dir), fileName)
286+
// We need to use the original file name here, because that is how the gptscript sdk will determine whether this is a not found error.
287+
return FileInfo{}, newNotFoundError(fmt.Sprintf("%s://%s/%s", AzureProvider, a.containerName, a.dir), originalFileName)
284288
}
285289
return FileInfo{}, err
286290
}

0 commit comments

Comments
 (0)