Browse Source

ts: Improve error message of unsupported `view` method (#3177)

acheron 1 year ago
parent
commit
275b28a345
2 changed files with 7 additions and 1 deletions
  1. 1 0
      CHANGELOG.md
  2. 6 1
      ts/packages/anchor/src/program/namespace/methods.ts

+ 1 - 0
CHANGELOG.md

@@ -54,6 +54,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 - cli: Fix installation with `--locked` argument using Rust v1.80 due to `time` crate issue ([#3143](https://github.com/coral-xyz/anchor/pull/3143)).
 - lang: Fix compilation warnings due to unused deprecated program id macros ([#3170](https://github.com/coral-xyz/anchor/pull/3170)).
 - ts: Remove `crypto-hash` dependency ([#3171](https://github.com/coral-xyz/anchor/pull/3171)).
+- ts: Improve error message of unsupported `view` method ([#3177](https://github.com/coral-xyz/anchor/pull/3177)).
 
 ### Breaking
 

+ 6 - 1
ts/packages/anchor/src/program/namespace/methods.ts

@@ -313,7 +313,12 @@ export class MethodsBuilder<
     }
 
     if (!this._viewFn) {
-      throw new Error("Method does not support views");
+      throw new Error(
+        [
+          "Method does not support views.",
+          "The instruction should return a value, and its accounts must be read-only",
+        ].join(" ")
+      );
     }
 
     // @ts-ignore