aai-institute / lakefs-spec

An fsspec implementation for the lakeFS project.
http://lakefs-spec.org/
Apache License 2.0
37 stars 4 forks source link

Propagate writing on protected branch error message to lakeFS-spec error message #255

Closed maxmynter closed 4 months ago

maxmynter commented 5 months ago

What is the motivation and/or use case?

We should propagate the error message for writing on a protected branch. Currently the following code, when the main branch is protected, produces an inconclusive error message.

fs = lakefs_spec.LakeFSFileSystem()

df = pd.read_csv("developer-stats.csv")

with fs.transaction as tx:
    df.to_csv("lakefs://quickstart/main/dev-stats.csv")
    tx.commit(repository="quickstart", branch="main", message="Try to commit")

The stack trace is

---------------------------------------------------------------------------
ForbiddenException                        Traceback (most recent call last)
    [... skipping hidden 1 frame]

Cell In[3], [line 6](vscode-notebook-cell:?execution_count=3&line=6)
      [5](vscode-notebook-cell:?execution_count=3&line=5) with fs.transaction as tx:
----> [6](vscode-notebook-cell:?execution_count=3&line=6)     df.to_csv("lakefs://quickstart/main/dev-stats.csv")
      [7](vscode-notebook-cell:?execution_count=3&line=7)     tx.commit(repository="quickstart", branch="main", message="Try to commit")

File [~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3902](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3902), in NDFrame.to_csv(self, path_or_buf, sep, na_rep, float_format, columns, header, index, index_label, mode, encoding, compression, quoting, quotechar, lineterminator, chunksize, date_format, doublequote, escapechar, decimal, errors, storage_options)
   [3893](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3893) formatter = DataFrameFormatter(
   [3894](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3894)     frame=df,
   [3895](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3895)     header=header,
   (...)
   [3899](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3899)     decimal=decimal,
   [3900](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3900) )
-> [3902](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3902) return DataFrameRenderer(formatter).to_csv(
   [3903](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3903)     path_or_buf,
   [3904](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3904)     lineterminator=lineterminator,
   [3905](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3905)     sep=sep,
   [3906](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3906)     encoding=encoding,
   [3907](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3907)     errors=errors,
   [3908](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3908)     compression=compression,
   [3909](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3909)     quoting=quoting,
   [3910](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/pandas/core/generic.py:3910)     columns=columns,
...
File [~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/lakefs/exceptions.py:37](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/lakefs/exceptions.py:37), in ServerException.__str__(self)
     [36](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/lakefs/exceptions.py:36) def __str__(self):
---> [37](https://file+.vscode-resource.vscode-cdn.net/Users/maxmynter/Desktop/appliedAI/pydata-hb/~/Desktop/appliedAI/pydata-hb/.venv/lib/python3.10/site-packages/lakefs/exceptions.py:37)     return f"code: {self.status_code}, reason: {self.reason}, body: {self.body}"

AttributeError: 'ForbiddenException' object has no attribute 'body'

How can we implement this feature?

Catch the error in the lakeFS error class and print a conclusive error message.