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
10 changes: 8 additions & 2 deletions lib/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ import {

if (txResponse.status !== "SUCCESS") {
console.error(`Transaction failed for ${functName} with status: ${txResponse.status}`, JSON.stringify(txResponse, null, 2));
throw new Error(`Transaction failed with status: ${txResponse.status}`);
throw new Error(
`Transaction failed with status: ${txResponse.status} ` +
`(function: ${functName}, contract: ${targetContractId}, network: ${config.network})`
);
}

// Parse return value if present (e.g., for withdraw)
Expand Down Expand Up @@ -219,7 +222,10 @@ import {
} catch (error: unknown) {
const errorMessage = error instanceof Error ? error.message : String(error);
console.error("Failed to swap:", errorMessage);
throw error;
throw new Error(
`Failed to swap (to=${to}, buyA=${buyA}, out=${out}, inMax=${inMax}, ` +
`network=${config?.network ?? "testnet"}): ${errorMessage}`
);
}
}

Expand Down
25 changes: 22 additions & 3 deletions lib/dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,16 @@ export async function quoteSwap(
const response = await fetchImpl(buildPathEndpointUrl(client, params));

if (!response.ok) {
throw new Error(`Failed to fetch path quotes: ${response.status} ${response.statusText}`);
const sendAssetLabel = assetInputToHorizonAsset(params.sendAsset);
const destAssetLabel = assetInputToHorizonAsset(params.destAsset);
const amountLabel = params.mode === "strict-send"
? `sendAmount=${params.sendAmount}`
: `destAmount=${params.destAmount}`;
throw new Error(
`Failed to fetch path quotes for ${params.mode} swap ` +
`(${sendAssetLabel} → ${destAssetLabel}, ${amountLabel}) ` +
`on ${client.network}: ${response.status} ${response.statusText}`
);
}

const payload = (await response.json()) as HorizonPathResponse;
Expand Down Expand Up @@ -223,7 +232,16 @@ export async function swapBestRoute(
const bestQuote = quotes[0];

if (!bestQuote) {
throw new Error("No route available for the requested swap");
const sendAssetLabel = assetInputToHorizonAsset(params.sendAsset);
const destAssetLabel = assetInputToHorizonAsset(params.destAsset);
const amountLabel = params.mode === "strict-send"
? `sendAmount=${params.sendAmount}`
: `destAmount=${params.destAmount}`;
throw new Error(
`No route available for ${params.mode} swap ` +
`(${sendAssetLabel} → ${destAssetLabel}, ${amountLabel}) ` +
`on ${client.network}`
);
}

const createServer =
Expand Down Expand Up @@ -417,7 +435,8 @@ async function validateDestinationAssetSupport(

if (!supportsAsset) {
throw new Error(
"Destination account does not trust the requested destination asset"
`Destination account ${destination} does not trust asset ${destAsset.code}:${destAsset.issuer}. ` +
`The destination account must have a trustline for this asset before receiving it.`
);
}
}
2 changes: 1 addition & 1 deletion tests/integration/dex-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe("dex workflow", () => {
},
{ fetchImpl }
)
).rejects.toThrow("No route available");
).rejects.toThrow("No route available for");
});

it("surfaces destination trustline-style submission failures", async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/dex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ describe("dex helpers", () => {
},
{ fetchImpl }
)
).rejects.toThrow("Destination account does not trust the requested destination asset");
).rejects.toThrow("does not trust asset EUR:");

expect(fetchImpl).toHaveBeenCalledTimes(1);
});
Expand Down