Skip to content

Commit 40c3f19

Browse files
committed
Add proper error display for sync commands
1 parent ac51e1d commit 40c3f19

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

src/commands/sync.ts

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,35 @@ export async function syncCommand() {
7070
};
7171
});
7272

73-
const selectedAgents = await p.multiselect({
74-
message: `Select agents to ${direction === "import" ? "import" : "export"}`,
75-
options: agentOptions,
76-
initialValues: config.agents,
77-
required: false,
73+
// Ask if user wants to select all agents
74+
const selectAll = await p.confirm({
75+
message: `${direction === "import" ? "Import" : "Export"} all agents?`,
76+
initialValue: true,
7877
});
7978

80-
if (p.isCancel(selectedAgents)) {
79+
if (p.isCancel(selectAll)) {
8180
p.cancel("Cancelled");
8281
return;
8382
}
8483

84+
let selectedAgents: string[] | symbol;
85+
86+
if (selectAll) {
87+
selectedAgents = config.agents;
88+
} else {
89+
selectedAgents = await p.multiselect({
90+
message: `Select agents to ${direction === "import" ? "import" : "export"}`,
91+
options: agentOptions,
92+
initialValues: [],
93+
required: false,
94+
});
95+
96+
if (p.isCancel(selectedAgents)) {
97+
p.cancel("Cancelled");
98+
return;
99+
}
100+
}
101+
85102
if ((selectedAgents as string[]).length === 0) {
86103
p.cancel("No agents selected");
87104
return;
@@ -98,11 +115,14 @@ export async function syncCommand() {
98115

99116
let successCount = 0;
100117
let failCount = 0;
118+
const errors: Array<{ agent: string; error: string }> = [];
101119

102120
for (const agentId of selectedAgents as string[]) {
103121
const adapter = adapterRegistry.get(agentId);
104122
if (!adapter) {
105-
s.message(`Warning: Adapter not found for ${agentId}`);
123+
const errorMsg = "Adapter not found";
124+
s.message(`✗ ${agentId}: ${errorMsg}`);
125+
errors.push({ agent: agentId, error: errorMsg });
106126
failCount++;
107127
continue;
108128
}
@@ -117,7 +137,8 @@ export async function syncCommand() {
117137
s.message(`✓ Imported ${adapter.name}`);
118138
successCount++;
119139
} else {
120-
s.message(`✗ Failed to import ${adapter.name}: ${result.message}`);
140+
s.message(`✗ ${adapter.name}: ${result.message}`);
141+
errors.push({ agent: adapter.name, error: result.message || "Unknown error" });
121142
failCount++;
122143
}
123144
} else {
@@ -126,18 +147,29 @@ export async function syncCommand() {
126147
s.message(`✓ Exported ${adapter.name}`);
127148
successCount++;
128149
} else {
129-
s.message(`✗ Failed to export ${adapter.name}: ${result.message}`);
150+
s.message(`✗ ${adapter.name}: ${result.message}`);
151+
errors.push({ agent: adapter.name, error: result.message || "Unknown error" });
130152
failCount++;
131153
}
132154
}
133155
} catch (error) {
134-
s.message(`✗ Error syncing ${adapter.name}: ${error}`);
156+
const errorMsg = error instanceof Error ? error.message : String(error);
157+
s.message(`✗ ${adapter.name}: ${errorMsg}`);
158+
errors.push({ agent: adapter.name, error: errorMsg });
135159
failCount++;
136160
}
137161
}
138162

139163
s.stop(`Sync complete: ${successCount} succeeded, ${failCount} failed`);
140164

165+
if (errors.length > 0) {
166+
console.log("");
167+
p.log.error("Failed agents:");
168+
for (const { agent, error } of errors) {
169+
p.log.message(` ✗ ${agent}: ${error}`);
170+
}
171+
}
172+
141173
p.outro(
142174
direction === "import"
143175
? "Configs imported to repository. Commit and push to sync across machines."

0 commit comments

Comments
 (0)