mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +00:00
Shell: Replace Result<T, E> use with ErrorOr<T>
This commit is contained in:
parent
184810a581
commit
d1477bcb8e
3 changed files with 11 additions and 12 deletions
|
@ -3583,24 +3583,24 @@ Vector<String> TildeValue::resolve_as_list(RefPtr<Shell> shell)
|
|||
return { resolve_slices(shell, shell->expand_tilde(builder.to_string()), m_slices) };
|
||||
}
|
||||
|
||||
Result<NonnullRefPtr<Rewiring>, String> CloseRedirection::apply() const
|
||||
ErrorOr<NonnullRefPtr<Rewiring>> CloseRedirection::apply() const
|
||||
{
|
||||
return adopt_ref(*new Rewiring(fd, fd, Rewiring::Close::ImmediatelyCloseNew));
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) Rewiring(fd, fd, Rewiring::Close::ImmediatelyCloseNew));
|
||||
}
|
||||
|
||||
CloseRedirection::~CloseRedirection()
|
||||
{
|
||||
}
|
||||
|
||||
Result<NonnullRefPtr<Rewiring>, String> PathRedirection::apply() const
|
||||
ErrorOr<NonnullRefPtr<Rewiring>> PathRedirection::apply() const
|
||||
{
|
||||
auto check_fd_and_return = [my_fd = this->fd](int fd, const String& path) -> Result<NonnullRefPtr<Rewiring>, String> {
|
||||
auto check_fd_and_return = [my_fd = this->fd](int fd, String const& path) -> ErrorOr<NonnullRefPtr<Rewiring>> {
|
||||
if (fd < 0) {
|
||||
String error = strerror(errno);
|
||||
auto error = Error::from_errno(errno);
|
||||
dbgln("open() failed for '{}' with {}", path, error);
|
||||
return error;
|
||||
}
|
||||
return adopt_ref(*new Rewiring(fd, my_fd, Rewiring::Close::Old));
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) Rewiring(fd, my_fd, Rewiring::Close::Old));
|
||||
};
|
||||
switch (direction) {
|
||||
case AST::PathRedirection::WriteAppend:
|
||||
|
|
|
@ -84,7 +84,7 @@ struct Rewiring : public RefCounted<Rewiring> {
|
|||
};
|
||||
|
||||
struct Redirection : public RefCounted<Redirection> {
|
||||
virtual Result<NonnullRefPtr<Rewiring>, String> apply() const = 0;
|
||||
virtual ErrorOr<NonnullRefPtr<Rewiring>> apply() const = 0;
|
||||
virtual ~Redirection();
|
||||
virtual bool is_path_redirection() const { return false; }
|
||||
virtual bool is_fd_redirection() const { return false; }
|
||||
|
@ -94,7 +94,7 @@ struct Redirection : public RefCounted<Redirection> {
|
|||
struct CloseRedirection : public Redirection {
|
||||
int fd { -1 };
|
||||
|
||||
virtual Result<NonnullRefPtr<Rewiring>, String> apply() const override;
|
||||
virtual ErrorOr<NonnullRefPtr<Rewiring>> apply() const override;
|
||||
virtual ~CloseRedirection();
|
||||
CloseRedirection(int fd)
|
||||
: fd(fd)
|
||||
|
@ -120,7 +120,7 @@ struct PathRedirection : public Redirection {
|
|||
return adopt_ref(*new PathRedirection(move(path), fd, direction));
|
||||
}
|
||||
|
||||
virtual Result<NonnullRefPtr<Rewiring>, String> apply() const override;
|
||||
virtual ErrorOr<NonnullRefPtr<Rewiring>> apply() const override;
|
||||
virtual ~PathRedirection();
|
||||
|
||||
private:
|
||||
|
@ -148,7 +148,7 @@ public:
|
|||
|
||||
virtual ~FdRedirection();
|
||||
|
||||
virtual Result<NonnullRefPtr<Rewiring>, String> apply() const override
|
||||
virtual ErrorOr<NonnullRefPtr<Rewiring>> apply() const override
|
||||
{
|
||||
return adopt_ref(*new Rewiring(old_fd, new_fd, other_pipe_end, action));
|
||||
}
|
||||
|
|
|
@ -603,7 +603,6 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
|
|||
auto resolve_redirection = [&](auto& redirection) -> IterationDecision {
|
||||
auto rewiring_result = redirection.apply();
|
||||
if (rewiring_result.is_error()) {
|
||||
if (!rewiring_result.error().is_empty())
|
||||
warnln("error: {}", rewiring_result.error());
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue