diff --git a/Userland/Shell/AST.cpp b/Userland/Shell/AST.cpp index 7b368e44dc..54850e0cab 100644 --- a/Userland/Shell/AST.cpp +++ b/Userland/Shell/AST.cpp @@ -171,7 +171,7 @@ static ErrorOr resolve_slices(RefPtr shell, String&& input_value, return move(input_value); } - auto index_values = value->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors(); + auto index_values = TRY(value->resolve_as_list(shell)); Vector indices; indices.ensure_capacity(index_values.size()); @@ -200,7 +200,7 @@ static ErrorOr resolve_slices(RefPtr shell, String&& input_value, for (auto& index : indices) builder.append(input_value.bytes_as_string_view()[index]); - input_value = builder.to_string().release_value_but_fixme_should_propagate_errors(); + input_value = TRY(builder.to_string()); } return move(input_value); @@ -221,7 +221,7 @@ static ErrorOr> resolve_slices(RefPtr shell, Vectorresolve_as_list(shell).release_value_but_fixme_should_propagate_errors(); + auto index_values = TRY(value->resolve_as_list(shell)); Vector indices; indices.ensure_capacity(index_values.size()); @@ -288,7 +288,7 @@ ErrorOr Node::for_each_entry(RefPtr shell, Functionis_list_without_resolution()) { - auto list = value->resolve_without_cast(shell).release_value_but_fixme_should_propagate_errors(); + auto list = TRY(value->resolve_without_cast(shell)); for (auto& element : static_cast(list.ptr())->values()) { if (TRY(callback(element)) == IterationDecision::Break) break; @@ -296,7 +296,7 @@ ErrorOr Node::for_each_entry(RefPtr shell, Functionresolve_as_list(shell).release_value_but_fixme_should_propagate_errors(); + auto list = TRY(value->resolve_as_list(shell)); for (auto& element : list) { if (TRY(callback(make_ref_counted(move(element)))) == IterationDecision::Break) break; @@ -494,8 +494,8 @@ ErrorOr> ListConcatenate::run(RefPtr shell) if (result->is_command() || element_value->is_command()) { auto joined_commands = join_commands( - result->resolve_as_commands(shell).release_value_but_fixme_should_propagate_errors(), - element_value->resolve_as_commands(shell).release_value_but_fixme_should_propagate_errors()); + TRY(result->resolve_as_commands(shell)), + TRY(element_value->resolve_as_commands(shell))); if (joined_commands.size() == 1) { auto& command = joined_commands[0]; @@ -1049,7 +1049,7 @@ ErrorOr> DynamicEvaluate::run(RefPtr shell) // Dynamic Evaluation behaves differently between strings and lists. // Strings are treated as variables, and Lists are treated as commands. if (result->is_string()) { - auto name_part = result->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors(); + auto name_part = TRY(result->resolve_as_list(shell)); VERIFY(name_part.size() == 1); return make_ref_counted(name_part[0]); } @@ -2271,9 +2271,9 @@ ErrorOr> MatchExpr::run(RefPtr shell) if (shell && shell->has_any_error()) return make_ref_counted({}); - auto list = value->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors(); + auto list = TRY(value->resolve_as_list(shell)); - auto list_matches = [&](auto&& pattern, auto& spans) { + auto list_matches = [&](auto&& pattern, auto& spans) -> ErrorOr { if constexpr (IsSame, Regex>) { if (list.size() != 1) return false; @@ -2285,7 +2285,7 @@ ErrorOr> MatchExpr::run(RefPtr shell) spans.ensure_capacity(match.n_capture_groups); for (size_t i = 0; i < match.n_capture_groups; ++i) { auto& capture = match.capture_group_matches[0][i]; - spans.append(capture.view.to_string().release_value_but_fixme_should_propagate_errors()); + spans.append(TRY(capture.view.to_string())); } return true; } else { @@ -2297,7 +2297,7 @@ ErrorOr> MatchExpr::run(RefPtr shell) if (!list[i].bytes_as_string_view().matches(pattern[i], mask_spans)) return false; for (auto& span : mask_spans) - spans.append(list[i].substring_from_byte_offset(span.start, span.length).release_value_but_fixme_should_propagate_errors()); + spans.append(TRY(list[i].substring_from_byte_offset(span.start, span.length))); } return true; @@ -2341,7 +2341,7 @@ ErrorOr> MatchExpr::run(RefPtr shell) auto result = TRY(entry.options.visit([&](auto& options) -> ErrorOr>> { for (auto& option : options) { Vector spans; - if (list_matches(TRY(resolve_pattern(option)), spans)) { + if (TRY(list_matches(TRY(resolve_pattern(option)), spans))) { if (entry.body) { if (entry.match_names.has_value()) { size_t i = 0; @@ -2620,7 +2620,7 @@ ErrorOr PathRedirectionNode::highlight_in_editor(Line::Editor& editor, She auto& position = m_path->position(); auto& path = path_text[0]; if (!path.starts_with('/')) - path = String::formatted("{}/{}", shell.cwd, path).release_value_but_fixme_should_propagate_errors(); + path = TRY(String::formatted("{}/{}", shell.cwd, path)); auto url = URL::create_with_file_scheme(path.to_deprecated_string()); url.set_host(TRY(String::from_deprecated_string(shell.hostname))); editor.stylize({ position.start_offset, position.end_offset }, { Line::Style::Hyperlink(url.to_deprecated_string()) }); @@ -2667,12 +2667,12 @@ ErrorOr Range::dump(int level) const ErrorOr> Range::run(RefPtr shell) { - auto interpolate = [position = position()](RefPtr start, RefPtr end, RefPtr shell) -> Vector> { + auto interpolate = [position = position()](RefPtr start, RefPtr end, RefPtr shell) -> ErrorOr>> { Vector> values; if (start->is_string() && end->is_string()) { - auto start_str = start->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors()[0]; - auto end_str = end->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors()[0]; + auto start_str = TRY(start->resolve_as_list(shell))[0]; + auto end_str = TRY(end->resolve_as_list(shell))[0]; Utf8View start_view { start_str }, end_view { end_str }; if (start_view.validate() && end_view.validate()) { @@ -2685,12 +2685,12 @@ ErrorOr> Range::run(RefPtr shell) for (u32 code_point = start_code_point; code_point != end_code_point; code_point += step) { builder.clear(); builder.append_code_point(code_point); - values.append(make_ref_counted(builder.to_string().release_value_but_fixme_should_propagate_errors())); + values.append(make_ref_counted(TRY(builder.to_string()))); } // Append the ending code point too, most shells treat this as inclusive. builder.clear(); builder.append_code_point(end_code_point); - values.append(make_ref_counted(builder.to_string().release_value_but_fixme_should_propagate_errors())); + values.append(make_ref_counted(TRY(builder.to_string()))); } else { // Could be two numbers? auto start_int = start_str.bytes_as_string_view().to_int(); @@ -2700,9 +2700,9 @@ ErrorOr> Range::run(RefPtr shell) auto end = end_int.value(); auto step = start > end ? -1 : 1; for (int value = start; value != end; value += step) - values.append(make_ref_counted(String::number(value).release_value_but_fixme_should_propagate_errors())); + values.append(make_ref_counted(TRY(String::number(value)))); // Append the range end too, most shells treat this as inclusive. - values.append(make_ref_counted(String::number(end).release_value_but_fixme_should_propagate_errors())); + values.append(make_ref_counted(TRY(String::number(end)))); } else { goto yield_start_end; } @@ -2733,7 +2733,7 @@ ErrorOr> Range::run(RefPtr shell) if (!start_value || !end_value) return make_ref_counted({}); - return make_ref_counted(interpolate(*start_value, *end_value, shell)); + return make_ref_counted(TRY(interpolate(*start_value, *end_value, shell))); } ErrorOr Range::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -2795,7 +2795,7 @@ ErrorOr> ReadRedirection::run(RefPtr shell) StringBuilder builder; builder.join(' ', path_segments); - command.redirections.append(PathRedirection::create(builder.to_string().release_value_but_fixme_should_propagate_errors(), m_fd, PathRedirection::Read)); + command.redirections.append(PathRedirection::create(TRY(builder.to_string()), m_fd, PathRedirection::Read)); return make_ref_counted(move(command)); } @@ -2826,7 +2826,7 @@ ErrorOr> ReadWriteRedirection::run(RefPtr shell) StringBuilder builder; builder.join(' ', path_segments); - command.redirections.append(PathRedirection::create(builder.to_string().release_value_but_fixme_should_propagate_errors(), m_fd, PathRedirection::ReadWrite)); + command.redirections.append(PathRedirection::create(TRY(builder.to_string()), m_fd, PathRedirection::ReadWrite)); return make_ref_counted(move(command)); } @@ -3020,7 +3020,7 @@ ErrorOr> SimpleVariable::run(RefPtr) { NonnullRefPtr value = make_ref_counted(m_name); if (m_slice) - value = value->with_slices(*m_slice).release_value_but_fixme_should_propagate_errors(); + value = TRY(value->with_slices(*m_slice)); return value; } @@ -3090,7 +3090,7 @@ ErrorOr> SpecialVariable::run(RefPtr) { NonnullRefPtr value = make_ref_counted(m_name); if (m_slice) - value = value->with_slices(*m_slice).release_value_but_fixme_should_propagate_errors(); + value = TRY(value->with_slices(*m_slice)); return value; } @@ -3143,8 +3143,8 @@ ErrorOr> Juxtaposition::run(RefPtr shell) if (shell && shell->has_any_error()) return make_ref_counted({}); - auto left = left_value->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors(); - auto right = right_value->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors(); + auto left = TRY(left_value->resolve_as_list(shell)); + auto right = TRY(right_value->resolve_as_list(shell)); if (m_mode == Mode::StringExpand) { Vector result; @@ -3155,7 +3155,7 @@ ErrorOr> Juxtaposition::run(RefPtr shell) if (!result.is_empty() && !right.is_empty()) { auto& last = result.last(); - last = String::formatted("{}{}", last, right.first()).release_value_but_fixme_should_propagate_errors(); + last = TRY(String::formatted("{}{}", last, right.first())); right.take_first(); } for (auto& right_item : right) @@ -3173,7 +3173,7 @@ ErrorOr> Juxtaposition::run(RefPtr shell) builder.append(left[0]); builder.append(right[0]); - return make_ref_counted(builder.to_string().release_value_but_fixme_should_propagate_errors()); + return make_ref_counted(TRY(builder.to_string())); } // Otherwise, treat them as lists and create a list product (or just append). @@ -3188,7 +3188,7 @@ ErrorOr> Juxtaposition::run(RefPtr shell) for (auto& right_element : right) { builder.append(left_element); builder.append(right_element); - result.append(builder.to_string().release_value_but_fixme_should_propagate_errors()); + result.append(TRY(builder.to_string())); builder.clear(); } } @@ -3350,7 +3350,7 @@ ErrorOr> StringPartCompose::run(RefPtr shell) builder.join(' ', left); builder.join(' ', right); - return make_ref_counted(builder.to_string().release_value_but_fixme_should_propagate_errors()); + return make_ref_counted(TRY(builder.to_string())); } ErrorOr StringPartCompose::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -3520,7 +3520,7 @@ ErrorOr> WriteAppendRedirection::run(RefPtr shell) StringBuilder builder; builder.join(' ', path_segments); - command.redirections.append(PathRedirection::create(builder.to_string().release_value_but_fixme_should_propagate_errors(), m_fd, PathRedirection::WriteAppend)); + command.redirections.append(PathRedirection::create(TRY(builder.to_string()), m_fd, PathRedirection::WriteAppend)); return make_ref_counted(move(command)); } @@ -3551,7 +3551,7 @@ ErrorOr> WriteRedirection::run(RefPtr shell) StringBuilder builder; builder.join(' ', path_segments); - command.redirections.append(PathRedirection::create(builder.to_string().release_value_but_fixme_should_propagate_errors(), m_fd, PathRedirection::Write)); + command.redirections.append(PathRedirection::create(TRY(builder.to_string()), m_fd, PathRedirection::Write)); return make_ref_counted(move(command)); } @@ -3791,7 +3791,7 @@ ErrorOr> GlobValue::resolve_as_list(RefPtr shell) if (!shell) return resolve_slices(shell, Vector { m_glob }, m_slices); - auto results = shell->expand_globs(m_glob, shell->cwd); + auto results = TRY(shell->expand_globs(m_glob, shell->cwd)); if (results.is_empty()) shell->raise_error(Shell::ShellError::InvalidGlobError, "Glob did not match anything!", m_generation_position); diff --git a/Userland/Shell/Builtin.cpp b/Userland/Shell/Builtin.cpp index 03082115db..c4ed4c9a77 100644 --- a/Userland/Shell/Builtin.cpp +++ b/Userland/Shell/Builtin.cpp @@ -685,7 +685,7 @@ ErrorOr Shell::builtin_glob(Main::Arguments arguments) return 1; for (auto& glob : globs) { - for (auto& expanded : expand_globs(glob, cwd)) + for (auto& expanded : TRY(expand_globs(glob, cwd))) outln("{}", expanded); } diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp index f79c578155..27088c1782 100644 --- a/Userland/Shell/Shell.cpp +++ b/Userland/Shell/Shell.cpp @@ -252,7 +252,7 @@ bool Shell::is_glob(StringView s) return false; } -Vector Shell::expand_globs(StringView path, StringView base) +ErrorOr> Shell::expand_globs(StringView path, StringView base) { auto explicitly_set_base = false; if (path.starts_with('/')) { @@ -261,15 +261,10 @@ Vector Shell::expand_globs(StringView path, StringView base) } auto parts = path.split_view('/', SplitBehavior::KeepTrailingSeparator); - DeprecatedString base_string = base; - struct stat statbuf; - if (lstat(base_string.characters(), &statbuf) < 0) { - perror("lstat"); - return {}; - } + struct stat statbuf = TRY(Core::System::lstat(base)); StringBuilder resolved_base_path_builder; - resolved_base_path_builder.append(FileSystem::real_path(base).release_value_but_fixme_should_propagate_errors()); + resolved_base_path_builder.append(TRY(FileSystem::real_path(base))); if (S_ISDIR(statbuf.st_mode)) resolved_base_path_builder.append('/'); diff --git a/Userland/Shell/Shell.h b/Userland/Shell/Shell.h index 52670b5740..d38e210db5 100644 --- a/Userland/Shell/Shell.h +++ b/Userland/Shell/Shell.h @@ -182,7 +182,7 @@ public: DeprecatedString prompt() const; static DeprecatedString expand_tilde(StringView expression); - static Vector expand_globs(StringView path, StringView base); + static ErrorOr> expand_globs(StringView path, StringView base); static Vector expand_globs(Vector path_segments, StringView base); ErrorOr> expand_aliases(Vector); DeprecatedString resolve_path(DeprecatedString) const;