Fix formatting-related panic

This commit is contained in:
Filip Tibell 2023-02-26 13:59:34 +01:00
parent 2901e85487
commit 88dbc368d1
No known key found for this signature in database
5 changed files with 17 additions and 15 deletions

View file

@ -8,6 +8,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Fixed
- Fixed crash when using `stdio.color("reset")` or `stdio.style("reset")` in a CI environment or non-interactive terminal
## `0.5.1` - February 25th, 2023 ## `0.5.1` - February 25th, 2023
### Added ### Added

View file

@ -45,8 +45,7 @@ async fn fs_read_dir(_: &'static Lua, path: String) -> LuaResult<Vec<String>> {
.map(|inner_path| { .map(|inner_path| {
inner_path inner_path
.trim() .trim()
.strip_prefix(&dir_string_prefix) .trim_start_matches(&dir_string_prefix)
.unwrap()
.to_owned() .to_owned()
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View file

@ -37,8 +37,7 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
fn create_user_agent_header() -> String { fn create_user_agent_header() -> String {
let (github_owner, github_repo) = env!("CARGO_PKG_REPOSITORY") let (github_owner, github_repo) = env!("CARGO_PKG_REPOSITORY")
.strip_prefix("https://github.com/") .trim_start_matches("https://github.com/")
.unwrap()
.split_once('/') .split_once('/')
.unwrap(); .unwrap();
format!("{github_owner}-{github_repo}-cli") format!("{github_owner}-{github_repo}-cli")

View file

@ -57,12 +57,12 @@ pub fn format_style(style: Option<&'static Style>) -> String {
} else if let Some(style) = style { } else if let Some(style) = style {
// HACK: We have no direct way of referencing the ansi color code // HACK: We have no direct way of referencing the ansi color code
// of the style that console::Style provides, and we also know for // of the style that console::Style provides, and we also know for
// sure that styles always include the reset sequence at the end // sure that styles always include the reset sequence at the end,
// unless we are in a CI environment on non-interactive terminal
style style
.apply_to("") .apply_to("")
.to_string() .to_string()
.strip_suffix(STYLE_RESET_STR) .trim_end_matches(STYLE_RESET_STR)
.unwrap()
.to_string() .to_string()
} else { } else {
STYLE_RESET_STR.to_string() STYLE_RESET_STR.to_string()
@ -248,8 +248,7 @@ pub fn pretty_format_luau_error(e: &LuaError, colorized: bool) -> String {
if is_override { if is_override {
if !trace_override || traceback.lines().count() > full_trace.len() { if !trace_override || traceback.lines().count() > full_trace.len() {
full_trace = traceback full_trace = traceback
.strip_prefix("override traceback:") .trim_start_matches("override traceback:")
.unwrap()
.to_string(); .to_string();
trace_override = true; trace_override = true;
} }
@ -269,11 +268,7 @@ pub fn pretty_format_luau_error(e: &LuaError, colorized: bool) -> String {
"{}\n{}\n{}\n{}", "{}\n{}\n{}\n{}",
pretty_format_luau_error(root_cause, colorized), pretty_format_luau_error(root_cause, colorized),
stack_begin, stack_begin,
if full_trace.starts_with("stack traceback:") { full_trace.trim_start_matches("stack traceback:\n"),
full_trace.strip_prefix("stack traceback:\n").unwrap()
} else {
&full_trace
},
stack_end stack_end
) )
} }

View file

@ -33,7 +33,10 @@ macro_rules! create_tests {
.map(ToString::to_string) .map(ToString::to_string)
.collect::<Vec<_>>() .collect::<Vec<_>>()
); );
let script_name = full_name.strip_suffix(".luau").unwrap(); let script_name = full_name
.trim_end_matches(".luau")
.trim_end_matches(".lua")
.to_string();
let exit_code = lune.run(&script_name, &script).await?; let exit_code = lune.run(&script_name, &script).await?;
Ok(exit_code) Ok(exit_code)
} }