@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.cjs.js CHANGED
@@ -2485,6 +2485,17 @@ class EpochSchedule {
2485
2485
 
2486
2486
  }
2487
2487
 
2488
+ class SendTransactionError extends Error {
2489
+ constructor(message, logs) {
2490
+ super(message);
2491
+
2492
+ _defineProperty__default['default'](this, "logs", void 0);
2493
+
2494
+ this.logs = logs;
2495
+ }
2496
+
2497
+ }
2498
+
2488
2499
  // TODO: These constants should be removed in favor of reading them out of a
2489
2500
  // Syscall account
2490
2501
 
@@ -4772,7 +4783,19 @@ class Connection {
4772
4783
  const res = superstruct.create(unsafeRes, SimulatedTransactionResponseStruct);
4773
4784
 
4774
4785
  if ('error' in res) {
4775
- throw new Error('failed to simulate transaction: ' + res.error.message);
4786
+ let logs;
4787
+
4788
+ if ('data' in res.error) {
4789
+ logs = res.error.data.logs;
4790
+
4791
+ if (logs && Array.isArray(logs)) {
4792
+ const traceIndent = '\n ';
4793
+ const logTrace = traceIndent + logs.join(traceIndent);
4794
+ console.error(res.error.message, logTrace);
4795
+ }
4796
+ }
4797
+
4798
+ throw new SendTransactionError('failed to simulate transaction: ' + res.error.message, logs);
4776
4799
  }
4777
4800
 
4778
4801
  return res.result;
@@ -4854,8 +4877,10 @@ class Connection {
4854
4877
  const res = superstruct.create(unsafeRes, SendTransactionRpcResult);
4855
4878
 
4856
4879
  if ('error' in res) {
4880
+ let logs;
4881
+
4857
4882
  if ('data' in res.error) {
4858
- const logs = res.error.data.logs;
4883
+ logs = res.error.data.logs;
4859
4884
 
4860
4885
  if (logs && Array.isArray(logs)) {
4861
4886
  const traceIndent = '\n ';
@@ -4864,7 +4889,7 @@ class Connection {
4864
4889
  }
4865
4890
  }
4866
4891
 
4867
- throw new Error('failed to send transaction: ' + res.error.message);
4892
+ throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
4868
4893
  }
4869
4894
 
4870
4895
  return res.result;