From d0e48d9bdcf8e619f2458fa34e961cec081e8785 Mon Sep 17 00:00:00 2001 From: utrain <63367489+u-train@users.noreply.github.com> Date: Wed, 26 Jul 2023 18:10:02 -0400 Subject: [PATCH] Add some logging/error-handling for opener errors! (#745) After seeing an issue with the opener not opening, it was strange to see that there was no logging or error handling! This PR aims to solve that. --- CHANGELOG.md | 2 ++ src/web/api.rs | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 996f4dc7..b678e2a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Rojo Changelog ## Unreleased Changes +* On failing to open a file from Roblox Studio, it is now logged appropriately instead of being ignored ([#745]). * Significantly improved performance of `rojo sourcemap`. ([#668]) * Fixed the diff visualizer of connected sessions. ([#674]) * Fixed disconnected session activity. ([#675]) @@ -21,6 +22,7 @@ * Added better support for `Font` properties ([#731]) * Add new plugin template to the `init` command ([#738]) +[#745]: https://github.com/rojo-rbx/rojo/pull/745 [#668]: https://github.com/rojo-rbx/rojo/pull/668 [#674]: https://github.com/rojo-rbx/rojo/pull/674 [#675]: https://github.com/rojo-rbx/rojo/pull/675 diff --git a/src/web/api.rs b/src/web/api.rs index 8f500116..338862f7 100644 --- a/src/web/api.rs +++ b/src/web/api.rs @@ -4,6 +4,7 @@ use std::{collections::HashMap, fs, path::PathBuf, str::FromStr, sync::Arc}; use hyper::{body, Body, Method, Request, Response, StatusCode}; +use opener::OpenError; use rbx_dom_weak::types::Ref; use crate::{ @@ -236,7 +237,39 @@ impl ApiService { } }; - let _ = opener::open(script_path); + match opener::open(&script_path) { + Ok(()) => {} + Err(error) => match error { + OpenError::Io(io_error) => { + return json( + ErrorResponse::internal_error(format!( + "Attempting to open {} failed because of the following io error: {}", + script_path.display(), + io_error + )), + StatusCode::INTERNAL_SERVER_ERROR, + ) + } + OpenError::ExitStatus { + cmd, + status, + stderr, + } => { + return json( + ErrorResponse::internal_error(format!( + r#"The command '{}' to open '{}' failed with the error code '{}'. + Error logs: + {}"#, + cmd, + script_path.display(), + status, + stderr + )), + StatusCode::INTERNAL_SERVER_ERROR, + ) + } + }, + }; json_ok(&OpenResponse { session_id: self.serve_session.session_id(),