|
19 | 19 | use std::env; |
20 | 20 | use std::fs; |
21 | 21 | use std::io::Error; |
22 | | -use std::io::ErrorKind; |
23 | 22 | use std::io::Result; |
24 | 23 | use std::path::Path; |
25 | 24 | use std::process::Command; |
@@ -48,32 +47,31 @@ fn build_proto() -> Result<()> { |
48 | 47 | let output = cmd.output()?; |
49 | 48 | let version = if output.status.success() { |
50 | 49 | let content = String::from_utf8_lossy(&output.stdout); |
51 | | - let content = content.trim().split(' ').last().ok_or_else(|| { |
52 | | - Error::new( |
53 | | - ErrorKind::Other, |
54 | | - format!("protoc --version got unexpected output: {}", content), |
55 | | - ) |
| 50 | + let content = content.trim().split(' ').next_back().ok_or_else(|| { |
| 51 | + Error::other(format!( |
| 52 | + "protoc --version got unexpected output: {}", |
| 53 | + content |
| 54 | + )) |
56 | 55 | })?; |
57 | 56 | lenient_semver::parse(content).map_err(|err| { |
58 | | - Error::new( |
59 | | - ErrorKind::Other, |
60 | | - format!("protoc --version doesn't return valid version: {:?}", err), |
61 | | - ) |
| 57 | + Error::other(format!( |
| 58 | + "protoc --version doesn't return valid version: {:?}", |
| 59 | + err |
| 60 | + )) |
62 | 61 | })? |
63 | 62 | } else { |
64 | | - return Err(Error::new( |
65 | | - ErrorKind::Other, |
66 | | - format!("protoc failed: {}", String::from_utf8_lossy(&output.stderr)), |
67 | | - )); |
| 63 | + return Err(Error::other(format!( |
| 64 | + "protoc failed: {}", |
| 65 | + String::from_utf8_lossy(&output.stderr) |
| 66 | + ))); |
68 | 67 | }; |
69 | 68 |
|
70 | 69 | let mut config = prost_build::Config::new(); |
71 | 70 | config.btree_map(["."]); |
72 | 71 |
|
73 | 72 | // Version before 3.12 doesn't support allow_proto3_optional |
74 | 73 | if version < Version::new(3, 12, 0) { |
75 | | - return Err(Error::new( |
76 | | - ErrorKind::Other, |
| 74 | + return Err(Error::other( |
77 | 75 | format!( |
78 | 76 | "protoc version is outdated, expect: >= 3.12.0, actual: {version}, reason: need feature --experimental_allow_proto3_optional" |
79 | 77 | ), |
|
0 commit comments