aboutsummaryrefslogtreecommitdiff
path: root/include/matcherexception.h
blob: 2046cf820bbddd0a4c0b09a31c308380ca8ffbb2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef NEWSBOAT_MATCHEREXCEPTON_H_
#define NEWSBOAT_MATCHEREXCEPTON_H_

#include <cstdint>
#include <string>

namespace newsboat {

struct MatcherErrorFfi;

class MatcherException : public std::exception {
public:
	// Numbers here MUST match constants in rust/libnewsboat-ffi/src/matchererror.rs
	enum class Type : std::uint8_t { ATTRIB_UNAVAIL = 0, INVALID_REGEX = 1 };

	MatcherException(Type et,
		const std::string& info,
		const std::string& info2 = "")
		: type_(et)
		, addinfo(info)
		, addinfo2(info2)
	{
	}

	~MatcherException() throw() override {}
	const char* what() const throw() override;

	static MatcherException from_rust_error(MatcherErrorFfi error);

	// Getters for testing purposes. Ugly, but alas.
	Type type() const
	{
		return type_;
	}

	std::string info() const
	{
		return addinfo;
	}

	std::string info2() const
	{
		return addinfo2;
	}

private:
	Type type_;
	std::string addinfo;
	std::string addinfo2;
};

/// A description of an error returned by Rust. This can be converted into
/// `MatcherException` object with `MatcherException::from_rust_error`
struct MatcherErrorFfi {
	MatcherException::Type type;
	char* info;
	char* info2;
};

} // namespace newsboat

#endif /* NEWSBOAT_MATCHEREXCEPTON_H_ */