Skip to content

Commit 8eb1aa8

Browse files
author
sheeek
committed
fix(files): handle different response formats in files list
- Handle dict, list[dict], and list[str] response formats - Unwrap responses that might be in 'files' or 'data' keys - Support both file_name and name fields - Gracefully handle string-only responses - More robust error handling for API inconsistencies Tested with: ✅ files list --folder "Home" ✅ files list --attached-to "ToDo" "xxx" Frappe API returns different formats depending on method used.
1 parent 3233bfd commit 8eb1aa8

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

src/frappecli/commands/files.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ def list_files(
150150
data={"folder": folder, "start": 0, "page_length": 100},
151151
)
152152

153-
def render_table(data: list[dict]) -> None:
153+
def render_table(data: list[dict] | list[str] | dict) -> None:
154+
# Handle different response formats
155+
if isinstance(data, dict):
156+
# Response might be wrapped in a dict
157+
data = data.get("files", data.get("data", [data]))
158+
154159
if not data:
155160
console.print("[yellow]No files found[/yellow]")
156161
return
@@ -161,11 +166,16 @@ def render_table(data: list[dict]) -> None:
161166
table.add_column("Modified", style="yellow")
162167

163168
for file in data:
164-
table.add_row(
165-
file.get("file_name", ""),
166-
str(file.get("file_size", "")),
167-
str(file.get("modified", "")),
168-
)
169+
# Handle both dict and string responses
170+
if isinstance(file, dict):
171+
table.add_row(
172+
file.get("file_name", file.get("name", "")),
173+
str(file.get("file_size", "")),
174+
str(file.get("modified", "")),
175+
)
176+
else:
177+
# Simple string response
178+
table.add_row(str(file), "", "")
169179

170180
console.print(table)
171181
console.print(f"\n[bold]Total:[/bold] {len(data)} files")

0 commit comments

Comments
 (0)