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/),
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
### Added

View file

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

View file

@ -37,8 +37,7 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
fn create_user_agent_header() -> String {
let (github_owner, github_repo) = env!("CARGO_PKG_REPOSITORY")
.strip_prefix("https://github.com/")
.unwrap()
.trim_start_matches("https://github.com/")
.split_once('/')
.unwrap();
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 {
// HACK: We have no direct way of referencing the ansi color code
// 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
.apply_to("")
.to_string()
.strip_suffix(STYLE_RESET_STR)
.unwrap()
.trim_end_matches(STYLE_RESET_STR)
.to_string()
} else {
STYLE_RESET_STR.to_string()
@ -248,8 +248,7 @@ pub fn pretty_format_luau_error(e: &LuaError, colorized: bool) -> String {
if is_override {
if !trace_override || traceback.lines().count() > full_trace.len() {
full_trace = traceback
.strip_prefix("override traceback:")
.unwrap()
.trim_start_matches("override traceback:")
.to_string();
trace_override = true;
}
@ -269,11 +268,7 @@ pub fn pretty_format_luau_error(e: &LuaError, colorized: bool) -> String {
"{}\n{}\n{}\n{}",
pretty_format_luau_error(root_cause, colorized),
stack_begin,
if full_trace.starts_with("stack traceback:") {
full_trace.strip_prefix("stack traceback:\n").unwrap()
} else {
&full_trace
},
full_trace.trim_start_matches("stack traceback:\n"),
stack_end
)
}

View file

@ -33,7 +33,10 @@ macro_rules! create_tests {
.map(ToString::to_string)
.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?;
Ok(exit_code)
}