「エラーモナド」を編集中

移動先: 案内検索

警告: ログインしていません。編集を行うと、あなたの IP アドレスが公開されます。ログインまたはアカウントを作成すれば、あなたの編集はその利用者名とともに表示されるほか、その他の利点もあります。

この編集を取り消せます。 下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 編集中の文章
1行目: 1行目:
.. _error_monad:
+
.. _error_monad:
  
=エラーMonad =
+
= The Error Monad =
  
これは、「michelson-lang.com」のブログ記事から修正されています。
+
This has been adapted from a blog post on ''michelson-lang.com''.
  
モナドに慣れていない場合は、数分でチュートリアルを読んでください。私はPhilip Wadlerのこの<code> paper <http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf&gt; </code> __から個人的には多くを得ていますが、オンラインで入手できる他の大量のもの。あなたのために働くものを見つけてください。エラーモナドはモナドが行っているようにひどく恐ろしいことではないので、あなたがその要点を理解していると感じたら、戻って何が起こっているのかを理解できるかどうかを見てください。
+
If you’re not familiar with monads, go take a few minutes and read a tutorial. I personally got a lot out of this <code>paper &lt;http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf&gt;</code>__ by Philip Wadler, but there are a ton of others available online. Find one that works for you. The error monad isn’t terribly scary as Monads go, so once you feel like you understand the gist, come on back and see if you can understand what’s going on.
  
以下の例では、多くのモナドが提供するいくつかの便利な操作を省略します。追加したい場合は、難しくありません。
+
I’m going to omit some convenience operations that a lot of monads provide in the examples below. If you want to add them, they’re not difficult.
  
==なぜあなたはエラーを要求していますか?
+
== Why you want the error monad ==
  
Tezosでは、不適切な入力によってノードをクラッシュさせることは望ましくありません。この可能性を回避するために、システムでエラー処理の例外を使用すべきでないと判断されました。代わりに、エラーモナドを使用します。この設計では、出力を使用する前にエラーを処理または伝達するよう強制されます。例外は依然として使用されることがありますが、これは主にクライアント側であり、内部エラーの場合のみです。
+
In Tezos, we don’t want to have the node be crashable by an improper input. To avoid this possibility, it was decided that the system should not use exceptions for error handling. Instead, it uses an error monad. This design forces errors to be handled or carried through before an output can be used. Exceptions are still occasionally used, but this is mostly in the client and only for internal errors.
  
並行性のために使用するLwtライブラリにも組み込みます。これはエラーモナドと組み合わされ、コードベース全体にわたって再び使用されます。 Lwtモナドは他の言語の約束とよく似ています。
+
We also mix in the Lwt library, which we use for concurrency. This is combined with the error monad and is once again used pervasively throughout the codebase. The Lwt monad is a lot like promises in other languages.
  
さらなる騒ぎをせずに、エラーモナドを書いてみましょう。
+
Without further ado, let’s write an error monad.
  
==単純なエラーモナドのバージョン==
+
== A simple version of the error monad ==
  
ここには非常に単純なエラーモナドがあります。
+
Here’s a very simple error monad.
  
..コード:: ocaml
+
.. code:: ocaml
  
<pre>モジュールエラー:sig
+
<pre>module Error : sig
   タイプ 'a t
+
   type 'a t
   *タイプt *の値を作成します)
+
   (* Create a value of type t *)
   戻り値: 'a - &gt; 'いや
+
   val return : 'a -&gt; 'a t
   *計算が失敗した場合*
+
   (* For when a computation fails *)
   値の誤差: 'a t
+
   val error : 'a t
   *エラーモナドの値に演算を適用する*
+
   (* Apply an operation to a value in the error monad *)
   val(&gt;&gt;?): 'a t - &gt; 'a - &gt; b t) - &gt; 'b t(* bind *
+
   val (&gt;&gt;?) : 'a t -&gt; ('a -&gt; 'b t) -&gt; 'b t (* bind *)
終了=構造体
+
end = struct
   タイプ 'a t = Ok of' a |エラー
+
   type 'a t = Ok of 'a | Error
   return x = Ok x
+
   let return x = Ok x
   let error =エラー
+
   let error = Error
   let(&gt;&gt ;?)の値func =
+
   let (&gt;&gt;?) value func =
     ?と一致する値
