Skip to content

Commit 1d6a5ad

Browse files
committed
Toml: remove error message redundancy
1 parent 4c22948 commit 1d6a5ad

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Diff for: src/Rustify/Result.hpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,22 @@ inline constexpr auto to_anyhow = [](std::string e) {
7272
namespace toml {
7373

7474
template <typename T, typename... U>
75-
inline auto
76-
try_find(const toml::value& v, const U&... u) noexcept
77-
-> Result<decltype(toml::find<T>(v, u...))> {
75+
inline Result<T>
76+
try_find(const toml::value& v, const U&... u) noexcept {
77+
using namespace std::string_view_literals; // NOLINT
78+
7879
try {
7980
return Ok(toml::find<T>(v, u...));
8081
} catch (const std::exception& e) {
81-
return Err(anyhow::anyhow(std::string(e.what())));
82+
std::string what = e.what();
83+
// TODO: make the same fix on upstream
84+
if (what.starts_with("[error] ")) {
85+
what = what.substr("[error] "sv.size());
86+
}
87+
if (what.back() == '\n') {
88+
what.pop_back(); // remove the last '\n' since logger::error adds one.
89+
}
90+
return Err(anyhow::anyhow(what));
8291
}
8392
}
8493

Diff for: tests/03-fmt.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,11 @@ test_expect_success 'cabin fmt without name in manifest' '
8888
echo "[package]" >cabin.toml &&
8989
test_must_fail "$CABIN_BIN" fmt 2>actual &&
9090
cat >expected <<-EOF &&
91-
Error: [error] toml::value::at: key "name" not found
91+
Error: toml::value::at: key "name" not found
9292
--> $(realpath $OUT)/pkg/cabin.toml
9393
|
9494
1 | [package]
9595
| ^^^^^^^^^-- in this table
96-
9796
EOF
9897
test_cmp expected actual
9998
)

0 commit comments

Comments
 (0)