Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/commands/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,25 @@ export function registerClientCommands(program: Command): void {
]);
const txnHash = Array.isArray(result) ? result[0] : result;

const message = await agentApi.confirmJobFeedback(
chainId,
opts.jobId,
txnHash
);
let message: string | undefined;
try {
message = await agentApi.confirmJobFeedback(
chainId,
opts.jobId,
txnHash
);
} catch (err) {
const errMessage = err instanceof Error ? err.message : String(err);
throw new CliError(
`Backend confirmation failed after review transaction was broadcast. Tx hash: ${txnHash}. ${errMessage}`,
"API_ERROR",
"The on-chain transaction was already sent. Keep the Tx Hash and retry or contact support with it.",
{
action: "client review",
txnHash,
}
);
}

if (json) {
outputResult(json, {
Expand Down
20 changes: 14 additions & 6 deletions src/commands/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,20 @@ export function registerComputeCommands(program: Command): void {
});

const agentAddress = getWalletAddress();
const result = await agentApi.computeTopUp(
agentId,
agentAddress,
amount,
txnHash
);
try {
await agentApi.computeTopUp(agentId, agentAddress, amount, txnHash);
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
throw new CliError(
`Backend confirmation failed after compute top-up transaction was broadcast. Tx hash: ${txnHash}. ${message}`,
"API_ERROR",
"The on-chain transaction was already sent. Keep the Tx Hash and retry or contact support with it.",
{
action: "compute top-up",
txnHash,
}
);
}

if (json) {
outputResult(json, {
Expand Down
9 changes: 8 additions & 1 deletion src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ export type ErrorCode =
export class CliError extends Error {
code: ErrorCode;
recovery?: string;
details?: Record<string, string | number | boolean>;

constructor(message: string, code: ErrorCode, recovery?: string) {
constructor(
message: string,
code: ErrorCode,
recovery?: string,
details?: Record<string, string | number | boolean>
) {
super(message);
this.code = code;
this.recovery = recovery;
this.details = details;
}
}
5 changes: 5 additions & 0 deletions src/lib/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export function outputError(
if (isCliErr) {
payload.code = errOrMessage.code;
if (errOrMessage.recovery) payload.recovery = errOrMessage.recovery;
if (errOrMessage.details) {
for (const [key, value] of Object.entries(errOrMessage.details)) {
payload[key] = String(value);
}
}
}
process.stdout.write(JSON.stringify(payload) + "\n");
} else {
Expand Down