+
     match value with
     | Ok x - &gt; func x
+
     | Ok x -&gt; func x
     |エラー - &gt;エラー
+
     | Error -&gt; Error
終了</pre>
+
end</pre>
それで、これはTezosが使うものですか?実際には、後で使用する多くの構造が既に用意されています。基本的な考え方は、正しい値を返し、操作が失敗した場合はエラーを返すことです。エラーモジュールの外側では、実際にエラー値をイントロスペクトすることはできません。バインドを使用して、値の正確性/不正性のみをディスパッチできます。
+
So, is this what Tezos uses? We actually already have a lot of the structure that we’ll use later. The basic idea is that you return a value that’s correct and return an error if the operation failed. Outside of the error module, you can’t actually introspect an error value. You can only dispatch on the correctness/incorrectness of the value using bind.
  
ここで何が間違っていますか?
+
What’s wrong here?
  
*エラーケースに関する情報は報告できません
+
* We can’t report any information about an error case
* Tezos全体のエラーメッセージの品質を改善するために使用されるエラートレースは報告できません
+
* We can’t report error traces, something that’s used to improve the quality of error messages throughout Tezos
*いくつかのエラーは処理できず、実行を継続できません
+
* We can’t handle some errors and continue executing
  
==若干の改善==
+
== A slight improvement ==
  
エラーに説明文字列を含めることで、エラー報告を強化しましょう。今度はエラーとともにメッセージを報告することができます。これで十分ですか?あんまり。印刷の仕方に柔軟性はありません。エラートレースを作成することはできず、エラーを処理してプログラムの実行を再開することはできません。
+
Let’s now enhance our error reporting by allowing errors to contain a description string. Now we can report messages along with our errors. Is this enough of an improvement? Not really. We don’t have any flexibility about how the printing works. We still can’t create error traces and we can’t handle errors and resume executing the program.
  
..コード:: ocaml
+
.. code:: ocaml
<pre>モジュールエラー:sig
+
 
   タイプ 'a t
+
<pre>module Error : sig
   戻り値: 'a - &gt; 'いや
+
   type 'a t
   valエラー:文字列 - &gt; 'いや
+
   val return : 'a -&gt; 'a t
   val(&gt;&gt;?): 'a t - &gt; 'a - &gt; b t) - &gt; 'b t(* bind *
+
   val error : string -&gt; 'a t
   val print_value:( 'a - &gt; string) - &gt; 'a t - &gt;単位
+
   val (&gt;&gt;?) : 'a t -&gt; ('a -&gt; 'b t) -&gt; 'b t (* bind *)
終了=構造体
+
   val print_value : ('a -&gt; string) -&gt; 'a t -&gt; unit
   タイプ 'a t = Ok of' a |文字列のエラー
+
end = struct
   return x = Ok x
+
   type 'a t = Ok of 'a | Error of string
   エラーs =エラーs
+
   let return x = Ok x
   let(&gt;&gt ;?)の値func =
+
   let error s = Error s
     ?と一致する値
+
   let (&gt;&gt;?) value func =
     | Ok x - &gt; func x
+
     match value with
     |エラーs - &gt;エラーs
+
     | Ok x -&gt; func x
 +
     | Error s -&gt; Error s
 
   let print_value func = function
 
   let print_value func = function
     | Ok x - &gt; Printf.printf&quot;成功:%s \ n&quot; (func x)
+
     | Ok x -&gt; Printf.printf &quot;Success: %s\n&quot; (func x)
     |エラーs - &gt; Printf.printf "エラー:%s \ n" s
+
     | Error s -&gt; Printf.printf &quot;Error: %s\n&quot; s
終了</pre>
+
end</pre>
==トレース==
+
== Traces ==
  
基本的な構造が完成したので、トレースを含めるためのメカニズムを追加できます。メモとして、上記のエラータイプは、OCaml標準ライブラリの<code> result </code>タイプです。トレースは、エラーメッセージのリストです。失敗したと思われる呼び出しがあり、一連のエラーを返す場合は、その結果を<code> trace </code>関数にラップすることができます。その呼び出しが失敗すると、追加のエラーが追加されます。
+
Now that we have the basic structure down, we can add a mechanism to let us include traces. As a note, the error type I had above is exactly the <code>result</code> type from the OCaml standard library. The traces are just lists of error messages. If you have a call you think might fail, and you want to provide a series of errors, you can wrap that result in the <code>trace</code> function. If that call fails, an additional error is added.
  
..コード:: ocaml
+
.. code:: ocaml
  
<pre>モジュールエラー:sig
+
<pre>module Error : sig
   タイプ 'a t
+
   type 'a t
   戻り値: 'a - &gt; 'いや
+
   val return : 'a -&gt; 'a t
   valエラー:文字列 - &gt; 'いや
+
   val error : string -&gt; 'a t
   val(&gt;&gt;?): 'a t - &gt; 'a - &gt; b t) - &gt; 'b t(* bind *
+
   val (&gt;&gt;?) : 'a t -&gt; ('a -&gt; 'b t) -&gt; 'b t (* bind *)
   val print_value:( 'a - &gt; string) - &gt; 'a t - &gt;単位
+
   val print_value : ('a -&gt; string) -&gt; 'a t -&gt; unit
   valトレース:文字列 - &gt; 'a t - &gt; 'いや
+
   val trace : string -&gt; 'a t -&gt; 'a t
終了=構造体
+
end = struct
   タイプ 'a t =' a、string list)result
+
   type 'a t = ('a, string list) result
   return x = Ok x
+
   let return x = Ok x
   エラーとする=エラー[s]
+
   let error s = Error [ s ]
   let(&gt;&gt ;?)の値func =
+
   let (&gt;&gt;?) value func =
     ?と一致する値
+
     match value with
     | Ok x - &gt; func x
+
     | Ok x -&gt; func x
     |エラーエラー - &gt;エラーエラー
+
     | Error errs -&gt; Error errs
 
   let print_value func = function
 
   let print_value func = function
     | Ok x - &gt; Printf.printf&quot;成功:%s \ n&quot; (func x)
+
     | Ok x -&gt; Printf.printf &quot;Success: %s\n&quot; (func x)
     |エラー[s] - &gt; Printf.printf "エラー:%s \ n" s
+
     | Error [ s ] -&gt; Printf.printf &quot;Error: %s\n&quot; s
     |エラーエラー - &gt; Printf.printf&quot;エラー:\ t%s \ n&quot; (String.concat "\ n \ t"エラー)
+
     | Error errors -&gt; Printf.printf &quot;Errors:\t%s\n&quot; (String.concat &quot;\n\t&quot; errors)
   トレースエラー=機能させる
+
   let trace error = function
     | Ok x - &gt; OK x
+
     | Ok x -&gt; Ok x
     |エラーエラー - &gt;エラー(error :: errors)
+
     | Error errors -&gt; Error (error :: errors)
終了</pre>
+
end</pre>
==よりわかりやすいメッセージ==
+
== A more descriptive message ==
  
トレースはうまくいきますが、メッセージにもっと興味深いデータを格納できるようにしたいと考えています。これを行うには、拡張可能なバリアント型を使用します。拡張可能なバリアントを使用すると、排他性チェックの代償としてバリアントタイプに新しいケースを追加することができます。この作業をうまく行うには、2つの新しいメカニズムが必要になります。 1つはエラー登録方式です。実際のエラーモナドでは、データエンコーディングモジュールが必要です。これは、すべてのデータがTezosでエンコード/デコードされる方法です。このモジュールは、将来の投稿の主題であるはずのコードベースのもう少し複雑な部分です。任意の新しいエラーを宣言できるので、エラーごとにプリンタを追加する方法があります。
+
Even though traces are nice, we really want to be able to store more interesting data in the messages. We’re going to use an extensible variant type to do this. Extensible variants allow us to add a new case to a variant type at the cost of exhaustivity checking. We’re going to need two new mechanisms to make this work well. The first is an error registration scheme. In the actual error monad, this involves the data encoding module, which is how all data is encoded/decoded in Tezos. This module is another decently complicated part of the codebase that should probably the subject of a future post. Since you can declare arbitrary new errors, we’ll have a way of adding a printer for each error.
  
新しいエラーハンドラを追加するときは、<code> register_handler </code>関数を使用します。この関数はエラーを受け取り、<code>文字列オプション</code>を返す関数をとります。これらの関数は次のようになります。
+
When we add a new error handler, we’ll use the <code>register_handler</code> function. This function will take a function that takes an error and returns a <code>string option</code>. These functions will look something like this:
  
..コード:: ocaml
+
.. code:: ocaml
<pre> type error + =文字列のExplosion_failure * int ;;
+
 
 +
<pre>type error += Explosion_failure of string * int;;
  
 
register_error
 
register_error
   (関数
+
   (function
     | Explosion_failure(s、i) - &gt;
+
     | Explosion_failure (s, i) -&gt;
         いくつか(Printf.sprintf "すべてが展開されました:%s at%d" s)
+
         Some (Printf.sprintf &quot;Everything exploded: %s at %d&quot; s i)
     | _&gt;なし)</pre>
+
     | _ -&gt; None)</pre>
また、<code> error </code>関数の名前を<code> fail </code>に変更します。これは、実際のErrormonadモジュールで使用されている規則です。また、必要に応じてディスパッチできるように<code> 't </code>型を公開しています。これはTezosコードベースで数回使用されます。
+
I’m also renaming the <code>error</code> function to <code>fail</code>. This is the convention used by the actual Errormonad module. I’m also exposing the <code>'a t</code> type so that you can dispatch on it if you need to. This is used several times in the Tezos codebase.
  
..コード:: ocaml
+
.. code:: ocaml
  
<pre>モジュールエラー:sig
+
<pre>module Error : sig
   タイプエラー= ..
+
   type error = ..
   タイプ 'a t =' a、エラーリスト)結果
