@solana/web3.js 1.20.3 → 1.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.esm.js CHANGED
@@ -2448,6 +2448,17 @@ class EpochSchedule {
2448
2448
 
2449
2449
  }
2450
2450
 
2451
+ class SendTransactionError extends Error {
2452
+ constructor(message, logs) {
2453
+ super(message);
2454
+
2455
+ _defineProperty(this, "logs", void 0);
2456
+
2457
+ this.logs = logs;
2458
+ }
2459
+
2460
+ }
2461
+
2451
2462
  // TODO: These constants should be removed in favor of reading them out of a
2452
2463
  // Syscall account
2453
2464
 
@@ -4735,7 +4746,19 @@ class Connection {
4735
4746
  const res = create(unsafeRes, SimulatedTransactionResponseStruct);
4736
4747
 
4737
4748
  if ('error' in res) {
4738
- throw new Error('failed to simulate transaction: ' + res.error.message);
4749
+ let logs;
4750
+
4751
+ if ('data' in res.error) {
4752
+ logs = res.error.data.logs;
4753
+
4754
+ if (logs && Array.isArray(logs)) {
4755
+ const traceIndent = '\n ';
4756
+ const logTrace = traceIndent + logs.join(traceIndent);
4757
+ console.error(res.error.message, logTrace);
4758
+ }
4759
+ }
4760
+
4761
+ throw new SendTransactionError('failed to simulate transaction: ' + res.error.message, logs);
4739
4762
  }
4740
4763
 
4741
4764
  return res.result;
@@ -4817,8 +4840,10 @@ class Connection {
4817
4840
  const res = create(unsafeRes, SendTransactionRpcResult);
4818
4841
 
4819
4842
  if ('error' in res) {
4843
+ let logs;
4844
+
4820
4845
  if ('data' in res.error) {
4821
- const logs = res.error.data.logs;
4846
+ logs = res.error.data.logs;
4822
4847
 
4823
4848
  if (logs && Array.isArray(logs)) {
4824
4849
  const traceIndent = '\n ';
@@ -4827,7 +4852,7 @@ class Connection {
4827
4852
  }
4828
4853
  }
4829
4854
 
4830
- throw new Error('failed to send transaction: ' + res.error.message);
4855
+ throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
4831
4856
  }
4832
4857
 
4833
4858
  return res.result;