Skip to content

Commit 0d0130f

Browse files
committed
some fixup
1 parent be64c42 commit 0d0130f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

1.9/ja/book/error-handling.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ Rustでは戻り値を使います。
1818
こうすることで、全体がどう組み合わさっているのかの理解が進み、より実用的な知識が身につくでしょう。
1919

2020
<!-- When done naïvely, error handling in Rust can be verbose and annoying. This -->
21-
<!-- chapter will explore those stumbling blocks and demonstrate how to use the -->
21+
<!-- section will explore those stumbling blocks and demonstrate how to use the -->
2222
<!-- standard library to make error handling concise and ergonomic. -->
2323
もし素朴なやり方を用いたなら、Rustにおけるエラーハンドリングは、冗長で面倒なものになり得ます。
24-
この章では、エラーを処理する上でどのような課題があるかを吟味し、標準ライブラリを使うと、それがいかにシンプルでエルゴノミック(人間にとって扱いやすいもの)に変わるのかを紹介します。
24+
このセクションでは、エラーを処理する上でどのような課題があるかを吟味し、標準ライブラリを使うと、それがいかにシンプルでエルゴノミック(人間にとって扱いやすいもの)に変わるのかを紹介します。
2525

2626
<!-- # Table of Contents -->
2727
# 目次
@@ -1048,7 +1048,7 @@ fn ok_or<T, E>(option: Option<T>, err: E) -> Result<T, E> {
10481048
これは `Result::map` に似ていますが、 `Result` 値の *エラー* の部分に対して関数をマップするところが異なります。
10491049
もし `Result` の値が `Ok(...)` だったら、そのまま変更せずに返します。
10501050

1051-
<!-- `map_err` is the trick that makes all of this work. `map_err` is like -->
1051+
<!-- We use `map_err` here because it is necessary for the error types to remain -->
10521052
<!-- the same (because of our use of `and_then`). Since we chose to convert the -->
10531053
<!-- `Option<String>` (from `argv.nth(1)`) to a `Result<String, String>`, we must -->
10541054
<!-- also convert the `ParseIntError` from `arg.parse()` to a `String`. -->
@@ -1231,7 +1231,7 @@ fn main() {
12311231
例えば、一番最後の `map` の呼び出しは、`Ok(...)` の値( `i32` 型)に `2` を掛けます。
12321232
もし、これより前にエラーが起きたなら、この操作は `map` の定義に従ってスキップされます。
12331233

1234-
<!-- `map_err` is the trick that makes all of this work. `map_err` is just like -->
1234+
<!-- `map_err` is the trick that makes all of this work. `map_err` is like -->
12351235
<!-- `map`, except it applies a function to the `Err(...)` value of a `Result`. In -->
12361236
<!-- this case, we want to convert all of our errors to one type: `String`. Since -->
12371237
<!-- both `io::Error` and `num::ParseIntError` implement `ToString`, we can call the -->
@@ -1875,7 +1875,7 @@ fn file_double<P: AsRef<Path>>(file_path: P) -> Result<i32, Box<Error>> {
18751875
しかし `Box<Error>` が不透明であるという制限は残ります。
18761876
(注意:これは完全な真実ではありません。
18771877
なぜならRustでは実行時のリフレクションができるからです。
1878-
この方法が有効なシナリオもありますが、[この章で扱う範囲を超えています](https://crates.io/crates/error)
1878+
この方法が有効なシナリオもありますが、[このセクションで扱う範囲を超えています](https://crates.io/crates/error)
18791879

18801880
<!-- It's time to revisit our custom `CliError` type and tie everything together. -->
18811881
では、私たちの独自のエラー型 `CliError` に戻って、全てを一つにまとめ上げましょう。
@@ -2085,7 +2085,7 @@ impl From<num::ParseFloatError> for CliError {
20852085
<!-- rather dense. While there is plenty of example code to go along with -->
20862086
<!-- the prose, most of it was specifically designed to be pedagogical. So, -->
20872087
<!-- we're going to do something new: a case study. -->
2088-
この章は長かったですね
2088+
このセクションは長かったですね
20892089
あなたのバックグラウンドにもよりますが、内容が少し濃すぎたかもしれません。
20902090
たくさんのコード例に、散文的な説明が添えられる形で進行しましたが、これは主に学習を助けるために、あえてこう構成されていたのでした。
20912091
次はなにか新しいことをしましょう。ケーススタディです。
@@ -2743,8 +2743,10 @@ impl Error for CliError {
27432743
match *self {
27442744
CliError::Io(ref err) => Some(err),
27452745
CliError::Parse(ref err) => Some(err),
2746-
// Our custom error doesn't have an underlying cause, but we could
2747-
// modify it so that it does.
2746+
# // Our custom error doesn't have an underlying cause, but we could
2747+
# // modify it so that it does.
2748+
// 今回の自前のエラーは下流の原因となるエラーは持っていませんが
2749+
// そのように変更することも可能です。
27482750
CliError::NotFound() => None,
27492751
}
27502752
}
@@ -2963,7 +2965,7 @@ match search(&args.arg_data_path, &args.arg_city) {
29632965
<!-- found a healthy mix of `try!` and combinators to be quite appealing. -->
29642966
<!-- `and_then`, `map` and `unwrap_or` are my favorites. -->
29652967
* もし短いサンプルコードを書いていて、エラーハンドリングが重荷になるようなら、 `unwrap` を使っても大丈夫かもしれません( [`Result::unwrap`](../std/result/enum.Result.html#method.unwrap), [`Option::unwrap`](../std/option/enum.Option.html#method.unwrap), [`Option::expect`](../std/option/enum.Option.html#method.expect) のいずれかが使えます)。
2966-
あなたのコードを参考にする人は、正しいエラーハンドリングについて知っているべきです。(そうでなければ、この章を紹介してください!)
2968+
あなたのコードを参考にする人は、正しいエラーハンドリングについて知っているべきです。(そうでなければ、このセクションを紹介してください!)
29672969
* もし即興のプログラムを書いているなら `unwrap` を使うことに罪悪感を持たなくてもいいでしょう。
29682970
ただし警告があります:もしそれが最終的に他の人たちの手に渡るなら、彼らが貧弱なエラーメッセージに動揺してもおかしくありません。
29692971
* もし即興のプログラムを書いていて、パニックすることに、どうしても後ろめたさを感じるなら、エラー型として `String``Box<Error + Send + Sync>` のいずれかを使ってください( `Box<Error + Send + Sync>`[`From` 実装がある](../std/convert/trait.From.html) ので使えます)。

0 commit comments

Comments
 (0)