+
   type 'a t = ('a, error list) result
   戻り値: 'a - &gt; 'いや
+
   val return : 'a -&gt; 'a t
   val失敗:error - &gt; 'いや
+
   val fail : error -&gt; 'a t
   val(&gt;&gt;):( 'a - &gt; b t) - &gt; 'a t - &gt; 'b t(* bind *
+
   val (&gt;&gt;?) : ('a -&gt; 'b t) -&gt; 'a t -&gt; 'b t (* bind *)
   val print_value:( 'a - &gt; string) - &gt; 'a t - &gt;単位
+
   val print_value : ('a -&gt; string) -&gt; 'a t -&gt; unit
   valトレース:error - &gt; 'a t - &gt; 'いや
+
   val trace : error -&gt; 'a t -&gt; 'a t
終了=構造体
+
end = struct
   タイプエラー= ..
+
   type error = ..
   タイプ 'a t =' a、エラーリスト)結果
+
   type 'a t = ('a, error list) result
   失敗エラー=エラー[エラー]
+
   let fail error = Error [ error ]
   return x = Ok x
+
   let return x = Ok x
   let(&gt;&gt ;?)func = function
+
   let (&gt;&gt;?) func = function
     | Ok x - &gt; func x
+
     | Ok x -&gt; func x
     |エラーエラー - &gt;エラーエラー
+
     | Error errs -&gt; Error errs
 
   let registered = ref []
 
   let registered = ref []
 
   let register_error handler =
 
   let register_error handler =
     登録済み= =(ハンドラー::!登録済み)
+
     registered := (handler :: !registered)
 
   let default_handler error =
 
   let default_handler error =
     &quot;登録されていないエラー&quot; ^ Obj。(extension_name @@ extension_constructorエラー)
+
     &quot;Unregistered error: &quot; ^ Obj.(extension_name @@ extension_constructor error)
 
   let to_string error =
 
   let to_string error =
     recをfind_handler = functionにする
+
     let rec find_handler = function
       | [] - &gt; default_handlerエラー
+
       | [] -&gt; default_handler error
       |ハンドラ::ハンドラ - &gt;
+
       | handler :: handlers -&gt;
           マッチハンドラのエラーを
+
           begin match handler error with
             |なし - &gt; find_handlerハンドラ
+
             | None -&gt; find_handler handlers
             |いくつかのs - &gt; s
+
             | Some s -&gt; s
           終わり
+
           end
     in find_handler!登録済み
+
     in find_handler !registered
 
   let print_value func = function
 
   let print_value func = function
     | Ok x - &gt; Printf.printf&quot;成功:%s \ n&quot; (func x)
+
     | Ok x -&gt; Printf.printf &quot;Success: %s\n&quot; (func x)
     |エラー[s] - &gt; Printf.printf "エラー:%s \ n" (to_string s)
+
     | Error [ s ] -&gt; Printf.printf &quot;Error: %s\n&quot; (to_string s)
     |エラーエラー - &gt; Printf.printf&quot;エラー:\ t%s \ n&quot; (String.concat "\ n \ t"(List.map to_string errors))
+
     | Error errors -&gt; Printf.printf &quot;Errors:\t%s\n&quot; (String.concat &quot;\n\t&quot; (List.map to_string errors))
   トレースエラー=機能させる
+
   let trace error = function
     | Ok x - &gt; OK x
+
     | Ok x -&gt; Ok x
     |エラーエラー - &gt;エラー(error :: errors)
+
     | Error errors -&gt; Error (error :: errors)
終了</pre>
+
end</pre>
== <code> Lwt.t </code>をミックスに配置する==
+
== Putting <code>Lwt.t</code> in the mix ==
 +
 
 +
Tezos uses the <code>Lwt library &lt;https://ocsigen.org/lwt/3.2.1/manual/manual&gt;</code>__ for threading. The Lwt monad is mixed in with the error monad module. This requires us to add some extra combinators and reexport some functions from Lwt.
  
Tezosはスレッドのために<code> Lwtライブラリ<https://ocsigen.org/lwt/3.2.1/manual/manual&gt; </code> __を使用します。 Lwtモナドは、エラーモナドモジュールと混在しています。これには、追加のコンビネータを追加し、Lwtからいくつかの関数を再エクスポートする必要があります。
+
I’m also renaming the type <code>t</code> to <code>tzresult</code>, as used in the Tezos codebase.
  
また、Tezosコードベースで使用されているように、<code> t </code>のタイプを<code> tzresult </code>に変更します。
+
.. code:: ocaml
  
..コード:: ocaml
+
<pre>module Error : sig
<pre>モジュールエラー:sig
+
   type error = ..
   タイプエラー= ..
+
   type 'a tzresult = ('a, error list) result
   タイプ 'a tzresult =' a、エラーリスト)結果
