From d1477bcb8ec617fd7bd00eb2949502c00f429c77 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 7 Nov 2021 11:36:11 +0100 Subject: [PATCH] Shell: Replace Result use with ErrorOr --- Userland/Shell/AST.cpp | 12 ++++++------ Userland/Shell/AST.h | 8 ++++---- Userland/Shell/Shell.cpp | 3 +-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Userland/Shell/AST.cpp b/Userland/Shell/AST.cpp index 5608adb3a2..a32c22f69e 100644 --- a/Userland/Shell/AST.cpp +++ b/Userland/Shell/AST.cpp @@ -3583,24 +3583,24 @@ Vector TildeValue::resolve_as_list(RefPtr shell) return { resolve_slices(shell, shell->expand_tilde(builder.to_string()), m_slices) }; } -Result, String> CloseRedirection::apply() const +ErrorOr> 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, String> PathRedirection::apply() const +ErrorOr> PathRedirection::apply() const { - auto check_fd_and_return = [my_fd = this->fd](int fd, const String& path) -> Result, String> { + auto check_fd_and_return = [my_fd = this->fd](int fd, String const& path) -> ErrorOr> { 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: diff --git a/Userland/Shell/AST.h b/Userland/Shell/AST.h index 0d0d7ed51b..4f3722854f 100644 --- a/Userland/Shell/AST.h +++ b/Userland/Shell/AST.h @@ -84,7 +84,7 @@ struct Rewiring : public RefCounted { }; struct Redirection : public RefCounted { - virtual Result, String> apply() const = 0; + virtual ErrorOr> 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 { struct CloseRedirection : public Redirection { int fd { -1 }; - virtual Result, String> apply() const override; + virtual ErrorOr> 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, String> apply() const override; + virtual ErrorOr> apply() const override; virtual ~PathRedirection(); private: @@ -148,7 +148,7 @@ public: virtual ~FdRedirection(); - virtual Result, String> apply() const override + virtual ErrorOr> apply() const override { return adopt_ref(*new Rewiring(old_fd, new_fd, other_pipe_end, action)); } diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp index 2b3062b62b..e1a8137402 100644 --- a/Userland/Shell/Shell.cpp +++ b/Userland/Shell/Shell.cpp @@ -603,8 +603,7 @@ RefPtr 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()); + warnln("error: {}", rewiring_result.error()); return IterationDecision::Break; } auto& rewiring = rewiring_result.value();