@@ -154,6 +154,67 @@ Python's standard `logging framework`_.
154154
155155.. _logging framework : https://docs.python.org/3/library/logging.html
156156
157+ Errors
158+ ------
159+
160+ The ``s3fs `` library includes a built-in mechanism to automatically retry
161+ operations when specific transient errors occur. You can customize this behavior
162+ by adding specific exception types or defining complex logic via custom handlers.
163+
164+ Default Retryable Errors
165+ ~~~~~~~~~~~~~~~~~~~~~~~~
166+
167+ By default, ``s3fs `` will retry the following exception types:
168+
169+ - ``socket.timeout ``
170+ - ``HTTPClientError ``
171+ - ``IncompleteRead ``
172+ - ``FSTimeoutError ``
173+ - ``ResponseParserError ``
174+ - ``aiohttp.ClientPayloadError `` (if available)
175+
176+ Registering Custom Error Types
177+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
178+
179+ To include additional exception types in the default retry logic, use the
180+ ``add_retryable_error `` function. This is useful for simple type-based retries.
181+
182+ .. code-block :: python
183+
184+ >> > class MyCustomError (Exception ):
185+ pass
186+ >> > s3fs.add_retryable_error(MyCustomError)
187+
188+ Implementing Custom Error Handlers
189+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190+
191+ For more complex scenarios, such as retrying based on an error message rather than
192+ just the type, you can register a custom error handler using ``set_custom_error_handler ``.
193+
194+ The handler should be a callable that accepts an exception instance and returns ``True ``
195+ if the error should be retried, or ``False `` otherwise.
196+
197+ .. code-block :: python
198+
199+ >> > def my_handler (e ):
200+ return isinstance (e, MyCustomError) and " some condition" in str (e)
201+ >> > s3fs.set_custom_error_handler(my_handler)
202+
203+ Handling AWS ClientErrors
204+ ~~~~~~~~~~~~~~~~~~~~~~~~~
205+
206+ ``s3fs `` provides specialized handling for ``botocore.exceptions.ClientError ``.
207+ While ``s3fs `` checks these against internal patterns (like throttling),
208+ you can extend this behavior using a custom handler. Note that the internal
209+ patterns will still be checked and handled before the custom handler.
210+
211+ .. code-block :: python
212+
213+ >> > def another_handler (e ):
214+ return isinstance (e, ClientError) and " Throttling" in str (e)
215+ >> > s3fs.set_custom_error_handler(another_handler)
216+
217+
157218 Credentials
158219-----------
159220
0 commit comments