+
   val ok : 'a -&gt; 'a tzresult
   大丈夫です: 'a - &gt; 'tzresult
+
   val return : 'a -&gt; 'a tzresult Lwt.t
   戻り値: 'a - &gt; 'tzresult Lwt.t
+
   val error : error -&gt; 'a tzresult
   val error:エラー - &gt; 'tzresult
+
   val fail : error -&gt; 'a tzresult Lwt.t
   val失敗:error - &gt; 'tzresult Lwt.t
+
   val (&gt;&gt;?) : 'a tzresult -&gt; ('a -&gt; 'b tzresult) -&gt; 'b tzresult (* bind *)
   val(&gt;&gt;?): 'a tzresult - &gt; 'a - &gt; b tzresult) - &gt; 'b tzresult(* bind *
+
   val (&gt;&gt;=?) : 'a tzresult Lwt.t -&gt; ('a -&gt; 'b tzresult Lwt.t) -&gt; 'b tzresult Lwt.t
   val(&gt;&gt; =): 'a tzresult Lwt.t - 'a - &gt; b tzresult Lwt.t) - &gt; 'b tzresult Lwt.t
+
   val (&gt;&gt;=) : 'a Lwt.t -&gt; ('a -&gt; 'b Lwt.t) -&gt; 'b Lwt.t
   val(&gt; =): 'a Lwt.t - 'a - &gt; b Lwt.t) - &gt; 'b Lwt.t
+
   val print_value : ('a -&gt; string) -&gt; 'a tzresult Lwt.t -&gt; unit Lwt.t
   val print_value:( 'a - &gt; string) - &gt; 'tzresult Lwt.t - &gt;単位Lwt.t
+
   val trace : error -&gt; 'a tzresult Lwt.t -&gt; 'a tzresult Lwt.t
   valトレース:error - &gt; 'tzresult Lwt.t - &gt; 'tzresult Lwt.t
+
end = struct
終了=構造体
+
   type error = ..
   タイプエラー= ..
+
   type 'a tzresult = ('a, error list) result
   タイプ 'a tzresult =' a、エラーリスト)結果
