Skip to content

Commit 366b508

Browse files
committed
Correct error message text for runtime
1 parent 42212ab commit 366b508

5 files changed

Lines changed: 54 additions & 17 deletions

File tree

compiler-cli/src/build_lock.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ impl BuildLock {
1818
pub fn new_target(paths: &ProjectPaths, mode: Mode, target: Target) -> Result<Self> {
1919
let directory = paths.build_directory();
2020
crate::fs::mkdir(&directory)?;
21+
let target = match target {
22+
Target::Erlang => "erlang",
23+
Target::JavaScript => "javascript",
24+
};
2125
Ok(Self {
2226
directory,
2327
filename: format!("gleam-{mode}-{target}.lock"),

compiler-core/src/build.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,14 @@ pub enum Target {
6464
JavaScript,
6565
}
6666

67-
impl Display for Target {
68-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67+
impl Target {
68+
pub fn as_presentable_str(&self) -> &str {
6969
match self {
70-
Target::Erlang => write!(f, "Erlang"),
71-
Target::JavaScript => write!(f, "JavaScript"),
70+
Target::Erlang => "Erlang",
71+
Target::JavaScript => "JavaScript",
7272
}
7373
}
74-
}
7574

76-
impl Target {
7775
pub fn variant_strings() -> Vec<EcoString> {
7876
Self::VARIANTS.iter().map(|s| (*s).into()).collect()
7977
}
@@ -127,7 +125,7 @@ impl Codegen {
127125
}
128126

129127
#[derive(
130-
Debug, Serialize, Deserialize, Display, EnumString, EnumVariantNames, Clone, Copy, PartialEq, Eq,
128+
Debug, Serialize, Deserialize, EnumString, EnumVariantNames, Clone, Copy, PartialEq, Eq,
131129
)]
132130
pub enum Runtime {
133131
#[strum(serialize = "nodejs", serialize = "node")]
@@ -141,6 +139,16 @@ pub enum Runtime {
141139
Bun,
142140
}
143141

142+
impl Runtime {
143+
pub fn as_presentable_str(&self) -> &str {
144+
match self {
145+
Runtime::NodeJs => "NodeJS",
146+
Runtime::Deno => "Deno",
147+
Runtime::Bun => "Bun",
148+
}
149+
}
150+
}
151+
144152
impl Default for Runtime {
145153
fn default() -> Self {
146154
Self::NodeJs

compiler-core/src/error.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ file_names.iter().map(|x| x.as_str()).join(", "))]
220220
#[error("warnings are not permitted")]
221221
ForbiddenWarnings { count: usize },
222222

223-
#[error("Invalid runtime for {target} target: {invalid_runtime}")]
223+
#[error("Invalid runtime for target {target:?}: {invalid_runtime:?}")]
224224
InvalidRuntime {
225225
target: Target,
226226
invalid_runtime: Runtime,
@@ -963,7 +963,8 @@ forward slash and must not end with a slash."
963963
title: "Target not supported".into(),
964964
text: wrap_format!(
965965
"`{module}` has a main function, but it does not support the {target} \
966-
target, so it cannot be run."
966+
target, so it cannot be run.",
967+
target = target.as_presentable_str(),
967968
),
968969
level: Level::Error,
969970
location: None,
@@ -3110,7 +3111,8 @@ a size are only allowed at the end of a bin pattern.",
31103111
"Unsupported endianness",
31113112
vec![wrap_format!(
31123113
"The {target} target does not support the `native` \
3113-
endianness option."
3114+
endianness option.",
3115+
target = target.as_presentable_str(),
31143116
)],
31153117
),
31163118
bit_array::ErrorType::OptionNotSupportedForTarget {
@@ -3120,7 +3122,8 @@ endianness option."
31203122
"UTF-codepoint pattern matching is not supported",
31213123
vec![wrap_format!(
31223124
"The {target} target does not support \
3123-
UTF-codepoint pattern matching."
3125+
UTF-codepoint pattern matching.",
3126+
target = target.as_presentable_str(),
31243127
)],
31253128
),
31263129
};
@@ -4539,7 +4542,11 @@ satisfying {required_version} but you are using v{gleam_version}.",
45394542
target,
45404543
invalid_runtime,
45414544
} => {
4542-
let text = format!("Invalid runtime for {target} target: {invalid_runtime}");
4545+
let text = format!(
4546+
"Invalid runtime for {target} target: {invalid_runtime}",
4547+
target = target.as_presentable_str(),
4548+
invalid_runtime = invalid_runtime.as_presentable_str(),
4549+
);
45434550

45444551
let hint = match target {
45454552
Target::JavaScript => {
@@ -4552,7 +4559,10 @@ satisfying {required_version} but you are using v{gleam_version}.",
45524559
};
45534560

45544561
vec![Diagnostic {
4555-
title: format!("Invalid runtime for {target}"),
4562+
title: format!(
4563+
"Invalid runtime for {target}",
4564+
target = target.as_presentable_str(),
4565+
),
45564566
text,
45574567
hint,
45584568
location: None,

compiler-core/src/paths.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ impl ProjectPaths {
9696
}
9797

9898
pub fn build_directory_for_target(&self, mode: Mode, target: Target) -> Utf8PathBuf {
99-
self.build_directory_for_mode(mode).join(target.to_string())
99+
let target = match target {
100+
Target::Erlang => "erlang",
101+
Target::JavaScript => "javascript",
102+
};
103+
self.build_directory_for_mode(mode).join(target)
100104
}
101105

102106
/// Note this uses the "application name", not the name of this package.

test-output/src/tests/echo.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,22 @@ macro_rules! assert_echo {
114114
}
115115

116116
fn snapshot_name(target: Option<Target>, runtime: Option<Runtime>, suffix: &str) -> String {
117+
let show_target = |target: Target| match target {
118+
Target::Erlang => "erlang",
119+
Target::JavaScript => "javascript",
120+
};
121+
let show_runtime = |runtime: Runtime| match runtime {
122+
Runtime::NodeJs => "nodejs",
123+
Runtime::Deno => "deno",
124+
Runtime::Bun => "bun",
125+
};
117126
let prefix = match (target, runtime) {
118127
(None, None) => "".into(),
119-
(None, Some(runtime)) => format!("{runtime}-"),
120-
(Some(target), None) => format!("{target}-"),
121-
(Some(target), Some(runtime)) => format!("{target}-{runtime}-"),
128+
(None, Some(runtime)) => format!("{}-", show_runtime(runtime)),
129+
(Some(target), None) => format!("{}-", show_target(target)),
130+
(Some(target), Some(runtime)) => {
131+
format!("{}-{}-", show_target(target), show_runtime(runtime))
132+
}
122133
};
123134
format!("{prefix}{suffix}")
124135
}

0 commit comments

Comments
 (0)