Skip to content

Commit b2f8bd4

Browse files
committed
fix: handle branch not found error
1 parent ec053db commit b2f8bd4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fsspec/implementations/github.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import re
23

34
import requests
45

@@ -266,10 +267,10 @@ def _open(
266267
**kwargs,
267268
)
268269

269-
def rm(self, path, recursive=False, maxdepth=None):
270+
def rm(self, path, recursive=False, maxdepth=None, message=None):
270271
path = self.expand_path(path, recursive=recursive, maxdepth=maxdepth)
271272
for p in reversed(path):
272-
self.rm_file(p)
273+
self.rm_file(p, message=message)
273274

274275
def rm_file(self, path, message=None, **kwargs):
275276
"""
@@ -317,6 +318,10 @@ def rm_file(self, path, message=None, **kwargs):
317318
}
318319

319320
r = requests.delete(delete_url, json=data, timeout=self.timeout, **self.kw)
321+
error_message = r.json().get("message", "")
322+
if re.search(r"Branch .+ not found", error_message):
323+
error = "Remove only works when the filesystem is initialised from a branch or default (None)"
324+
raise ValueError(error)
320325
r.raise_for_status()
321326

322327
self.invalidate_cache(path)

0 commit comments

Comments
 (0)