Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,12 @@ impl<'a> Context<'a> {
/// Should KCL be executed on the server (true)?
/// Or locally (false)?
pub(crate) fn use_server_kcl_execution() -> bool {
std::env::var(ENGINE_EXECUTION_ENV)
.map(|value| !value.is_empty())
.unwrap_or_default()
// Default to true.
let Ok(engine_exec) = std::env::var(ENGINE_EXECUTION_ENV) else {
return true;
};
// Opt out if set to 0.
engine_exec != "0"
}

async fn engine_ws_with_settings(
Expand Down Expand Up @@ -406,8 +409,14 @@ impl<'a> Context<'a> {
match result {
Ok(_) => break,
Err(err) => {
check_server_compilation_issues(&mut self.io.err_out, &err.non_fatal, issue_check)
.map_err(|e| anyhow!("KCL execution had errors: {e}"))?;
check_server_compilation_issues(
&mut self.io.err_out,
filepath.as_str(),
code,
&err.non_fatal,
issue_check,
)
.map_err(|e| anyhow!("KCL execution had errors: {e}"))?;
if let Some(error) = err.error {
return Err(anyhow!("KCL execution failed: {}", error.get_message()));
}
Expand Down Expand Up @@ -869,15 +878,24 @@ pub(crate) fn reasoning_to_markdown(reason: &kittycad::types::ReasoningMessage)

fn check_server_compilation_issues(
err_out: &mut impl std::io::Write,
filename: &str,
code: &str,
issues: &[kcl_error::CompilationIssue],
issue_check: kcl_error_fmt::KclIssueCheck,
) -> Result<()> {
if issue_check == kcl_error_fmt::KclIssueCheck::Ignore || issues.is_empty() {
return Ok(());
}

for issue in issues {
writeln!(err_out, "{:?}: {}", issue.severity, issue.message)?;
for (i, issue) in issues.iter().enumerate() {
if i > 0 {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put newlines between error blocks

writeln!(err_out)?;
}
writeln!(
err_out,
"{}",
kcl_lib::render_compilation_issue_miette(filename, code, &Default::default(), issue.clone())
)?;
}

if issue_check == kcl_error_fmt::KclIssueCheck::DenyErrors && issues.iter().any(|issue| issue.is_err()) {
Expand Down
21 changes: 5 additions & 16 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,7 @@ cli_tests! {
svec!["zoo", "kcl", "snapshot", "tests/gear.kcl", "tests/gear.png"],
)
.setup(setup_authenticated)
.stdout_contains("Snapshot saved to `tests/gear.png`")
.stderr_contains("Prefer to use explicit units for angles")
.stdout_contains("Snapshot from engine saved to `tests/gear.png`")
}

snapshot_via_engine(_ctx) => {
Expand All @@ -714,8 +713,7 @@ cli_tests! {
],
)
.setup(setup_authenticated)
.stdout_contains("Snapshot saved to `tests/with-settings/gear.png`")
.stderr_contains("Prefer to use explicit units for angles")
.stdout_contains("Snapshot from engine saved to `tests/with-settings/gear.png`")
}

snapshot_a_kcl_file_with_a_nested_project_toml_as_png(_ctx) => {
Expand All @@ -730,8 +728,7 @@ cli_tests! {
],
)
.setup(setup_authenticated)
.stdout_contains("Snapshot saved to `tests/nested-settings/subdir/gear.png`")
.stderr_contains("Prefer to use explicit units for angles")
.stdout_contains("Snapshot from engine saved to `tests/nested-settings/subdir/gear.png`")
}

snapshot_a_kcl_assembly_as_png(_ctx) => {
Expand All @@ -740,7 +737,7 @@ cli_tests! {
svec!["zoo", "kcl", "snapshot", "tests/walkie-talkie", "tests/walkie-talkie.png"],
)
.setup(setup_authenticated)
.stdout_contains("Snapshot saved to `tests/walkie-talkie.png`")
.stdout_contains("Snapshot from engine saved to `tests/walkie-talkie.png`")
}

snapshot_a_kcl_assembly_as_png_with_dot(_ctx) => {
Expand All @@ -750,7 +747,7 @@ cli_tests! {
)
.setup(setup_authenticated)
.current_directory(std::env::current_dir().unwrap().join("tests/walkie-talkie"))
.stdout_contains("Snapshot saved to `walkie-talkie.png`")
.stdout_contains("Snapshot from engine saved to `walkie-talkie.png`")
}

get_the_mass_of_a_kcl_file(_ctx) => {
Expand All @@ -772,7 +769,6 @@ cli_tests! {
)
.setup(setup_authenticated)
.stdout_contains("1268.234")
.stderr_contains("Prefer to use explicit units for angles")
}

get_the_mass_of_a_kcl_file_but_use_project_toml(_ctx) => {
Expand All @@ -794,7 +790,6 @@ cli_tests! {
)
.setup(setup_authenticated)
.stdout_contains("74.023")
.stderr_contains("Prefer to use explicit units for angles")
}

get_the_mass_of_a_kcl_file_with_nested_dirs_and_a_project_toml(_ctx) => {
Expand All @@ -816,7 +811,6 @@ cli_tests! {
)
.setup(setup_authenticated)
.stdout_contains("74.023")
.stderr_contains("Prefer to use explicit units for angles")
}

analyze_a_kcl_file_as_table(_ctx) => {
Expand All @@ -841,7 +835,6 @@ cli_tests! {
)
.setup(setup_authenticated)
.stdout_contains("center_of_mass")
.stderr_contains("Prefer to use explicit units for angles")
}

analyze_a_kcl_file_as_json(_ctx) => {
Expand All @@ -867,7 +860,6 @@ cli_tests! {
)
.setup(setup_authenticated)
.stdout_contains(r#""center_of_mass""#)
.stderr_contains("Prefer to use explicit units for angles")
}

analyze_a_kcl_file_as_json_with_default_metric_units(_ctx) => {
Expand All @@ -885,7 +877,6 @@ cli_tests! {
)
.setup(setup_authenticated)
.stdout_contains(r#""output_unit": "kg:m3""#)
.stderr_contains("Prefer to use explicit units for angles")
}

analyze_a_kcl_file_and_use_project_toml(_ctx) => {
Expand All @@ -911,7 +902,6 @@ cli_tests! {
)
.setup(setup_authenticated)
.stdout_contains(r#""mass""#)
.stderr_contains("Prefer to use explicit units for angles")
}

analyze_a_kcl_file_with_invalid_density(_ctx) => {
Expand Down Expand Up @@ -957,7 +947,6 @@ cli_tests! {
)
.setup(setup_authenticated)
.stdout_contains("0.0007")
.stderr_contains("Prefer to use explicit units for angles")
}
}

Expand Down
Loading