+
   let fail error = Lwt.return (Error [ error ])
   失敗エラー= Lwt.return(エラー[エラー]
+
   let error error = (Error [ error ])
   エラーエラー=(エラー[エラー]
 
 
   let ok x = Ok x
 
   let ok x = Ok x
   return x = Lwt.return(ok x)
+
   let return x = Lwt.return (ok x)
   let(&gt;&gt ;?)の値func =
+
   let (&gt;&gt;?) value func =
     ?と一致する値
+
     match value with
     | Ok x - &gt; func x
+
     | Ok x -&gt; func x
     |エラーエラー - &gt;エラーエラー
+
     | Error errs -&gt; Error errs
   let(&gt; == Lwt.bind
+
   let (&gt;&gt;=) = Lwt.bind
   let(&gt; =?)の値func =
+
   let (&gt;&gt;=?) value func =
     値>&gt; =関数
+
     value &gt;&gt;= function
     | Ok x - &gt; func x
+
     | Ok x -&gt; func x
     |エラーエラー - &gt; Lwt.return(エラーエラー)
+
     | Error errs -&gt; Lwt.return (Error errs)
 
   let registered = ref []
 
   let registered = ref []
 
   let register_error handler =
 
   let register_error handler =
     登録済み= =(ハンドラー::!登録済み)
+
     registered := (handler :: !registered)
 
   let default_handler error =
 
   let default_handler error =
     &quot;登録されていないエラー&quot; ^ Obj。(extension_name @@ extension_constructorエラー)
+
     &quot;Unregistered error: &quot; ^ Obj.(extension_name @@ extension_constructor error)
 
   let to_string error =
 
   let to_string error =
     recをfind_handler = functionにする
+
     let rec find_handler = function
       | [] - &gt; default_handlerエラー
+
       | [] -&gt; default_handler error
       |ハンドラ::ハンドラ - &gt;
+
       | handler :: handlers -&gt;
           マッチハンドラのエラーを
+
           begin match handler error with
             |なし - &gt; find_handlerハンドラ
+
             | None -&gt; find_handler handlers
             |いくつかのs - &gt; s
+
             | Some s -&gt; s
           終わり
+
           end
     in find_handler!登録済み
+
     in find_handler !registered
 
   let print_value func value =
 
   let print_value func value =
     値>&gt; =楽しい値 - &gt;
+
     value &gt;&gt;= fun value -&gt;
     一致する値を
+
     begin match value with
       | Ok x - &gt; Printf.printf&quot;成功:%s \ n&quot; (func x)
+
       | Ok x -&gt; Printf.printf &quot;Success: %s\n&quot; (func x)
       |エラー[s] - &gt; Printf.printf "エラー:%s \ n" (to_string s)
+
       | Error [ s ] -&gt; Printf.printf &quot;Error: %s\n&quot; (to_string s)
       |エラーエラー - &gt; Printf.printf&quot;エラー:\ t%s \ n&quot; (String.concat "\ n \ t"(List.map to_string errors))
+
       | Error errors -&gt; Printf.printf &quot;Errors:\t%s\n&quot; (String.concat &quot;\n\t&quot; (List.map to_string errors))
     終わり; Lwt.return()
+
     end; Lwt.return ()
   トレースエラー値=
+
   let trace error value =
     値>&gt; =関数
+
     value &gt;&gt;= function
     | Ok x - &gt;戻り値x
+
     | Ok x -&gt; return x
     |エラーエラー - &gt; Lwt.return(Error(error :: errors))
+
     | Error errors -&gt; Lwt.return (Error (error :: errors))
終了</pre>
+
end</pre>
==実際のTezosエラーモナド==
+
== The actual Tezos error monad ==
  
実際のTezosのエラーモナドはいくつかを追加します。まず、エラーには3つのカテゴリがあります。
+
The actual Tezos error monad adds a few things. Firstly, there are three categories of errors:
  
*:リテラル:<code> \ </code> Temporary` - 契約の残高が低すぎて意図した操作を実行できないなど、将来有効な操作の結果生じるエラーです。これは、契約の残高にさらに追加することで修正できます。
+
* :literal:<code>\</code>Temporary` - An error resulting from an operation that might be valid in the future, for example, a contract’s balance being too low to execute the intended operation. This can be fixed by adding more to the contract’s balance.
*:リテラル:<code> \ </code> Branch` - チェーンの1つのブランチで発生しますが、別のブランチでは発生しないエラーです。たとえば、古いプロトコルバージョンまたは将来のプロトコルバージョンの操作を受け取ります。
+
* :literal:<code>\</code>Branch` - An error that occurs in one branch of the chain, but may not occur in a different one. For example, receiving an operation for an old or future protocol version.
*:リテラル:<code> \ </code> Permanent` - 操作が決して有効にならないために回復できないエラー。たとえば、無効な?表記
+
* :literal:<code>\</code>Permanent` - An error that is not recoverable because the operation is never going to be valid. For example, an invalid ? notation.
  
登録スキームでは、データエンコーディングも使用されます。以下は、<code>バリデーター</api / odoc / tezos-node-shell / Tezos_node_shell / Validator / index.html&gt; </code> __の例です。
+
The registration scheme also uses data encodings. Here’s an example from the <code>validator &lt;../api/odoc/tezos-node-shell/Tezos_node_shell/Validator/index.html&gt;</code>__:
  
..コード:: ocaml
+
.. code:: ocaml
  
<pre> register_error_kind
+
<pre>register_error_kind
     `永久
+
     `Permanent
     ?id:&quot; validator.wrong_level&quot;
+
     ~id:&quot;validator.wrong_level&quot;
     ?タイトル:&quot;間違ったレベル&quot;
+
     ~title:&quot;Wrong level&quot;
     ?description:&quot;ブロックレベルは期待されたものではありません&quot;
+
     ~description:&quot;The block level is not the expected one&quot;
     ?pp:(楽しいppf(e、g) - &gt;
+
     ~pp:(fun ppf (e, g) -&gt;
 
         Format.fprintf ppf
 
         Format.fprintf ppf
           "宣言されたレベル%1dは%1dではありません" g e)
+
           &quot;The declared level %ld is not %ld&quot; g e)
     Data_encoding。(obj2
+
     Data_encoding.(obj2
                     (req "expected" int32)
+
                     (req &quot;expected&quot; int32)
                     (req "提供された" int32))
+
                     (req &quot;provided&quot; int32))
     (関数Wrong_level(e、g) - > Some(e、g)| _ - > None)
+
     (function Wrong_level (e, g)  -&gt; Some (e, g) | _ -&gt; None)
     (fun(e、g) - &gt; Wrong_level(e、g))</pre>
+
     (fun (e, g) -&gt; Wrong_level (e, g))</pre>
エラーには、カテゴリ、ID、タイトル、説明、およびエンコーディングが使用されます。エンコーディングタイプのオプションの値にエラーを返す関数と、エンコードされたタイプの値を取得してエラー値を作成する関数を指定する必要があります。きれいなプリンタを任意に指定することもできますが、省略することもできます。
+
An error takes a category, id, title, description, and encoding. You must specify a function to take an error to an optional value of the encoding type and a function to take a value of the encoded type and create an error value. A pretty printer can optionally be specified, but may also be omitted.
  
実際のエラーモナドとそのトレース機能は、この関数では契約を解析します:
+
The actual error monad and it’s tracing features can be seen in this function which parses contracts:
  
..コード:: ocaml
+
.. code:: ocaml
  
<pre> let parse_script
+
<pre>let parse_script
   :?type_logger:(int *(Script.expr list * Script.expr list) - &gt; unit) - &gt;
+
   : ?type_logger: (int * (Script.expr list * Script.expr list) -&gt; unit) -&gt;
   コンテキスト - &gt; Script.storage - &gt; Script.code - &gt; ex_script tzresult Lwt.t
+
   context -&gt; Script.storage -&gt; Script.code -&gt; ex_script tzresult Lwt.t
   = fun?type_logger ctxt
+
   = fun ?type_logger ctxt
     { ストレージ; storage_type = init_storage_type}
+
     { storage; storage_type = init_storage_type }
     {コード; arg_type; ret_type; storage_type} - &gt;
+
     { code; arg_type; ret_type; storage_type } -&gt;
     トレース
+
     trace
       (Ill_formed_type(some "parameter"、arg_type))
+
       (Ill_formed_type (Some &quot;parameter&quot;, arg_type))
       (Lwt.return(parse_ty arg_type))&gt; =? fun(Ex_ty arg_type) - &gt;
+
       (Lwt.return (parse_ty arg_type)) &gt;&gt;=? fun (Ex_ty arg_type) -&gt;
     トレース
+
     trace
       (Ill_formed_type(いくつかの "return"、ret_type))
+
       (Ill_formed_type (Some &quot;return&quot;, ret_type))
       (Lwt.return(parse_ty ret_type))&gt;&gt; =?楽しみ(Ex_ty ret_type) - &gt;
+
       (Lwt.return (parse_ty ret_type)) &gt;&gt;=? fun (Ex_ty ret_type) -&gt;
     トレース
+
     trace
       (Ill_formed_type(いくつかの "初期ストレージ"、init_storage_type))
+
       (Ill_formed_type (Some &quot;initial storage&quot;, init_storage_type))
       (Lwt.return(parse_ty init_storage_type))&gt; =? fun(Ex_ty init_storage_type) - &gt;
+
       (Lwt.return (parse_ty init_storage_type)) &gt;&gt;=? fun (Ex_ty init_storage_type) -&gt;
     トレース
+
     trace
       (Ill_formed_type(いくつかの "storage"、storage_type))
+
       (Ill_formed_type (Some &quot;storage&quot;, storage_type))
       (Lwt.return(parse_ty storage_type))&gt; =?楽しい(Ex_ty storage_type) - &gt;
+
       (Lwt.return (parse_ty storage_type)) &gt;&gt;=? fun (Ex_ty storage_type) -&gt;
     arg_type_full = Pair_t(arg_type、storage_type)を
+
     let arg_type_full = Pair_t (arg_type, storage_type) in
     ret_type_full = Pair_t(ret_type、storage_type)を
+
     let ret_type_full = Pair_t (ret_type, storage_type) in
     Lwt.return(ty_eq init_storage_type storage_type)&gt;&gt; =?楽しい(Eq _) - &gt;
+
     Lwt.return (ty_eq init_storage_type storage_type) &gt;&gt;=? fun (Eq _) -&gt;
     トレース
+
     trace
       (Ill_typed_data(None、storage、storage_type))
+
       (Ill_typed_data (None, storage, storage_type))
       (parse_data?type_logger ctxt storage_type storage)&gt; =?楽しいストレージ - &gt;
+
       (parse_data ?type_logger ctxt storage_type storage) &gt;&gt;=? fun storage -&gt;
     トレース
+
     trace
       (Ill_typed_contract(code、arg_type、ret_type、storage_type、[]))
+
       (Ill_typed_contract (code, arg_type, ret_type, storage_type, []))
       (parse_returning(Toplevel {storage_type})ctxt?type_logger arg_type_full ret_type_full code)
+
       (parse_returning (Toplevel { storage_type }) ctxt ?type_logger arg_type_full ret_type_full code)
     &gt; =?楽しいコード - &gt;
+
     &gt;&gt;=? fun code -&gt;
     return(Ex_script {code; arg_type; ret_type; storage; storage_type}</pre>
+
     return (Ex_script { code; arg_type; ret_type; storage; storage_type })</pre>
型チェックプロセスの各特定の型エラーは、プログラムのどの部分が不正であったかを説明する、より一般的なエラーに包まれています。これにより、エラー報告が改善されます。また、関数間で使用されるバインド演算子が表示され、エラーが発生しない場合にのみ処理を継続することができます。この関数は、<code> Lwt </code>モナドでも動作します。これは、大部分がエラーモナドによって隠されています。
+
Each specific type error from the typechecking process is wrapped in a more general error that explains which part of the program was malformed. This improves the error reporting. You can also see the bind operator used between functions to continue only if an error does not occur. This function also operates in the <code>Lwt</code> monad, which is largely hidden via the error monad.

tezos-wikiへの投稿はすべて、a Creative Commons Attribution-ShareAlike 3.0 License (詳細はTezos-wiki:著作権を参照)のもとで公開したと見なされることにご注意ください。 自分が書いたものが他の人に容赦なく編集され、自由に配布されるのを望まない場合は、ここに投稿しないでください。
また、投稿するのは、自分で書いたものか、パブリック ドメインまたはそれに類するフリーな資料からの複製であることを約束してください。 著作権保護されている作品は、許諾なしに投稿しないでください!

取り消し | 編集の仕方 (新しいウィンドウで開きます)