Skip to content

Commit 1234157

Browse files
chore: show more descriptive Redis error (#515)
1 parent 5260411 commit 1234157

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## 1.0.29-dev1
1+
## 1.0.29-dev2
22

33
* **Fixed issue in the blob storage destination connector where files with the same name were overwriting each other**
4+
* **Added more descriptive Redis connector error messages**
45

56
## 1.0.29
67

unstructured_ingest/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.29-dev1" # pragma: no cover
1+
__version__ = "1.0.29-dev2" # pragma: no cover

unstructured_ingest/processes/connectors/redisdb.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class RedisAccessConfig(AccessConfig):
3232
default=None, description="If not anonymous, use this uri, if specified."
3333
)
3434
password: Optional[str] = Field(
35-
default=None,
35+
default=None,
3636
description="Password used to connect to database if uri is "
37-
"not specified and connection is not anonymous."
37+
"not specified and connection is not anonymous.",
3838
)
3939

4040

@@ -45,7 +45,7 @@ class RedisConnectionConfig(ConnectionConfig):
4545
host: Optional[str] = Field(
4646
default=None,
4747
description="Hostname or IP address of a Redis instance to connect to "
48-
"if uri is not specified.",
48+
"if uri is not specified.",
4949
)
5050
database: int = Field(default=0, description="Database index to connect to.")
5151
port: Optional[int] = Field(
@@ -126,6 +126,20 @@ class RedisUploaderConfig(UploaderConfig):
126126
key_prefix: str = Field(default="", description="Prefix for Redis keys")
127127

128128

129+
def _form_redis_pipeline_error_message(error: str) -> str:
130+
"""
131+
Form a user-friendly error message for Redis pipeline errors.
132+
The error message has `$` character at the beginning and `) of pipeline` at the end.
133+
Everything between these two strings is the value an should be removed.
134+
"""
135+
start = error.find("$")
136+
end = error.find(") of pipeline")
137+
if start != -1 and end != -1:
138+
return error[: start + 1] + "<value>" + error[end:]
139+
else:
140+
return error
141+
142+
129143
@dataclass
130144
class RedisUploader(Uploader):
131145
upload_config: RedisUploaderConfig
@@ -182,14 +196,14 @@ async def _check_redis_stack(self, element: dict) -> bool:
182196
# Redis with stack extension supports JSON type
183197
await pipe.json().set(key_with_prefix, "$", element).execute()
184198
except redis_exceptions.ResponseError as e:
185-
message = str(e)
199+
message = _form_redis_pipeline_error_message(str(e))
186200
if "unknown command `JSON.SET`" in message:
187201
# if this error occurs, Redis server doesn't support JSON type,
188202
# so save as string type instead
189203
await pipe.set(key_with_prefix, json.dumps(element)).execute()
190204
redis_stack = False
191205
else:
192-
raise e
206+
raise redis_exceptions.ResponseError(message) from e
193207
return redis_stack
194208

195209

0 commit comments

Comments
 (0)