use oxdock_diagnostics::Diagnostic;
use oxdock_parser::template::{bare_sigil_error, qualified_keypath_error};
use oxdock_parser::{
ANY_TYPE_NAME, BOOL_TYPE_NAME, Expr, FLOAT_TYPE_NAME, Field, HANDLE_TYPE_NAME, INT_TYPE_NAME,
KEYWORD_APPEND, KEYWORD_APPEND_LINE, KEYWORD_ARCHIVE, KEYWORD_ASSERT_CONTAINS, KEYWORD_ASYNC,
KEYWORD_AWAIT, KEYWORD_BREAK, KEYWORD_CANCEL, KEYWORD_CONST, KEYWORD_CONTINUE, KEYWORD_COPY,
KEYWORD_COPY_GIT, KEYWORD_ENV, KEYWORD_EXIT, KEYWORD_EXPAND, KEYWORD_EXPORT, KEYWORD_FOR,
KEYWORD_FUNC, KEYWORD_IMPORT, KEYWORD_INHERIT_ENV, KEYWORD_INSTALL, KEYWORD_ISOLATED,
KEYWORD_LET, KEYWORD_LIST_APPEND, KEYWORD_LS, KEYWORD_MKDIR, KEYWORD_PROMPT, KEYWORD_READ,
KEYWORD_READ_LINE, KEYWORD_REMOTE, KEYWORD_REMOVE, KEYWORD_RETURN, KEYWORD_RUN,
KEYWORD_SET_EXECUTABLE, KEYWORD_SLEEP, KEYWORD_SWITCH, KEYWORD_SYMLINK, KEYWORD_TIMEOUT,
KEYWORD_TYPE, KEYWORD_UNARCHIVE, KEYWORD_WITH_IO, KEYWORD_WORKDIR, KEYWORD_WRITE,
LIST_TYPE_NAME, MAP_TYPE_NAME, MODULE_SEPARATOR, PERMIT_TYPE_NAME, PIPE_TYPE_NAME, ParseError,
SEMAPHORE_TYPE_NAME, STRING_TYPE_NAME, Spelled, TypeTag, VOID_TYPE_NAME, render_structural,
};
use super::function_names::{
FUNC_BASE64_DECODE, FUNC_BASE64_ENCODE, FUNC_BOOL, FUNC_CONTAINS, FUNC_FLOAT,
FUNC_FORMAT_BYTE_COUNT, FUNC_FORMAT_DURATION, FUNC_GLOB, FUNC_HAS_KEY, FUNC_INT, FUNC_IS_EXEC,
FUNC_IS_TERMINAL, FUNC_LEN, FUNC_LOAD_JSON, FUNC_LOAD_TOML, FUNC_MAP_SET, FUNC_MERGE_MAPS,
FUNC_PARSE_ARGS, FUNC_PARSE_BYTE_COUNT, FUNC_PARSE_DURATION, FUNC_PARSE_FLAGS, FUNC_PARSE_JSON,
FUNC_PARSE_POSITIONALS, FUNC_PARSE_TOML, FUNC_PATH_BASE, FUNC_PATH_REL, FUNC_PATH_TYPE,
FUNC_PATH_WRITABLE, FUNC_SEMAPHORE_NEW, FUNC_SHELL_SPLIT_ARGS, FUNC_TO_JSON,
};
const FIELD_ARGV: &str = "argv";
const FIELD_ALLOWED: &str = "allowed";
const FIELD_CODE: &str = "code";
const FIELD_COMMAND: &str = "command";
const FIELD_DECLARES: &str = "declares";
const FIELD_DETAIL: &str = "detail";
const FIELD_EXPECTED: &str = "expected";
const FIELD_FUNCTION: &str = "function";
const FIELD_GOT: &str = "got";
const FIELD_MAX: &str = "max";
const FIELD_MIN: &str = "min";
const FIELD_PARAM: &str = "param";
const FIELD_REASON: &str = "reason";
const FIELD_SNAPSHOT: &str = "snapshot";
const FIELD_STATUS: &str = "status";
const FIELD_STEP: &str = "step";
const FIELD_TARGET: &str = "target";
const FIELD_TASK: &str = "task";
const FIELD_VALUE: &str = "value";
const FIELD_VAR: &str = "var";
const FIELD_YIELD: &str = "yield";
pub(super) const KEY_EVAL_EXIT_REQUESTED: &str = "dsl.eval.exit_requested";
pub(super) const KEY_STD_PUMP_DOWNSTREAM_CLOSED: &str = "dsl.std.pump_downstream_closed";
pub use oxdock_diagnostics::flatten_chain;
pub fn map_duplicate_field(field: &str) -> Diagnostic {
let message = format!("duplicate field `{field}` in `{MAP_TYPE_NAME}` spelling");
Diagnostic::new(
"dsl.map.duplicate_field",
message,
Diagnostic::make_fields(&[("field", field)]),
)
}
pub fn alias_self(field: &str, alias: &str) -> Diagnostic {
let message = format!("alias `{alias}` duplicates its own field `{field}`");
Diagnostic::new(
"dsl.alias.self",
message,
Diagnostic::make_fields(&[("field", field), ("alias", alias)]),
)
}
pub fn alias_clash(alias: &str, field: &str, owner: &str) -> Diagnostic {
let message = format!("alias `{alias}` for field `{field}` clashes with `{owner}`");
Diagnostic::new(
"dsl.alias.clash",
message,
Diagnostic::make_fields(&[("alias", alias), ("field", field), ("owner", owner)]),
)
}
pub fn typing_max_depth(max: usize, name: &str) -> Diagnostic {
let message = format!("type spelling exceeds maximum generic depth of {max}: `{name}`");
Diagnostic::new(
"dsl.typing.max_depth",
message,
Diagnostic::make_fields(&[("max", &max.to_string()), ("spelling", name)]),
)
}
pub fn typing_max_depth_spelled(max: usize, spelled: &Spelled) -> Diagnostic {
let rendered = format!("{spelled:?}");
let message = format!("type spelling exceeds maximum generic depth of {max}: `{rendered}`");
Diagnostic::new(
"dsl.typing.max_depth",
message,
Diagnostic::make_fields(&[("max", &max.to_string()), ("spelling", &rendered)]),
)
}
pub fn typing_bare_map() -> Diagnostic {
let message = format!(
"bare `{MAP_TYPE_NAME}` is not a declaration type: write a shape (`{MAP_TYPE_NAME}<name: {KEYWORD_TYPE}, ...>`) or `{MAP_TYPE_NAME}<{ANY_TYPE_NAME}>` for maps with unknown keys"
);
Diagnostic::new(
"dsl.typing.bare_map",
message,
Diagnostic::make_fields(&[("type", MAP_TYPE_NAME)]),
)
}
pub fn typing_bare_list() -> Diagnostic {
let message = format!(
"bare `{LIST_TYPE_NAME}` is not a declaration type: write a shape (`{LIST_TYPE_NAME}<{KEYWORD_TYPE}>`) or `{LIST_TYPE_NAME}<{ANY_TYPE_NAME}>` for lists with unknown elements"
);
Diagnostic::new(
"dsl.typing.bare_list",
message,
Diagnostic::make_fields(&[("type", LIST_TYPE_NAME)]),
)
}
pub fn typing_bare_handle() -> Diagnostic {
let message = format!(
"bare `{HANDLE_TYPE_NAME}` is not a declaration type: write `{HANDLE_TYPE_NAME}<T>` for a known payload or `{HANDLE_TYPE_NAME}<{ANY_TYPE_NAME}>` for an unknown one"
);
Diagnostic::new(
"dsl.typing.bare_handle",
message,
Diagnostic::make_fields(&[("type", HANDLE_TYPE_NAME)]),
)
}
pub fn alias_cycle(chain: &[String]) -> Diagnostic {
let joined = chain.join(" -> ");
let message = format!("type alias cycle: {joined}");
Diagnostic::new(
"dsl.alias.cycle",
message,
Diagnostic::make_fields(&[("chain", &joined)]),
)
}
pub fn typing_unknown(
name: &str,
types: &[String],
schemas: &[String],
aliases: &[String],
) -> Diagnostic {
let types = types.join(", ");
let schemas = schemas.join(", ");
let aliases = aliases.join(", ");
let message = format!(
"unknown type `{name}`; known types: {types} and schemas: {schemas} and aliases: {aliases}"
);
Diagnostic::new(
"dsl.typing.unknown",
message,
Diagnostic::make_fields(&[
("name", name),
("types", &types),
("schemas", &schemas),
("aliases", &aliases),
]),
)
}
pub fn typing_unregistered(what: &str, name: &str, types: &[String]) -> Diagnostic {
let known = types.join(", ");
let message = format!("{what} declares unregistered type '{name}'; known types: {known}");
Diagnostic::new(
"dsl.typing.unregistered",
message,
Diagnostic::make_fields(&[("ctx", what), ("name", name), ("types", &known)]),
)
}
pub fn typing_void_position(what: &str) -> Diagnostic {
let message = format!(
"{what} declares {VOID_TYPE_NAME} outside a return annotation: {VOID_TYPE_NAME} is only a return type (or {HANDLE_TYPE_NAME}<{VOID_TYPE_NAME}> payload)"
);
Diagnostic::new(
"dsl.typing.void_position",
message,
Diagnostic::make_fields(&[("ctx", what)]),
)
}
pub fn check_unknown_option(func: &str, key: &str, known: &[&str]) -> Diagnostic {
let expected = known.join(", ");
let message = format!("{func}() unknown option '{key}' (expected: {expected})");
Diagnostic::new(
"dsl.check.unknown_option",
message,
Diagnostic::make_fields(&[("function", func), ("key", key), ("expected", &expected)]),
)
}
pub fn check_option_value(reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
Diagnostic::new(
"dsl.check.option_value",
reason_text.clone(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn typing_no_args(name: &str) -> Diagnostic {
let message = format!("`{name}` takes no type arguments");
Diagnostic::new(
"dsl.typing.no_args",
message,
Diagnostic::make_fields(&[("type", name)]),
)
}
pub fn typing_handle_arity() -> Diagnostic {
let message = format!("`{HANDLE_TYPE_NAME}` takes exactly one bare type argument");
Diagnostic::new(
"dsl.typing.handle_arity",
message,
Diagnostic::make_fields(&[("type", HANDLE_TYPE_NAME)]),
)
}
pub fn typing_list_arity() -> Diagnostic {
let message = format!("`{LIST_TYPE_NAME}` takes exactly one bare type argument");
Diagnostic::new(
"dsl.typing.list_arity",
message,
Diagnostic::make_fields(&[("type", LIST_TYPE_NAME)]),
)
}
pub fn typing_map_bare(head: &str) -> Diagnostic {
let message = format!(
"`{MAP_TYPE_NAME}` fields require `name: {KEYWORD_TYPE}`; `{head}` takes no bare arguments"
);
Diagnostic::new(
"dsl.typing.map_bare",
message,
Diagnostic::make_fields(&[("head", head)]),
)
}
pub fn typing_default_mismatch(field: &str, expected: &str) -> Diagnostic {
let message = format!("default for field `{field}` does not match {expected}");
Diagnostic::new(
"dsl.typing.default_mismatch",
message,
Diagnostic::make_fields(&[("field", field), ("expected", expected)]),
)
}
pub fn typing_empty_union() -> Diagnostic {
Diagnostic::new(
"dsl.typing.empty_union",
"empty union: no member shapes to admit".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn alias_already_defined(name: &str) -> Diagnostic {
let message = format!("type alias `{name}` is already defined");
Diagnostic::new(
"dsl.alias.already_defined",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn alias_builtin_collision(name: &str) -> Diagnostic {
let message = format!("type alias `{name}` collides with a builtin type");
Diagnostic::new(
"dsl.alias.builtin_collision",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn alias_host_collision(name: &str) -> Diagnostic {
let message = format!("type alias `{name}` collides with registered host type `{name}`");
Diagnostic::new(
"dsl.alias.host_collision",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn alias_schema_collision(name: &str) -> Diagnostic {
let message = format!("type alias `{name}` collides with registered record schema `{name}`");
Diagnostic::new(
"dsl.alias.schema_collision",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn alias_func_collision(name: &str) -> Diagnostic {
let message = format!("type alias `{name}` collides with function `{name}`");
Diagnostic::new(
"dsl.alias.func_collision",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn typing_ambiguous(alias: &str, base: &str) -> Diagnostic {
let qualified = format!("{alias}::{base}");
let message = format!(
"type `{qualified}` is ambiguous: alias `{alias}` imports distinct types for `{base}` from multiple files with overlapping guards"
);
Diagnostic::new(
"dsl.typing.ambiguous",
message,
Diagnostic::make_fields(&[("name", &qualified), ("alias", alias), ("base", base)]),
)
}
pub fn typing_harvest_collision(name: &str, existing: &str, target: &str) -> Diagnostic {
let message = format!(
"type `{name}` is ambiguous: bare harvest `{name}` collides: already defined from `{existing}`, new source `{target}`"
);
Diagnostic::new(
"dsl.typing.ambiguous",
message,
Diagnostic::make_fields(&[("name", name), ("existing", existing), ("target", target)]),
)
}
pub fn tail_chars(s: &str, n: usize) -> String {
if s.chars().count() <= n {
return s.to_string();
}
s.chars()
.rev()
.take(n)
.collect::<Vec<_>>()
.into_iter()
.rev()
.collect()
}
pub fn mcp_export_type_unknown(name: &str) -> Diagnostic {
let message = format!(
"{KEYWORD_EXPORT} {KEYWORD_TYPE} `{name}` matches no local {KEYWORD_TYPE} and no imported file exports it"
);
Diagnostic::new(
"dsl.mcp.export_type_unknown",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn mcp_break_outside_loop(step: usize) -> Diagnostic {
let message = format!("step {step}: {KEYWORD_BREAK} outside loop");
Diagnostic::new(
"dsl.mcp.break_outside_loop",
message,
Diagnostic::make_fields(&[("step", &step.to_string())]),
)
}
pub fn mcp_continue_outside_loop(step: usize) -> Diagnostic {
let message = format!("step {step}: {KEYWORD_CONTINUE} outside loop");
Diagnostic::new(
"dsl.mcp.continue_outside_loop",
message,
Diagnostic::make_fields(&[("step", &step.to_string())]),
)
}
pub fn mcp_return_outside_function(step: usize) -> Diagnostic {
let message = format!(
"step {step}: {KEYWORD_RETURN} outside function, {KEYWORD_ASYNC} task, or {KEYWORD_LET} block"
);
Diagnostic::new(
"dsl.mcp.return_outside_function",
message,
Diagnostic::make_fields(&[("step", &step.to_string())]),
)
}
pub fn mcp_unknown_tool(base: &str) -> Diagnostic {
let message = format!("unknown MCP tool `{base}`");
Diagnostic::new(
"dsl.mcp.unknown_tool",
message,
Diagnostic::make_fields(&[("tool", base)]),
)
}
pub fn mcp_call_failed(reason: &Diagnostic, stdout: &str, stderr: &str) -> Diagnostic {
let reason_text = flatten_chain(reason);
let mut message = reason_text.clone();
if !stdout.is_empty() {
message.push_str("\n--- captured stdout ---\n");
message.push_str(&tail_chars(stdout, 4096));
}
if !stderr.is_empty() {
message.push_str("\n--- captured stderr ---\n");
message.push_str(&tail_chars(stderr, 4096));
}
Diagnostic::new(
"dsl.mcp.call_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn import_cycle(chain: &[String]) -> Diagnostic {
let joined = chain.join(" -> ");
let message = format!("{KEYWORD_IMPORT} cycle detected: {joined}");
Diagnostic::new(
"dsl.import.cycle",
message,
Diagnostic::make_fields(&[("chain", &joined)]),
)
}
pub fn import_depth_limit(max: usize, path: &str) -> Diagnostic {
let message = format!("{KEYWORD_IMPORT} depth limit exceeded ({max}): `{path}`");
Diagnostic::new(
"dsl.import.depth_limit",
message,
Diagnostic::make_fields(&[("max", &max.to_string()), ("path", path)]),
)
}
pub fn import_not_found(path: &str) -> Diagnostic {
let message = format!(
"{KEYWORD_IMPORT} `{path}` not found: the file must exist when the run starts (generated imports are not supported)"
);
Diagnostic::new(
"dsl.import.not_found",
message,
Diagnostic::make_fields(&[("path", path)]),
)
}
pub fn import_cannot_resolve(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("{KEYWORD_IMPORT} `{path}` cannot be resolved: {reason_text}");
Diagnostic::new(
"dsl.import.cannot_resolve",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
}
pub fn import_cannot_read(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("{KEYWORD_IMPORT} `{path}` cannot be read: {reason_text}");
Diagnostic::new(
"dsl.import.cannot_read",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
}
pub fn import_bad_utf8(path: &str, reason: &std::str::Utf8Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("{KEYWORD_IMPORT} `{path}` is not valid UTF-8: {reason_text}");
Diagnostic::new(
"dsl.import.bad_utf8",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
}
pub fn import_parse_failed(path: &str, reason: &ParseError) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("{KEYWORD_IMPORT} `{path}` failed to parse: {reason_text}");
Diagnostic::new(
"dsl.import.parse_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
}
pub fn engine_parse_failed(reason: &ParseError) -> Diagnostic {
if let Some(inner) = reason.diagnostic() {
return inner.clone();
}
let reason_text = format!("{reason}");
Diagnostic::new(
"dsl.engine.parse_failed",
reason_text.clone(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn import_missing_export(path: &str, kind: &str, name: &str) -> Diagnostic {
let what = if kind == KEYWORD_FUNC {
String::new()
} else {
format!("{kind} ")
};
let message = format!("{KEYWORD_IMPORT} `{path}` does not export {what}`{name}`");
Diagnostic::new(
"dsl.import.missing_export",
message,
Diagnostic::make_fields(&[("path", path), ("kind", kind), ("name", name)]),
)
}
pub fn import_unknown_member(path: &str, noun: &str, name: &str) -> Diagnostic {
let message = format!("{KEYWORD_IMPORT} `{path}` has no such {noun} `{name}`");
Diagnostic::new(
"dsl.import.unknown_member",
message,
Diagnostic::make_fields(&[("path", path), ("noun", noun), ("name", name)]),
)
}
pub fn import_unknown_type(path: &str, name: &str, reason: Option<Diagnostic>) -> Diagnostic {
let message = match reason {
Some(reason) => {
format!("{KEYWORD_IMPORT} `{path}` has no such {KEYWORD_TYPE} `{name}`: {reason:#}")
}
None => format!("{KEYWORD_IMPORT} `{path}` has no such {KEYWORD_TYPE} `{name}`"),
};
Diagnostic::new(
"dsl.import.unknown_type",
message,
Diagnostic::make_fields(&[("path", path), ("name", name)]),
)
}
pub fn import_failed_validation(path: &str, reason: Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_IMPORT} `{path}` failed validation: {reason_text}");
Diagnostic::new(
"dsl.import.failed_validation",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
}
pub fn import_stateful_harvest(path: &str, offender: &str) -> Diagnostic {
let message = format!(
"{KEYWORD_IMPORT} `{path}` cannot harvest stateful function `{offender}`: import the file"
);
Diagnostic::new(
"dsl.import.stateful_harvest",
message,
Diagnostic::make_fields(&[("path", path), ("offender", offender)]),
)
}
pub fn import_unknown_function(path: &str, name: &str) -> Diagnostic {
let message = format!("{KEYWORD_IMPORT} `{path}` has no such function `{name}`");
Diagnostic::new(
"dsl.import.unknown_function",
message,
Diagnostic::make_fields(&[("path", path), ("name", name)]),
)
}
pub fn import_type_collision(path: &str, name: &str, existing: &str, target: &str) -> Diagnostic {
let message = format!(
"{KEYWORD_IMPORT} `{path}` {KEYWORD_TYPE} `{name}` collides: already defined with target `{existing}`, new target `{target}`"
);
Diagnostic::new(
"dsl.import.type_collision",
message,
Diagnostic::make_fields(&[
("path", path),
("name", name),
("existing", existing),
("target", target),
]),
)
}
pub fn import_const_no_alias(qualified: &str, alias: &str) -> Diagnostic {
let message = format!(
"unknown {KEYWORD_CONST} `{qualified}`: no import alias `{alias}` exports that name"
);
Diagnostic::new(
"dsl.import.const_no_alias",
message,
Diagnostic::make_fields(&[("name", qualified), ("alias", alias)]),
)
}
pub fn import_const_ambiguous(
alias: &str,
name: &str,
files: &std::collections::HashSet<String>,
) -> Diagnostic {
let message = super::native::const_ambiguous_message(alias, name, files);
Diagnostic::new(
"dsl.import.const_ambiguous",
message,
Diagnostic::make_fields(&[("alias", alias), ("name", name)]),
)
}
pub fn import_const_hinted(qualified: &str, hint: &str) -> Diagnostic {
let message = format!("unknown {KEYWORD_CONST} `{qualified}`: {hint}");
Diagnostic::new(
"dsl.import.const_hinted",
message,
Diagnostic::make_fields(&[("name", qualified), ("hint", hint)]),
)
}
pub fn import_const_unknown(qualified: &str) -> Diagnostic {
let message = format!("unknown {KEYWORD_CONST} `{qualified}`");
Diagnostic::new(
"dsl.import.const_unknown",
message,
Diagnostic::make_fields(&[("name", qualified)]),
)
}
pub fn import_const_uninitialized(qualified: &str) -> Diagnostic {
let message = format!(
"`{qualified}` cannot be read: the module was harvested but never initialized; import the file"
);
Diagnostic::new(
"dsl.import.const_uninitialized",
message,
Diagnostic::make_fields(&[("name", qualified)]),
)
}
pub fn import_const_is_let(qualified: &str) -> Diagnostic {
let message = format!(
"`{qualified}` is a {KEYWORD_LET} binding and cannot be exported: only {KEYWORD_CONST} bindings cross the module boundary"
);
Diagnostic::new(
"dsl.import.const_is_let",
message,
Diagnostic::make_fields(&[("name", qualified)]),
)
}
pub fn import_const_forward_failed(reason: &str) -> Diagnostic {
Diagnostic::new(
"dsl.import.const_forward_failed",
reason.to_string(),
Diagnostic::make_fields(&[(FIELD_REASON, reason)]),
)
}
pub fn import_flow_crosses_boundary(flow: &str, step: usize, path: &str) -> Diagnostic {
let message =
format!("step {step}: {flow} cannot cross import boundary (in {KEYWORD_IMPORT} `{path}`)");
Diagnostic::new(
"dsl.import.flow_crosses_boundary",
message,
Diagnostic::make_fields(&[("flow", flow), ("step", &step.to_string()), ("path", path)]),
)
}
pub fn func_zero_value_missing(rendered: &str) -> Diagnostic {
let message =
format!("no zero value for {rendered}; omit the `?` or pass the argument explicitly");
Diagnostic::new(
"dsl.func.zero_value_missing",
message,
Diagnostic::make_fields(&[("spelling", rendered)]),
)
}
pub fn func_param_type(func: &str, reason: Diagnostic) -> Diagnostic {
let reason_text = reason.to_string();
let message = format!("function `{func}`");
Diagnostic::new(
"dsl.func.param_type",
message,
Diagnostic::make_fields(&[("function", func), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new(reason))
}
pub fn func_optional_param(func: &str, param: &str, reason: Diagnostic) -> Diagnostic {
let reason_text = reason.to_string();
let message = format!("function `{func}` optional param `${param}`");
Diagnostic::new(
"dsl.func.optional_param",
message,
Diagnostic::make_fields(&[
("function", func),
("param", param),
("reason", &reason_text),
]),
)
.with_source(std::sync::Arc::new(reason))
}
pub fn func_shadow_reserved(name: &str) -> Diagnostic {
let message = format!("cannot shadow reserved function `{name}`");
Diagnostic::new(
"dsl.func.shadow_reserved",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn func_duplicate_in_scope(name: &str) -> Diagnostic {
let message = format!("duplicate function `{name}` in same scope");
Diagnostic::new(
"dsl.func.duplicate_in_scope",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn func_param_values_without_type(param: &str, func: &str) -> Diagnostic {
let message = format!("param '{param}' of '{func}' declares values without a type");
Diagnostic::new(
"dsl.func.param_values_without_type",
message,
Diagnostic::make_fields(&[("function", func), ("param", param)]),
)
}
pub fn func_optional_before_required(param: &str, func: &str) -> Diagnostic {
let message = format!("param '{param}' of '{func}' is optional before a required param");
Diagnostic::new(
"dsl.func.optional_before_required",
message,
Diagnostic::make_fields(&[("function", func), ("param", param)]),
)
}
pub fn func_optional_without_map(param: &str, func: &str) -> Diagnostic {
let message = format!("param '{param}' of '{func}' is optional without a {MAP_TYPE_NAME} type");
Diagnostic::new(
"dsl.func.optional_without_map",
message,
Diagnostic::make_fields(&[("function", func), ("param", param)]),
)
}
pub fn func_ambiguous_alias(
alias: &str,
base: &str,
files: &std::collections::HashSet<String>,
) -> Diagnostic {
let message = super::native::ambiguous_alias_message(alias, base, files);
Diagnostic::new(
"dsl.func.ambiguous_alias",
message,
Diagnostic::make_fields(&[("alias", alias), ("name", base)]),
)
}
pub fn func_export_unknown(name: &str) -> Diagnostic {
let message = format!(
"{KEYWORD_EXPORT} `{name}` matches no defined script function or known host function"
);
Diagnostic::new(
"dsl.func.export_unknown",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn func_placeholder_unknown(module: &str, func: &str, known: &[String]) -> Diagnostic {
let mut known: Vec<&str> = known.iter().map(|s| s.as_str()).collect();
known.sort();
let joined = known.join(", ");
let message = format!(
"unknown placeholder function `{module}{MODULE_SEPARATOR}{func}`; known functions: {joined}"
);
Diagnostic::new(
"dsl.func.placeholder_unknown",
message,
Diagnostic::make_fields(&[("module", module), ("name", func), ("known", &joined)]),
)
}
pub fn func_describe_unqualified(name: &str) -> Diagnostic {
let message = format!(
"unknown function `{name}`: DESCRIBE requires a qualified name (e.g. `STD::{name}`)"
);
Diagnostic::new(
"dsl.func.describe_unqualified",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn func_unknown(name: &str) -> Diagnostic {
let message = format!("unknown function `{name}`");
Diagnostic::new(
"dsl.func.unknown",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn func_arg_arity_exact(func: &str, expected: usize, got: usize) -> Diagnostic {
let message = format!("{func}() expects {expected} argument(s), got {got}");
Diagnostic::new(
"dsl.func.arg_arity_exact",
message,
Diagnostic::make_fields(&[
(FIELD_FUNCTION, func),
(FIELD_EXPECTED, &expected.to_string()),
(FIELD_GOT, &got.to_string()),
]),
)
}
pub fn func_arg_arity_range(func: &str, min: usize, max: usize, got: usize) -> Diagnostic {
let message = format!("{func}() expects {min} to {max} argument(s), got {got}");
Diagnostic::new(
"dsl.func.arg_arity_range",
message,
Diagnostic::make_fields(&[
(FIELD_FUNCTION, func),
(FIELD_MIN, &min.to_string()),
(FIELD_MAX, &max.to_string()),
(FIELD_GOT, &got.to_string()),
]),
)
}
pub fn func_arg_must_be_string(func: &str, param: &str) -> Diagnostic {
let message = format!("{func}() argument `${param}` must be a STRING");
Diagnostic::new(
"dsl.func.arg_must_be_string",
message,
Diagnostic::make_fields(&[(FIELD_FUNCTION, func), (FIELD_PARAM, param)]),
)
}
pub fn func_arg_must_be_one_of(func: &str, param: &str, allowed: &[&str], got: &str) -> Diagnostic {
let joined = allowed.join(", ");
let message = format!("{func}() argument `${param}` must be one of: {joined}, got {got:?}");
Diagnostic::new(
"dsl.func.arg_must_be_one_of",
message,
Diagnostic::make_fields(&[
(FIELD_FUNCTION, func),
(FIELD_PARAM, param),
(FIELD_ALLOWED, &joined),
(FIELD_GOT, got),
]),
)
}
pub fn func_arg_must_be_finite(func: &str, param: &str, value: f64) -> Diagnostic {
let message = format!("{func}() argument `${param}` must be finite, found FLOAT ({value:?})");
Diagnostic::new(
"dsl.func.arg_must_be_finite",
message,
Diagnostic::make_fields(&[
(FIELD_FUNCTION, func),
(FIELD_PARAM, param),
(FIELD_VALUE, &format!("{value:?}")),
]),
)
}
pub fn func_arg_must_be_bool(func: &str, param: &str, got: &str) -> Diagnostic {
let message = format!("{func}() argument `${param}` must be a Bool, found {got:?}");
Diagnostic::new(
"dsl.func.arg_must_be_bool",
message,
Diagnostic::make_fields(&[
(FIELD_FUNCTION, func),
(FIELD_PARAM, param),
(FIELD_GOT, got),
]),
)
}
pub fn func_arg_must_be_bool_or_string(func: &str, param: &str, got: &super::Value) -> Diagnostic {
let message = format!("{func}() argument `${param}` must be a Bool or String, found {got:?}");
Diagnostic::new(
"dsl.func.arg_must_be_bool_or_string",
message,
Diagnostic::make_fields(&[
(FIELD_FUNCTION, func),
(FIELD_PARAM, param),
(FIELD_GOT, &format!("{got:?}")),
]),
)
}
pub fn func_arg_must_be_pipe(func: &str, param: &str, got: &str) -> Diagnostic {
let message = format!("{func}() argument `${param}` must be a PIPE, got {got}");
Diagnostic::new(
"dsl.func.arg_must_be_pipe",
message,
Diagnostic::make_fields(&[
(FIELD_FUNCTION, func),
(FIELD_PARAM, param),
(FIELD_GOT, got),
]),
)
}
pub fn func_arg_must_be_semaphore(func: &str, param: &str, got: &str) -> Diagnostic {
let message = format!("{func}() argument `${param}` must be a SEMAPHORE, got {got}");
Diagnostic::new(
"dsl.func.arg_must_be_semaphore",
message,
Diagnostic::make_fields(&[
(FIELD_FUNCTION, func),
(FIELD_PARAM, param),
(FIELD_GOT, got),
]),
)
}
pub fn func_arg_must_be_handle(func: &str, param: &str, got: &str) -> Diagnostic {
let message = format!("{func}() argument `${param}` must be a HANDLE, got {got}");
Diagnostic::new(
"dsl.func.arg_must_be_handle",
message,
Diagnostic::make_fields(&[
(FIELD_FUNCTION, func),
(FIELD_PARAM, param),
(FIELD_GOT, got),
]),
)
}
pub fn func_arg_expects_custom(func: &str, param: &str, expected: &str, got: &str) -> Diagnostic {
let message = format!("{func}() argument `${param}` expects a {expected} value, got {got}");
Diagnostic::new(
"dsl.func.arg_expects_custom",
message,
Diagnostic::make_fields(&[
(FIELD_FUNCTION, func),
(FIELD_PARAM, param),
(FIELD_EXPECTED, expected),
(FIELD_GOT, got),
]),
)
}
pub fn eval_call_unknown(name: &str, hint: &str) -> Diagnostic {
let message = format!("unknown function `{name}`{hint}");
Diagnostic::new(
"dsl.eval.call_unknown",
message,
Diagnostic::make_fields(&[("name", name), ("hint", hint)]),
)
}
pub fn eval_call_unknown_rpn(name: &str, hint: &str) -> Diagnostic {
let message = format!("unknown function {name}{hint}");
Diagnostic::new(
"dsl.eval.call_unknown_rpn",
message,
Diagnostic::make_fields(&[("name", name), ("hint", hint)]),
)
}
pub fn eval_call_return_tag_failed(name: &str, reason: Diagnostic) -> Diagnostic {
let reason_text = reason.to_string();
let message = format!("function `{name}`: {reason_text}");
Diagnostic::new(
"dsl.eval.call_return_tag_failed",
message,
Diagnostic::make_fields(&[("function", name), ("reason", &reason_text)]),
)
}
pub fn eval_call_failed(name: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
Diagnostic::new(
"dsl.eval.call_failed",
format!("function `{name}` failed"),
Diagnostic::make_fields(&[("function", name), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_call_recursion_limit(func: &str) -> Diagnostic {
let message = format!("recursion depth limit exceeded in {KEYWORD_FUNC} {func}");
Diagnostic::new(
"dsl.eval.call_recursion_limit",
message,
Diagnostic::make_fields(&[("function", func)]),
)
}
pub fn eval_call_arity_exact(func: &str, expected: usize, got: usize) -> Diagnostic {
let message = format!("{func}() expects {expected} argument(s), got {got}");
Diagnostic::new(
"dsl.eval.call_arity_exact",
message,
Diagnostic::make_fields(&[
("function", func),
("expected", &expected.to_string()),
("got", &got.to_string()),
]),
)
}
pub fn eval_call_arity_range(func: &str, min: usize, max: usize, got: usize) -> Diagnostic {
let message = format!("{func}() expects {min} to {max} argument(s), got {got}");
Diagnostic::new(
"dsl.eval.call_arity_range",
message,
Diagnostic::make_fields(&[
("function", func),
("min", &min.to_string()),
("max", &max.to_string()),
("got", &got.to_string()),
]),
)
}
pub fn eval_call_missing_param(param: &str, func: &str) -> Diagnostic {
let message = format!("internal error: missing non-optional param `${param}` in {func}()");
Diagnostic::new(
"dsl.eval.call_missing_param",
message,
Diagnostic::make_fields(&[("param", param), ("function", func)]),
)
}
pub fn eval_call_zero_value_failed(func: &str, param: &str, reason: Diagnostic) -> Diagnostic {
let reason_text = reason.to_string();
let message = format!("function `{func}` optional param `${param}` has no zero value");
Diagnostic::new(
"dsl.eval.call_zero_value_failed",
message,
Diagnostic::make_fields(&[
("function", func),
("param", param),
("reason", &reason_text),
]),
)
.with_source(std::sync::Arc::new(reason))
}
pub fn eval_call_flow_crosses_func(step: usize, word: &str, func: &str) -> Diagnostic {
let message = format!("step {step}: {word} cannot cross function boundary (in {func}())");
Diagnostic::new(
"dsl.eval.call_flow_crosses_func",
message,
Diagnostic::make_fields(&[
("step", &step.to_string()),
("flow", word),
("function", func),
]),
)
}
pub fn eval_for_needs_key_value() -> Diagnostic {
Diagnostic::new(
"dsl.eval.for_needs_key_value",
format!(
"{KEYWORD_FOR} loop over Map requires key and value bindings: {KEYWORD_FOR} $k: {STRING_TYPE_NAME}, $v: {KEYWORD_TYPE} IN $map"
),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_for_map_key_type(actual: &str) -> Diagnostic {
Diagnostic::new(
"dsl.eval.for_map_key_type",
format!(
"{KEYWORD_FOR} loop over {MAP_TYPE_NAME} requires a {STRING_TYPE_NAME} key variable, got {actual}"
),
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn eval_for_needs_list_or_map(got: &super::Value) -> Diagnostic {
let got_text = format!("{got:?}");
Diagnostic::new(
"dsl.eval.for_needs_list_or_map",
format!("{KEYWORD_FOR} loop requires a List or Map iterable, found {got_text}"),
Diagnostic::make_fields(&[("got", &got_text)]),
)
}
pub fn std_unknown_type(name: &str) -> Diagnostic {
let message = format!("unknown type `{name}`");
Diagnostic::new(
"dsl.std.unknown_type",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn std_contains_needle_type(actual: &str) -> Diagnostic {
let message = format!(
"{FUNC_CONTAINS} needs a {STRING_TYPE_NAME} needle for a {STRING_TYPE_NAME} haystack, found `{actual}`"
);
Diagnostic::new(
"dsl.std.contains_needle_type",
message,
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn std_contains_haystack_type(actual: &str) -> Diagnostic {
let message = format!(
"{FUNC_CONTAINS} needs a {STRING_TYPE_NAME} or {LIST_TYPE_NAME} haystack, found `{actual}`"
);
Diagnostic::new(
"dsl.std.contains_haystack_type",
message,
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn std_len_unexpected_type(actual: &str) -> Diagnostic {
let message = format!(
"{FUNC_LEN} needs a {STRING_TYPE_NAME}, {LIST_TYPE_NAME}, or {MAP_TYPE_NAME} value, got `{actual}`"
);
Diagnostic::new(
"dsl.std.len_unexpected_type",
message,
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn std_is_terminal_expected(stream: &str) -> Diagnostic {
let message =
format!("{FUNC_IS_TERMINAL} expects \"stdin\", \"stdout\", or \"stderr\", got {stream:?}");
Diagnostic::new(
"dsl.std.is_terminal_expected",
message,
Diagnostic::make_fields(&[("got", stream)]),
)
}
pub fn std_semaphore_needs_positive(max: i64) -> Diagnostic {
let message = format!("{FUNC_SEMAPHORE_NEW}() requires a positive max, got {max}");
Diagnostic::new(
"dsl.std.semaphore_needs_positive",
message,
Diagnostic::make_fields(&[("max", &max.to_string())]),
)
}
pub fn std_bool_needs_bool_or_string(got: &super::Value) -> Diagnostic {
let message = format!("{FUNC_BOOL} needs a Bool or String, found {got:?}");
Diagnostic::new(
"dsl.std.bool_needs_bool_or_string",
message,
Diagnostic::make_fields(&[("got", &format!("{got:?}"))]),
)
}
pub fn std_bool_cannot_coerce(command: &str, got: &str) -> Diagnostic {
let message = format!("{command} cannot coerce {got:?} to {BOOL_TYPE_NAME}");
Diagnostic::new(
"dsl.std.bool_cannot_coerce",
message,
Diagnostic::make_fields(&[(FIELD_COMMAND, command), (FIELD_GOT, got)]),
)
}
pub fn std_path_base_failed(reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("{FUNC_PATH_BASE}: {reason_text}");
Diagnostic::new(
"dsl.std.path_base_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_path_rel_failed(reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("{FUNC_PATH_REL}: {reason_text}");
Diagnostic::new(
"dsl.std.path_rel_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_shell_split_failed(reason: &shell_words::ParseError) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("{FUNC_SHELL_SPLIT_ARGS}: {reason_text}");
Diagnostic::new(
"dsl.std.shell_split_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_parse_args_arity(got: usize) -> Diagnostic {
let message = format!("{FUNC_PARSE_ARGS}() expects 1 argument, got {got}");
Diagnostic::new(
"dsl.std.parse_args_arity",
message,
Diagnostic::make_fields(&[("got", &got.to_string())]),
)
}
pub fn std_parse_args_bool_flag(flag: &str, got: &str) -> Diagnostic {
let message = format!(
"{FUNC_PARSE_ARGS} flag --{flag} expects {BOOL_TYPE_NAME} (true/false, 1/0, yes/no, on/off), got {got:?}"
);
Diagnostic::new(
"dsl.std.parse_args_bool_flag",
message,
Diagnostic::make_fields(&[("flag", flag), ("got", got)]),
)
}
pub fn std_parse_args_bool_type(flag: &str, actual: &str) -> Diagnostic {
let message =
format!("{FUNC_PARSE_ARGS} flag --{flag} expects {BOOL_TYPE_NAME}, got `{actual}`");
Diagnostic::new(
"dsl.std.parse_args_bool_type",
message,
Diagnostic::make_fields(&[("flag", flag), ("actual", actual)]),
)
}
pub fn std_parse_args_needs_value(flag: &str) -> Diagnostic {
let message = format!("{FUNC_PARSE_ARGS} flag --{flag} needs a value: use --{flag}=<value>");
Diagnostic::new(
"dsl.std.parse_args_needs_value",
message,
Diagnostic::make_fields(&[("flag", flag)]),
)
}
pub fn std_parse_args_expects_int(flag: &str) -> Diagnostic {
let message = format!("{FUNC_PARSE_ARGS} flag --{flag} expects {INT_TYPE_NAME}");
Diagnostic::new(
"dsl.std.parse_args_expects_int",
message,
Diagnostic::make_fields(&[("flag", flag)]),
)
}
pub fn std_parse_args_expects_float(flag: &str) -> Diagnostic {
let message = format!("{FUNC_PARSE_ARGS} flag --{flag} expects {FLOAT_TYPE_NAME}");
Diagnostic::new(
"dsl.std.parse_args_expects_float",
message,
Diagnostic::make_fields(&[("flag", flag)]),
)
}
pub fn std_parse_args_not_utf8() -> Diagnostic {
Diagnostic::new(
"dsl.std.parse_args_not_utf8",
format!("{FUNC_PARSE_ARGS}: argument must be UTF-8"),
Diagnostic::make_fields(&[]),
)
}
pub fn std_parse_args_lex_error(reason: &lexopt::Error) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{FUNC_PARSE_ARGS}: {reason_text}");
Diagnostic::new(
"dsl.std.parse_args_lex_error",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_parse_args_schema_flag_empty() -> Diagnostic {
Diagnostic::new(
"dsl.std.parse_args_schema_flag_empty",
format!("{FUNC_PARSE_ARGS} schema flag names must be non-empty"),
Diagnostic::make_fields(&[]),
)
}
pub fn std_parse_args_duplicate_flag(flag: &str, alias: Option<&str>) -> Diagnostic {
let display = match alias {
Some(alias) => format!("--{flag}/--{alias}"),
None => format!("--{flag}"),
};
let message = format!("{FUNC_PARSE_ARGS} duplicate flag {display}");
Diagnostic::new(
"dsl.std.parse_args_duplicate_flag",
message,
Diagnostic::make_fields(&[("flag", flag), ("display", &display)]),
)
}
pub fn std_parse_args_missing_flag(flag: &str, alias: Option<&str>) -> Diagnostic {
let display = match alias {
Some(alias) => format!("--{flag}/--{alias}"),
None => format!("--{flag}"),
};
let message = format!("{FUNC_PARSE_ARGS} missing required flag {display}");
Diagnostic::new(
"dsl.std.parse_args_missing_flag",
message,
Diagnostic::make_fields(&[("flag", flag), ("display", &display)]),
)
}
pub fn std_parse_args_unknown_flag(flag: &str) -> Diagnostic {
let message = format!("{FUNC_PARSE_ARGS} unknown flag --{flag}");
Diagnostic::new(
"dsl.std.parse_args_unknown_flag",
message,
Diagnostic::make_fields(&[("flag", flag)]),
)
}
pub fn std_parse_args_schema_type(name: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("{FUNC_PARSE_ARGS} schema type {name:?}: {reason_text}");
Diagnostic::new(
"dsl.std.parse_args_schema_type",
message,
Diagnostic::make_fields(&[("name", name), ("reason", &reason_text)]),
)
}
pub fn std_parse_args_schema_shape(name: &str) -> Diagnostic {
let message = format!(
"{FUNC_PARSE_ARGS} schema type {name:?} must be a {MAP_TYPE_NAME} shape with scalar fields"
);
Diagnostic::new(
"dsl.std.parse_args_schema_shape",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn std_parse_args_schema_field_type(field: &str, actual: &str) -> Diagnostic {
let message = format!(
"{FUNC_PARSE_ARGS} schema for --{field}: type must be one of {STRING_TYPE_NAME}, {BOOL_TYPE_NAME}, {INT_TYPE_NAME}, or {FLOAT_TYPE_NAME}, got {actual}"
);
Diagnostic::new(
"dsl.std.parse_args_schema_field_type",
message,
Diagnostic::make_fields(&[("field", field), ("actual", actual)]),
)
}
pub fn std_parse_args_arg_shape(reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
Diagnostic::new(
"dsl.std.parse_args_arg_shape",
reason_text.clone(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_parse_flags_arity(got: usize) -> Diagnostic {
let message = format!("{FUNC_PARSE_FLAGS}() expects 1 argument, got {got}");
Diagnostic::new(
"dsl.std.parse_flags_arity",
message,
Diagnostic::make_fields(&[("got", &got.to_string())]),
)
}
pub fn std_parse_flags_positional(items: &[String]) -> Diagnostic {
let joined = items.join(", ");
let message =
format!("{FUNC_PARSE_FLAGS}() does not accept positional arguments; found {joined}");
Diagnostic::new(
"dsl.std.parse_flags_positional",
message,
Diagnostic::make_fields(&[("found", &joined)]),
)
}
pub fn std_parse_positionals_arity(got: usize) -> Diagnostic {
let message = format!("{FUNC_PARSE_POSITIONALS}() expects 1 argument, got {got}");
Diagnostic::new(
"dsl.std.parse_positionals_arity",
message,
Diagnostic::make_fields(&[("got", &got.to_string())]),
)
}
pub fn std_parse_byte_count_negative(n: i64) -> Diagnostic {
let message = format!("{FUNC_PARSE_BYTE_COUNT} needs a non-negative byte count, got {n}");
Diagnostic::new(
"dsl.std.parse_byte_count_negative",
message,
Diagnostic::make_fields(&[("got", &n.to_string())]),
)
}
pub fn std_parse_byte_count_integral(got: f64) -> Diagnostic {
let message = format!("{FUNC_PARSE_BYTE_COUNT} needs an integral byte count, got {got:?}");
Diagnostic::new(
"dsl.std.parse_byte_count_integral",
message,
Diagnostic::make_fields(&[("got", &format!("{got:?}"))]),
)
}
pub fn std_parse_byte_count_shape(got: &super::Value) -> Diagnostic {
let message = format!("{FUNC_PARSE_BYTE_COUNT} needs a token or number, found {got:?}");
Diagnostic::new(
"dsl.std.parse_byte_count_shape",
message,
Diagnostic::make_fields(&[("got", &format!("{got:?}"))]),
)
}
pub fn std_parse_byte_count_range(s: &str) -> Diagnostic {
let message = format!("{FUNC_PARSE_BYTE_COUNT} out of {INT_TYPE_NAME} range: {s:?}");
Diagnostic::new(
"dsl.std.parse_byte_count_range",
message,
Diagnostic::make_fields(&[("got", s)]),
)
}
pub fn std_int_non_integer_float(got: f64) -> Diagnostic {
let message =
format!("{FUNC_INT}() requires an integer value, found {FLOAT_TYPE_NAME} ({got:?})");
Diagnostic::new(
"dsl.std.int_non_integer_float",
message,
Diagnostic::make_fields(&[("got", &format!("{got:?}"))]),
)
}
pub fn std_int_bad_string(s: &str) -> Diagnostic {
let message = format!("{FUNC_INT}() requires an integer string, found {s:?}");
Diagnostic::new(
"dsl.std.int_bad_string",
message,
Diagnostic::make_fields(&[("got", s)]),
)
}
pub fn std_int_bad_type(got: &super::Value) -> Diagnostic {
let message = format!("{FUNC_INT}() requires an Int, Float, Bool, or String, found {got:?}");
Diagnostic::new(
"dsl.std.int_bad_type",
message,
Diagnostic::make_fields(&[("got", &format!("{got:?}"))]),
)
}
pub fn std_float_non_finite_float(got: f64) -> Diagnostic {
let message =
format!("{FUNC_FLOAT}() requires a finite value, found {FLOAT_TYPE_NAME} ({got:?})");
Diagnostic::new(
"dsl.std.float_non_finite_float",
message,
Diagnostic::make_fields(&[("got", &format!("{got:?}"))]),
)
}
pub fn std_float_bad_string(s: &str) -> Diagnostic {
let message = format!("{FUNC_FLOAT}() requires a numeric string, found {s:?}");
Diagnostic::new(
"dsl.std.float_bad_string",
message,
Diagnostic::make_fields(&[("got", s)]),
)
}
pub fn std_float_non_finite_string(s: &str) -> Diagnostic {
let message = format!("{FUNC_FLOAT}() requires a finite value, found {s:?}");
Diagnostic::new(
"dsl.std.float_non_finite_string",
message,
Diagnostic::make_fields(&[("got", s)]),
)
}
pub fn std_float_bad_type(got: &super::Value) -> Diagnostic {
let message = format!("{FUNC_FLOAT}() requires an Int, Float, or String, found {got:?}");
Diagnostic::new(
"dsl.std.float_bad_type",
message,
Diagnostic::make_fields(&[("got", &format!("{got:?}"))]),
)
}
pub fn eval_math_stack_underflow() -> Diagnostic {
Diagnostic::new(
"dsl.eval.math_stack_underflow",
"compiled math stack underflow".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_math_stack_len(len: usize) -> Diagnostic {
let message = format!("compiled math left {len} values on the stack");
Diagnostic::new(
"dsl.eval.math_stack_len",
message,
Diagnostic::make_fields(&[("count", &len.to_string())]),
)
}
pub fn eval_arith_overflow_div_zero() -> Diagnostic {
Diagnostic::new(
"dsl.eval.arith_overflow_div_zero",
"arithmetic error: integer overflow or division by zero".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_arith_needs_numeric(left: &super::Value, right: &super::Value) -> Diagnostic {
let message =
format!("Type Error: arithmetic requires Int or Float, found {left:?} and {right:?}");
Diagnostic::new(
"dsl.eval.arith_needs_numeric",
message,
Diagnostic::make_fields(&[
("left", &format!("{left:?}")),
("right", &format!("{right:?}")),
]),
)
}
pub fn eval_float_div_zero() -> Diagnostic {
Diagnostic::new(
"dsl.eval.float_div_zero",
"arithmetic error: float division by zero".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_non_finite_result() -> Diagnostic {
Diagnostic::new(
"dsl.eval.non_finite_result",
"arithmetic error: non-finite float result".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_neg_overflow() -> Diagnostic {
Diagnostic::new(
"dsl.eval.neg_overflow",
"arithmetic error: integer overflow".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_neg_needs_numeric(got: &super::Value) -> Diagnostic {
let message = format!("Type Error: unary '-' requires Int or Float, found {got:?}");
Diagnostic::new(
"dsl.eval.neg_needs_numeric",
message,
Diagnostic::make_fields(&[("got", &format!("{got:?}"))]),
)
}
pub fn eval_condition_needs_bool(got: &super::Value) -> Diagnostic {
let message = format!("Type Error: condition must be a Bool, found {got:?}");
Diagnostic::new(
"dsl.eval.condition_needs_bool",
message,
Diagnostic::make_fields(&[("got", &format!("{got:?}"))]),
)
}
pub fn eval_expected_int(got: &str) -> Diagnostic {
let message = format!("expected int, got {got:?}");
Diagnostic::new(
"dsl.eval.expected_int",
message,
Diagnostic::make_fields(&[("got", got)]),
)
}
pub fn eval_dispatch_failed(reason: &Diagnostic) -> Diagnostic {
eval_dispatch_fallback(&flatten_chain(reason))
}
pub fn eval_dispatch_fallback(reason_text: &str) -> Diagnostic {
Diagnostic::new(
"dsl.eval.dispatch_failed",
reason_text.to_string(),
Diagnostic::make_fields(&[(FIELD_REASON, reason_text)]),
)
}
pub fn eval_stream_write_failed(reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
Diagnostic::new(
"dsl.eval.stream_write_failed",
reason_text.clone(),
Diagnostic::make_fields(&[(FIELD_REASON, reason_text.as_str())]),
)
}
pub fn eval_pipe_assertion_read_failed(reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("step pipe assertion cannot read pipe: {reason_text}");
Diagnostic::new(
"dsl.eval.pipe_assertion_read_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn eval_with_io_unexpanded() -> Diagnostic {
Diagnostic::new(
"dsl.eval.with_io_unexpanded",
format!("{KEYWORD_WITH_IO} block should have been expanded during parsing"),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_with_io_geometry_needs_tty() -> Diagnostic {
Diagnostic::new(
"dsl.eval.with_io_geometry_needs_tty",
format!(
"{KEYWORD_WITH_IO} [rows]/[cols] need [tty] on the same step: geometry without a terminal has nothing to size"
),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_with_io_tty_no_stderr() -> Diagnostic {
Diagnostic::new(
"dsl.eval.with_io_tty_no_stderr",
format!(
"{KEYWORD_WITH_IO} [tty] cannot bind stderr: the pty master carries stdout and stderr interleaved, so the two streams cannot demultiplex"
),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_with_io_tty_needs_run() -> Diagnostic {
Diagnostic::new(
"dsl.eval.with_io_tty_needs_run",
format!(
"{KEYWORD_WITH_IO} [tty] only wraps a {KEYWORD_RUN} step: the pty master is one interleaved child stream, so terminal-unaware commands cannot run under it"
),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_with_io_duplicate_stream(stream: &str) -> Diagnostic {
Diagnostic::new(
"dsl.eval.with_io_duplicate_stream",
format!("{KEYWORD_WITH_IO} declared {stream} more than once"),
Diagnostic::make_fields(&[("stream", stream)]),
)
}
pub fn eval_pipe_handle_mismatch(actual: &str, value: &super::Value) -> Diagnostic {
let message = format!("TypeMismatch: expected {PIPE_TYPE_NAME}, got {actual} ({value:?})");
let got_text = format!("{value:?}");
Diagnostic::new(
"dsl.eval.pipe_handle_mismatch",
message,
Diagnostic::make_fields(&[("actual", actual), ("got", &got_text)]),
)
}
pub fn eval_async_cancelled() -> Diagnostic {
Diagnostic::new(
"dsl.eval.async_cancelled",
format!("{KEYWORD_ASYNC} task cancelled"),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_async_thread_panicked(detail: &str) -> Diagnostic {
Diagnostic::new(
"dsl.eval.async_thread_panicked",
detail.to_string(),
Diagnostic::make_fields(&[(FIELD_DETAIL, detail)]),
)
}
pub fn eval_exit_requested(code: i64) -> Diagnostic {
let code_text = code.to_string();
Diagnostic::new(
KEY_EVAL_EXIT_REQUESTED,
format!("{KEYWORD_EXIT} requested with code {code}"),
Diagnostic::make_fields(&[(FIELD_CODE, &code_text)]),
)
}
pub(super) fn eval_exit_requested_code(diag: &Diagnostic) -> Option<i64> {
if diag.key() != KEY_EVAL_EXIT_REQUESTED {
return None;
}
diag.fields().get(FIELD_CODE)?.parse::<i64>().ok()
}
pub fn eval_run_snapshot_context(failure: &str, snapshot: &str) -> Diagnostic {
Diagnostic::new(
"dsl.eval.snapshot_context",
format!("{failure}\n{snapshot}"),
Diagnostic::make_fields(&[(FIELD_SNAPSHOT, snapshot)]),
)
}
pub fn eval_async_exit_status(task: Option<u64>, status: &std::process::ExitStatus) -> Diagnostic {
let status_text = super::exit::describe_exit_status(status);
let code_text = super::exit::exit_status_code(status).map(|code| code.to_string());
let message = match task {
Some(id) => format!("named {KEYWORD_ASYNC} task {id} exited with status {status_text}"),
None => format!("{KEYWORD_ASYNC} process exited with status {status_text}"),
};
let task_text = task.map(|id| id.to_string());
let mut fields: Vec<(&str, &str)> = Vec::with_capacity(2);
if let Some(task) = task_text.as_deref() {
fields.push((FIELD_TASK, task));
}
match code_text.as_deref() {
Some(code) => fields.push((FIELD_CODE, code)),
None => fields.push((FIELD_STATUS, &status_text)),
}
Diagnostic::new(
"dsl.eval.async_exit_status",
message,
Diagnostic::make_fields(&fields),
)
}
pub fn eval_flow_crosses_remote(step: usize, word: &str) -> Diagnostic {
let message = format!("step {step}: {word} cannot cross a {KEYWORD_REMOTE} boundary");
Diagnostic::new(
"dsl.eval.flow_crosses_remote",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("flow", word)]),
)
}
pub fn eval_stdin_lock_failed(func: &str) -> Diagnostic {
let message = format!("failed to lock stdin for {func}");
Diagnostic::new(
"dsl.eval.stdin_lock_failed",
message,
Diagnostic::make_fields(&[("func", func)]),
)
}
pub fn eval_stdin_read_failed(func: Option<&str>, reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = match func {
Some(verb) => format!("failed to read from stdin for {verb}: {reason_text}"),
None => format!("failed to read from stdin: {reason_text}"),
};
let mut fields: Vec<(&str, &str)> = Vec::with_capacity(2);
if let Some(verb) = func {
fields.push(("func", verb));
}
fields.push(("reason", &reason_text));
Diagnostic::new(
"dsl.eval.stdin_read_failed",
message,
Diagnostic::make_fields(&fields),
)
}
pub fn eval_assert_stdin_overflow(verb: &str) -> Diagnostic {
let message = format!(
"{verb} stdin exceeded the 8 MiB exact buffer; assert via pipe targets or harness expect.stdout"
);
Diagnostic::new(
"dsl.eval.assert_stdin_overflow",
message,
Diagnostic::make_fields(&[("verb", verb)]),
)
}
pub fn eval_assert_stdout_overflow(verb: &str) -> Diagnostic {
let message = format!(
"{verb} stdout overflowed the 8 MiB exact buffer; assert via pipe targets or harness expect.stdout"
);
Diagnostic::new(
"dsl.eval.assert_stdout_overflow",
message,
Diagnostic::make_fields(&[("verb", verb)]),
)
}
pub fn eval_assert_no_exact_capture(verb: &str) -> Diagnostic {
let message = format!("{verb} stdout has no exact capture registered");
Diagnostic::new(
"dsl.eval.assert_no_exact_capture",
message,
Diagnostic::make_fields(&[("verb", verb)]),
)
}
pub fn eval_assert_hash_mismatch(verb: &str, expected: &str, computed: &str) -> Diagnostic {
let message = format!("{verb} --hash mismatch: expected {expected}, computed {computed}");
Diagnostic::new(
"dsl.eval.assert_hash_mismatch",
message,
Diagnostic::make_fields(&[
("verb", verb),
("expected", expected),
("computed", computed),
]),
)
}
pub fn eval_assert_hash_match(verb: &str, sha: &str) -> Diagnostic {
let message = format!("{verb} --hash match: content matches {sha}");
Diagnostic::new(
"dsl.eval.assert_hash_match",
message,
Diagnostic::make_fields(&[("verb", verb), ("sha", sha)]),
)
}
pub fn eval_assert_hash_needs_string(verb: &str, actual: &super::Value) -> Diagnostic {
let message = format!("{verb} --hash needs a string actual, found {actual:?}");
Diagnostic::new(
"dsl.eval.assert_hash_needs_string",
message,
Diagnostic::make_fields(&[("verb", verb), ("actual", &format!("{actual:?}"))]),
)
}
pub fn eval_assert_stream_mismatch(
verb: &str,
expected: Option<&super::Value>,
actual: &str,
) -> Diagnostic {
let message = format!("{verb} stream mismatch\nexpected: {expected:?}\nactual: {actual:?}");
Diagnostic::new(
"dsl.eval.assert_stream_mismatch",
message,
Diagnostic::make_fields(&[
("verb", verb),
("expected", &format!("{expected:?}")),
("actual", actual),
]),
)
}
pub fn eval_assert_stream_mismatch_text(verb: &str, expected: &str, actual: &str) -> Diagnostic {
let message = format!("{verb} stream mismatch\nexpected: {expected:?}\nactual: {actual:?}");
Diagnostic::new(
"dsl.eval.assert_stream_mismatch_text",
message,
Diagnostic::make_fields(&[("verb", verb), ("expected", expected), ("actual", actual)]),
)
}
pub fn eval_assert_stream_unexpected_equal(verb: &str, expected: &str) -> Diagnostic {
let message = format!("{verb} stream unexpectedly equal: {expected:?}");
Diagnostic::new(
"dsl.eval.assert_stream_unexpected_equal",
message,
Diagnostic::make_fields(&[("verb", verb), ("expected", expected)]),
)
}
pub fn eval_assert_stderr_unsupported(verb: &str) -> Diagnostic {
let message =
format!("{verb} over stderr is not supported; use {KEYWORD_ASSERT_CONTAINS} stderr ...");
Diagnostic::new(
"dsl.eval.assert_stderr_unsupported",
message,
Diagnostic::make_fields(&[("verb", verb)]),
)
}
pub fn eval_assert_requires_expected(verb: &str) -> Diagnostic {
let message = format!("{verb} requires an expected value");
Diagnostic::new(
"dsl.eval.assert_requires_expected",
message,
Diagnostic::make_fields(&[("verb", verb)]),
)
}
pub fn eval_assert_value_mismatch(
verb: &str,
expected: &super::Value,
actual: &super::Value,
) -> Diagnostic {
let message = format!("{verb} mismatch\nexpected: {expected:?}\nactual: {actual:?}");
Diagnostic::new(
"dsl.eval.assert_value_mismatch",
message,
Diagnostic::make_fields(&[
("verb", verb),
("expected", &format!("{expected:?}")),
("actual", &format!("{actual:?}")),
]),
)
}
pub fn eval_assert_value_unexpected_equal(
verb: &str,
expected: &super::Value,
actual: &super::Value,
) -> Diagnostic {
let message =
format!("{verb} mismatch: values are equal\nexpected: {expected:?}\nactual: {actual:?}");
Diagnostic::new(
"dsl.eval.assert_value_unexpected_equal",
message,
Diagnostic::make_fields(&[
("verb", verb),
("expected", &format!("{expected:?}")),
("actual", &format!("{actual:?}")),
]),
)
}
pub fn eval_assert_pipe_mismatch(
verb: &str,
expected: Option<&super::Value>,
actual: &str,
) -> Diagnostic {
let message = format!("{verb} pipe mismatch\nexpected: {expected:?}\nactual: {actual:?}");
Diagnostic::new(
"dsl.eval.assert_pipe_mismatch",
message,
Diagnostic::make_fields(&[
("verb", verb),
("expected", &format!("{expected:?}")),
("actual", actual),
]),
)
}
pub fn eval_assert_pipe_mismatch_text(verb: &str, expected: &str, actual: &str) -> Diagnostic {
let message = format!("{verb} pipe mismatch\nexpected: {expected:?}\nactual: {actual:?}");
Diagnostic::new(
"dsl.eval.assert_pipe_mismatch_text",
message,
Diagnostic::make_fields(&[("verb", verb), ("expected", expected), ("actual", actual)]),
)
}
pub fn eval_assert_pipe_unexpected_equal(verb: &str, expected: &str) -> Diagnostic {
let message = format!("{verb} pipe unexpectedly equal: {expected:?}");
Diagnostic::new(
"dsl.eval.assert_pipe_unexpected_equal",
message,
Diagnostic::make_fields(&[("verb", verb), ("expected", expected)]),
)
}
pub fn eval_assert_contains_str_mismatch(verb: &str, needle: &str, actual: &str) -> Diagnostic {
let message = format!("{verb} did not contain '{needle}'; actual: {actual:?}");
Diagnostic::new(
"dsl.eval.assert_contains_str_mismatch",
message,
Diagnostic::make_fields(&[("verb", verb), ("needle", needle), ("actual", actual)]),
)
}
pub fn eval_assert_contains_value_mismatch(
verb: &str,
needle: &str,
actual: &super::Value,
) -> Diagnostic {
let message = format!("{verb} did not contain '{needle}'; actual: {actual:?}");
Diagnostic::new(
"dsl.eval.assert_contains_value_mismatch",
message,
Diagnostic::make_fields(&[
("verb", verb),
("needle", needle),
("actual", &format!("{actual:?}")),
]),
)
}
pub fn eval_assert_contains_missing(verb: &str, needle: &str) -> Diagnostic {
let message = format!("{verb} did not contain '{needle}'");
Diagnostic::new(
"dsl.eval.assert_contains_missing",
message,
Diagnostic::make_fields(&[("verb", verb), ("needle", needle)]),
)
}
pub fn eval_assert_contains_needs_haystack(verb: &str, actual: &super::Value) -> Diagnostic {
let message = format!("{verb} needs a string, list, or map haystack, found {actual:?}");
Diagnostic::new(
"dsl.eval.assert_contains_needs_haystack",
message,
Diagnostic::make_fields(&[("verb", verb), ("actual", &format!("{actual:?}"))]),
)
}
pub fn eval_assert_contains_emitted_mismatch(
verb: &str,
needle: &str,
emitted: &str,
) -> Diagnostic {
let trimmed = emitted.trim_end();
let message = format!("{verb} did not contain '{needle}'; emitted:\n{trimmed}");
Diagnostic::new(
"dsl.eval.assert_contains_emitted_mismatch",
message,
Diagnostic::make_fields(&[("verb", verb), ("needle", needle), ("emitted", trimmed)]),
)
}
pub fn eval_assert_contains_pipe_mismatch(verb: &str, needle: &str, hay: &str) -> Diagnostic {
let message = format!("{verb} did not contain '{needle}'; pipe held {hay:?}");
Diagnostic::new(
"dsl.eval.assert_contains_pipe_mismatch",
message,
Diagnostic::make_fields(&[("verb", verb), ("needle", needle), ("hay", hay)]),
)
}
pub fn eval_break_outside_loop() -> Diagnostic {
let message = format!("{KEYWORD_BREAK} outside loop");
Diagnostic::new(
"dsl.eval.break_outside_loop",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn eval_continue_outside_loop() -> Diagnostic {
let message = format!("{KEYWORD_CONTINUE} outside loop");
Diagnostic::new(
"dsl.eval.continue_outside_loop",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn eval_capture_flow_outside_loop(step: usize, word: &str) -> Diagnostic {
let message = format!("step {step}: {word} outside loop (cannot be captured)");
Diagnostic::new(
"dsl.eval.capture_flow_outside_loop",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("flow", word)]),
)
}
pub fn eval_capture_return_outside_function(step: usize) -> Diagnostic {
let message = format!("step {step}: {KEYWORD_RETURN} outside function (cannot be captured)");
Diagnostic::new(
"dsl.eval.capture_return_outside_function",
message,
Diagnostic::make_fields(&[("step", &step.to_string())]),
)
}
pub fn eval_block_flow_crosses_block(step: usize, word: &str) -> Diagnostic {
let message = format!("step {step}: {word} cannot cross block boundary");
Diagnostic::new(
"dsl.eval.block_flow_crosses_block",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("flow", word)]),
)
}
pub fn eval_async_flow_crosses_async(step: usize, word: &str) -> Diagnostic {
let message = format!("step {step}: {word} cannot cross {KEYWORD_ASYNC} boundary");
Diagnostic::new(
"dsl.eval.async_flow_crosses_async",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("flow", word)]),
)
}
pub fn eval_capture_with_io_stdout(kw: &str) -> Diagnostic {
let message = format!(
"{kw} capture cannot use {KEYWORD_WITH_IO} [stdout=$var]; the capture binds the {KEYWORD_RETURN} value"
);
Diagnostic::new(
"dsl.eval.capture_with_io_stdout",
message,
Diagnostic::make_fields(&[("keyword", kw)]),
)
}
pub fn eval_capture_not_utf8(kw: &str, var: &str, reason: Diagnostic) -> Diagnostic {
let reason_text = reason.to_string();
let message = format!("{kw} ${var} capture is not valid UTF-8");
Diagnostic::new(
"dsl.eval.capture_not_utf8",
message,
Diagnostic::make_fields(&[("keyword", kw), ("var", var), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new(reason))
}
pub fn eval_with_io_tty_live_pipe(stream: &str) -> Diagnostic {
let message = format!(
"{KEYWORD_WITH_IO} [tty] {stream} cannot arrive on a live OS pipe; bind a script pipe with {stream}=$var"
);
Diagnostic::new(
"dsl.eval.with_io_tty_live_pipe",
message,
Diagnostic::make_fields(&[("stream", stream)]),
)
}
pub fn eval_write_live_pipe(stream: &str) -> Diagnostic {
Diagnostic::new(
"dsl.eval.write_live_pipe",
"cannot write DSL output to a live OS pipe".to_string(),
Diagnostic::make_fields(&[("stream", stream)]),
)
}
pub fn eval_async_entry_unavailable() -> Diagnostic {
Diagnostic::new(
"dsl.eval.async_entry_unavailable",
format!("{KEYWORD_ASYNC} task entry unavailable"),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_task_var_undefined(var: &str) -> Diagnostic {
let message = format!("variable '${var}' is not defined");
Diagnostic::new(
"dsl.eval.task_var_undefined",
message,
Diagnostic::make_fields(&[("var", var)]),
)
}
pub fn eval_task_not_handle(var: &str) -> Diagnostic {
let message = format!("variable '${var}' is not a task handle");
Diagnostic::new(
"dsl.eval.task_not_handle",
message,
Diagnostic::make_fields(&[("var", var)]),
)
}
pub fn eval_task_not_found(label: &str) -> Diagnostic {
let message = format!("task handle for '{label}' was not found or has already been awaited");
Diagnostic::new(
"dsl.eval.task_not_found",
message,
Diagnostic::make_fields(&[("label", label)]),
)
}
pub fn eval_await_cancelled(var: &str) -> Diagnostic {
let message = format!("{KEYWORD_AWAIT} task '${var}' was cancelled");
Diagnostic::new(
"dsl.eval.await_cancelled",
message,
Diagnostic::make_fields(&[("var", var)]),
)
}
pub fn eval_await_member_not_handle(label: &str, got: &str) -> Diagnostic {
let message = format!("{KEYWORD_AWAIT} '{label}' is not a task handle, got {got}");
Diagnostic::new(
"dsl.eval.await_member_not_handle",
message,
Diagnostic::make_fields(&[("label", label), ("got", got)]),
)
}
pub fn eval_await_timeout(var: &str) -> Diagnostic {
let message = format!("{KEYWORD_AWAIT} task '${var}' interrupted by {KEYWORD_TIMEOUT}");
Diagnostic::new(
"dsl.eval.await_timeout",
message,
Diagnostic::make_fields(&[("var", var)]),
)
}
pub fn eval_await_exit_status(var: &str, status: &std::process::ExitStatus) -> Diagnostic {
let status_text = super::exit::describe_exit_status(status);
let code_text = super::exit::exit_status_code(status).map(|code| code.to_string());
let message = format!("{KEYWORD_AWAIT} task '${var}' failed with status {status_text}");
let status_field: (&str, &str) = match code_text.as_deref() {
Some(code) => (FIELD_CODE, code),
None => (FIELD_STATUS, &status_text),
};
Diagnostic::new(
"dsl.eval.await_exit_status",
message,
Diagnostic::make_fields(&[(FIELD_VAR, var), status_field]),
)
}
pub fn eval_await_fell_off(kw: &str, out_var: &str, task_var: &str) -> Diagnostic {
let message = format!(
"{kw} ${out_var} = {KEYWORD_AWAIT} ${task_var} fell off the end without {KEYWORD_RETURN}: the task body can return a value on some path but this run produced none"
);
Diagnostic::new(
"dsl.eval.await_fell_off",
message,
Diagnostic::make_fields(&[("keyword", kw), ("out", out_var), ("task", task_var)]),
)
}
pub fn eval_cancel_gone(var: &str) -> Diagnostic {
let message =
format!("{KEYWORD_CANCEL}: task '${var}' has already been awaited or does not exist");
Diagnostic::new(
"dsl.eval.cancel_gone",
message,
Diagnostic::make_fields(&[("var", var)]),
)
}
pub fn eval_cancel_already(var: &str) -> Diagnostic {
let message = format!("{KEYWORD_CANCEL}: task '${var}' was already cancelled");
Diagnostic::new(
"dsl.eval.cancel_already",
message,
Diagnostic::make_fields(&[("var", var)]),
)
}
pub fn eval_timeout_deadline(budget: &str) -> Diagnostic {
let message = format!("{KEYWORD_TIMEOUT} after {budget} — deadline exceeded");
Diagnostic::new(
"dsl.eval.timeout_deadline",
message,
Diagnostic::make_fields(&[("budget", budget)]),
)
}
pub fn eval_inside_isolated() -> Diagnostic {
Diagnostic::new(
"dsl.eval.inside_isolated",
format!("inside {KEYWORD_ISOLATED} block"),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_isolated_outside_allowlist() -> Diagnostic {
Diagnostic::new(
"dsl.eval.isolated_outside_allowlist",
format!("isolated allowlist outside {KEYWORD_ISOLATED}"),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_placeholder_miss_text(text: &str) -> Diagnostic {
Diagnostic::new(
"dsl.eval.placeholder_miss_text",
text.to_string(),
Diagnostic::make_fields(&[("reason", text)]),
)
}
pub fn eval_remote_copy_outside_guest() -> Diagnostic {
Diagnostic::new(
"dsl.eval.remote_copy_outside_guest",
format!(
"{KEYWORD_COPY} --from-host and --to-host execute only inside a remote guest session"
),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_remote_rewind_failed(reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("transfer stage rewind failed: {reason_text}");
Diagnostic::new(
"dsl.eval.remote_rewind_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn eval_remote_push_file_read_failed(reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_REMOTE} push file read failed: {reason_text}");
Diagnostic::new(
"dsl.eval.remote_push_file_read_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn eval_remote_push_file_write_failed(reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_REMOTE} push file write failed: {reason_text}");
Diagnostic::new(
"dsl.eval.remote_push_file_write_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn eval_remote_unknown_var(target: &str, name: &str) -> Diagnostic {
let message = format!("{KEYWORD_REMOTE} '{target}' uses unknown variable ${name}");
Diagnostic::new(
"dsl.eval.remote_unknown_var",
message,
Diagnostic::make_fields(&[("target", target), ("var", name)]),
)
}
pub fn eval_remote_unrenderable_var(name: &str, actual: &str, target: &str) -> Diagnostic {
let message = format!(
"cannot pass ${name}: {actual} into {KEYWORD_REMOTE} '{target}' (pass bytes via {KEYWORD_WITH_IO}, files via the workspace)"
);
Diagnostic::new(
"dsl.eval.remote_unrenderable_var",
message,
Diagnostic::make_fields(&[("var", name), ("actual", actual), ("target", target)]),
)
}
pub fn eval_remote_unknown_env(target: &str, name: &str) -> Diagnostic {
let message = format!("{KEYWORD_REMOTE} '{target}' uses unknown env {name}");
Diagnostic::new(
"dsl.eval.remote_unknown_env",
message,
Diagnostic::make_fields(&[("target", target), ("env", name)]),
)
}
pub fn eval_remote_fetch_missing(rel: &str, reason: Option<&Diagnostic>) -> Diagnostic {
let reason_text = reason.map(flatten_chain);
let message = match &reason_text {
Some(text) => format!("{KEYWORD_REMOTE} fetch source missing: {rel} ({text})"),
None => format!("{KEYWORD_REMOTE} fetch source missing: {rel}"),
};
let fields = match &reason_text {
Some(text) => Diagnostic::make_fields(&[("rel", rel), ("reason", text.as_str())]),
None => Diagnostic::make_fields(&[("rel", rel)]),
};
Diagnostic::new("dsl.eval.remote_fetch_missing", message, fields)
}
pub fn eval_remote_fetch_entry_cap(rel: &str, cap: usize) -> Diagnostic {
let message =
format!("{KEYWORD_REMOTE} fetch hit the {cap} entry cap: {rel} names too many paths");
Diagnostic::new(
"dsl.eval.remote_fetch_entry_cap",
message,
Diagnostic::make_fields(&[("rel", rel), ("cap", &cap.to_string())]),
)
}
pub fn eval_remote_fetch_no_file_name(rel: &str) -> Diagnostic {
let message = format!("{KEYWORD_REMOTE} fetch source has no file name: {rel}");
Diagnostic::new(
"dsl.eval.remote_fetch_no_file_name",
message,
Diagnostic::make_fields(&[("rel", rel)]),
)
}
pub fn eval_remote_no_session(target: &str) -> Diagnostic {
let message = format!(
"{KEYWORD_REMOTE} '{target}' has no registered session (bind it with --remote {target}=\"<command>\")"
);
Diagnostic::new(
"dsl.eval.remote_no_session",
message,
Diagnostic::make_fields(&[("target", target)]),
)
}
pub fn eval_remote_exit_status(target: &str, code: i64) -> Diagnostic {
let message = format!("{KEYWORD_REMOTE} '{target}' exited with code {code}");
Diagnostic::new(
"dsl.eval.remote_exit_status",
message,
Diagnostic::make_fields(&[(FIELD_TARGET, target), (FIELD_CODE, &code.to_string())]),
)
}
pub fn eval_remote_transport_failed(target: &str) -> Diagnostic {
let message = format!("{KEYWORD_REMOTE} '{target}' transport failed");
Diagnostic::new(
"dsl.eval.remote_transport_failed",
message,
Diagnostic::make_fields(&[("target", target)]),
)
}
pub fn eval_remote_push_destination_escapes(rel: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!(
"{KEYWORD_REMOTE} push symlink destination {rel:?} escapes the workspace: {reason_text}"
);
Diagnostic::new(
"dsl.eval.remote_push_destination_escapes",
message,
Diagnostic::make_fields(&[("rel", rel), ("reason", &reason_text)]),
)
}
pub fn eval_remote_push_target_outside(rel: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!(
"{KEYWORD_REMOTE} push symlink {rel:?} points outside the workspace: {reason_text}"
);
Diagnostic::new(
"dsl.eval.remote_push_target_outside",
message,
Diagnostic::make_fields(&[("rel", rel), ("reason", &reason_text)]),
)
}
pub fn eval_remote_push_symlink_over_dir(rel: &str) -> Diagnostic {
let message =
format!("{KEYWORD_REMOTE} sync-back cannot replace directory {rel:?} with a symlink");
Diagnostic::new(
"dsl.eval.remote_push_symlink_over_dir",
message,
Diagnostic::make_fields(&[("rel", rel)]),
)
}
pub fn eval_run_cancelled(command: &str) -> Diagnostic {
let message = format!("{KEYWORD_RUN} {command} interrupted by cancellation");
Diagnostic::new(
"dsl.eval.run_cancelled",
message,
Diagnostic::make_fields(&[(FIELD_COMMAND, command)]),
)
}
pub fn eval_run_argv_cancelled(argv: &[String]) -> Diagnostic {
let message = format!("{KEYWORD_RUN} {argv:?} interrupted by cancellation");
Diagnostic::new(
"dsl.eval.run_argv_cancelled",
message,
Diagnostic::make_fields(&[(FIELD_ARGV, &format!("{argv:?}"))]),
)
}
pub fn eval_run_unexpected_capture(command: &str) -> Diagnostic {
let message = format!("{KEYWORD_RUN} {command} unexpectedly captured output");
Diagnostic::new(
"dsl.eval.run_unexpected_capture",
message,
Diagnostic::make_fields(&[(FIELD_COMMAND, command)]),
)
}
pub fn eval_run_argv_unexpected_capture(argv: &[String]) -> Diagnostic {
let message = format!("{KEYWORD_RUN} {argv:?} unexpectedly captured output");
Diagnostic::new(
"dsl.eval.run_argv_unexpected_capture",
message,
Diagnostic::make_fields(&[(FIELD_ARGV, &format!("{argv:?}"))]),
)
}
pub fn eval_run_exit_status(command: &str, status: &std::process::ExitStatus) -> Diagnostic {
let status_text = super::exit::describe_exit_status(status);
let code_text = super::exit::exit_status_code(status).map(|code| code.to_string());
let message = format!("{KEYWORD_RUN} {command} exited with status {status_text}");
let status_field: (&str, &str) = match code_text.as_deref() {
Some(code) => (FIELD_CODE, code),
None => (FIELD_STATUS, &status_text),
};
Diagnostic::new(
"dsl.eval.run_exit_status",
message,
Diagnostic::make_fields(&[(FIELD_COMMAND, command), status_field]),
)
}
pub fn eval_run_argv_exit_status(argv: &[String], status: &std::process::ExitStatus) -> Diagnostic {
let status_text = super::exit::describe_exit_status(status);
let code_text = super::exit::exit_status_code(status).map(|code| code.to_string());
let message = format!("{KEYWORD_RUN} {argv:?} exited with status {status_text}");
let status_field: (&str, &str) = match code_text.as_deref() {
Some(code) => (FIELD_CODE, code),
None => (FIELD_STATUS, &status_text),
};
Diagnostic::new(
"dsl.eval.run_argv_exit_status",
message,
Diagnostic::make_fields(&[(FIELD_ARGV, &format!("{argv:?}")), status_field]),
)
}
pub fn eval_run_needs_program(command: &str) -> Diagnostic {
let message = format!("{KEYWORD_RUN} {command} needs at least a program");
Diagnostic::new(
"dsl.eval.run_needs_program",
message,
Diagnostic::make_fields(&[(FIELD_COMMAND, command)]),
)
}
pub fn eval_run_pty_exit_status(command: &str, code: i64) -> Diagnostic {
let message = format!("{KEYWORD_RUN} {command} exited with status {code}");
Diagnostic::new(
"dsl.eval.run_pty_exit_status",
message,
Diagnostic::make_fields(&[(FIELD_COMMAND, command), (FIELD_CODE, &code.to_string())]),
)
}
pub fn eval_run_exec_requires_arg() -> Diagnostic {
let message = format!("{KEYWORD_RUN} exec form requires at least one argument");
Diagnostic::new(
"dsl.eval.run_exec_requires_arg",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn eval_pipe_not_utf8(verb: &str, reason: &std::string::FromUtf8Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("{verb} pipe content is not UTF-8: {reason_text}");
Diagnostic::new(
"dsl.eval.pipe_not_utf8",
message,
Diagnostic::make_fields(&[("verb", verb), ("reason", &reason_text)]),
)
}
pub fn eval_run_spawn_failed(command: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("{KEYWORD_RUN} {command}: {reason_text}");
Diagnostic::new(
"dsl.eval.run_spawn_failed",
message,
Diagnostic::make_fields(&[(FIELD_COMMAND, command), (FIELD_REASON, &reason_text)]),
)
}
pub fn eval_run_argv_spawn_failed(argv: &[String], reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("{KEYWORD_RUN} {argv:?}: {reason_text}");
Diagnostic::new(
"dsl.eval.run_argv_spawn_failed",
message,
Diagnostic::make_fields(&[
(FIELD_ARGV, &format!("{argv:?}")),
(FIELD_REASON, &reason_text),
]),
)
}
pub fn eval_run_exec_pipe_arg() -> Diagnostic {
let message = format!(
"cannot pass {PIPE_TYPE_NAME} as a command argument: pipes carry streams between steps, not text. Capture the producing step's output with {KEYWORD_LET} $var: {STRING_TYPE_NAME} = ... instead."
);
Diagnostic::new(
"dsl.eval.run_exec_pipe_arg",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn eval_run_exec_semaphore_arg() -> Diagnostic {
let message = format!(
"cannot pass {SEMAPHORE_TYPE_NAME} as a command argument: semaphores coordinate task access between steps, not text."
);
Diagnostic::new(
"dsl.eval.run_exec_semaphore_arg",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn eval_run_exec_permit_arg() -> Diagnostic {
let message = format!(
"cannot pass {PERMIT_TYPE_NAME} as a command argument: permits grant scoped task access, not text."
);
Diagnostic::new(
"dsl.eval.run_exec_permit_arg",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn eval_run_exec_element_needs_string(got: &str) -> Diagnostic {
let message = format!("{KEYWORD_RUN} exec form element must be a string, got {got}");
Diagnostic::new(
"dsl.eval.run_exec_element_needs_string",
message,
Diagnostic::make_fields(&[("got", got)]),
)
}
pub fn eval_sleep_cancelled() -> Diagnostic {
let message = format!("{KEYWORD_SLEEP} interrupted by cancellation");
Diagnostic::new(
"dsl.eval.sleep_cancelled",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn eval_copy_failed(from: &str, to: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("{KEYWORD_COPY} {from} {to}: {reason_text}");
Diagnostic::new(
"dsl.eval.copy_failed",
message,
Diagnostic::make_fields(&[("from", from), ("to", to), ("reason", &reason_text)]),
)
}
pub fn eval_copy_git_failed(rev: &str, from: &str, to: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("{KEYWORD_COPY_GIT} {rev} {from} {to}: {reason_text}");
Diagnostic::new(
"dsl.eval.copy_git_failed",
message,
Diagnostic::make_fields(&[
("rev", rev),
("from", from),
("to", to),
("reason", &reason_text),
]),
)
}
pub fn eval_copy_no_file_name(display: &str) -> Diagnostic {
let message = format!("{KEYWORD_COPY} source has no file name: {display}");
Diagnostic::new(
"dsl.eval.copy_no_file_name",
message,
Diagnostic::make_fields(&[("path", display)]),
)
}
pub fn eval_copy_destination_escapes(display: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("{KEYWORD_COPY} destination escapes root: {display}: {reason_text}");
Diagnostic::new(
"dsl.eval.copy_destination_escapes",
message,
Diagnostic::make_fields(&[("path", display), ("reason", &reason_text)]),
)
}
pub fn eval_symlink_failed(from: &str, to: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_SYMLINK} {from} {to}");
Diagnostic::new(
"dsl.eval.symlink_failed",
message,
Diagnostic::make_fields(&[("from", from), ("to", to), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_symlink_no_file_name(from: &str) -> Diagnostic {
let message = format!("{KEYWORD_SYMLINK} source has no file name: {from}");
Diagnostic::new(
"dsl.eval.symlink_no_file_name",
message,
Diagnostic::make_fields(&[("from", from)]),
)
}
pub fn eval_archive_failed(src: &str, dst: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_ARCHIVE} {src} {dst}");
Diagnostic::new(
"dsl.eval.archive_failed",
message,
Diagnostic::make_fields(&[("src", src), ("dst", dst), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_archive_no_file_name(src: &str, dst: &str, display: &str) -> Diagnostic {
let message = format!("{KEYWORD_ARCHIVE} {src} {dst}: source has no file name: {display}");
Diagnostic::new(
"dsl.eval.archive_no_file_name",
message,
Diagnostic::make_fields(&[("src", src), ("dst", dst), ("display", display)]),
)
}
pub fn eval_archive_refuses_symlink_source(src: &str, dst: &str) -> Diagnostic {
let message = format!("{KEYWORD_ARCHIVE} {src} {dst}: refuses to pack symlink source {src:?}");
Diagnostic::new(
"dsl.eval.archive_refuses_symlink_source",
message,
Diagnostic::make_fields(&[("src", src), ("dst", dst)]),
)
}
pub fn eval_archive_refuses_symlink(src: &str, dst: &str, child: &str) -> Diagnostic {
let message = format!("{KEYWORD_ARCHIVE} {src} {dst}: refuses to pack symlink {child:?}");
Diagnostic::new(
"dsl.eval.archive_refuses_symlink",
message,
Diagnostic::make_fields(&[("src", src), ("dst", dst), ("child", child)]),
)
}
pub fn eval_archive_destination_is_source(src: &str, dst: &str) -> Diagnostic {
let message =
format!("{KEYWORD_ARCHIVE} {src} {dst}: destination {dst:?} cannot be the source itself");
Diagnostic::new(
"dsl.eval.archive_destination_is_source",
message,
Diagnostic::make_fields(&[("src", src), ("dst", dst)]),
)
}
pub fn eval_archive_destination_inside_tree(src: &str, dst: &str) -> Diagnostic {
let message = format!(
"{KEYWORD_ARCHIVE} {src} {dst}: destination {dst:?} cannot overwrite inside the packed tree"
);
Diagnostic::new(
"dsl.eval.archive_destination_inside_tree",
message,
Diagnostic::make_fields(&[("src", src), ("dst", dst)]),
)
}
pub fn eval_unarchive_failed(src: &str, dst: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_UNARCHIVE} {src} {dst}");
Diagnostic::new(
"dsl.eval.unarchive_failed",
message,
Diagnostic::make_fields(&[("src", src), ("dst", dst), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_unarchive_member_failed(src: &str, dst: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_UNARCHIVE} {src} {dst}: member");
Diagnostic::new(
"dsl.eval.unarchive_member_failed",
message,
Diagnostic::make_fields(&[("src", src), ("dst", dst), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_unarchive_bad_max_bytes(
src: &str,
dst: &str,
raw: &str,
reason: Diagnostic,
) -> Diagnostic {
let reason_text = reason.to_string();
let message = format!("{KEYWORD_UNARCHIVE} {src} {dst}: --max-bytes {raw:?}");
Diagnostic::new(
"dsl.eval.unarchive_bad_max_bytes",
message,
Diagnostic::make_fields(&[
("src", src),
("dst", dst),
("raw", raw),
("reason", &reason_text),
]),
)
.with_source(std::sync::Arc::new(reason))
}
pub fn eval_unarchive_expansion_cap(src: &str, dst: &str, cap: u64, path: &str) -> Diagnostic {
let message = format!(
"{KEYWORD_UNARCHIVE} {src} {dst}: member: archive exceeds the {cap}-byte expansion cap at {path:?}"
);
Diagnostic::new(
"dsl.eval.unarchive_expansion_cap",
message,
Diagnostic::make_fields(&[
("src", src),
("dst", dst),
("cap", &cap.to_string()),
("path", path),
]),
)
}
pub fn eval_unarchive_refuses_symlink(
src: &str,
dst: &str,
path: &str,
target: &str,
) -> Diagnostic {
let message = format!(
"{KEYWORD_UNARCHIVE} {src} {dst}: member: refuses symlink member {path:?} -> {target:?}"
);
Diagnostic::new(
"dsl.eval.unarchive_refuses_symlink",
message,
Diagnostic::make_fields(&[
("src", src),
("dst", dst),
("path", path),
("target", target),
]),
)
}
pub fn eval_unarchive_restore_mode_failed(src: &str, dst: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_UNARCHIVE} {src} {dst}: restoring mode");
Diagnostic::new(
"dsl.eval.unarchive_restore_mode_failed",
message,
Diagnostic::make_fields(&[("src", src), ("dst", dst), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_workdir_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_WORKDIR} {path}");
Diagnostic::new(
"dsl.eval.workdir_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_mkdir_resolve_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_MKDIR} {path}");
Diagnostic::new(
"dsl.eval.mkdir_resolve_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_mkdir_create_failed(display: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("failed to create dir {display}");
Diagnostic::new(
"dsl.eval.mkdir_create_failed",
message,
Diagnostic::make_fields(&[("path", display), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_set_executable_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_SET_EXECUTABLE} {path}");
Diagnostic::new(
"dsl.eval.set_executable_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_ls_resolve_failed(path: Option<&str>, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = match path {
Some(p) => format!("{KEYWORD_LS} {p}"),
None => KEYWORD_LS.to_string(),
};
let mut fields: Vec<(&str, &str)> = Vec::with_capacity(2);
if let Some(p) = path {
fields.push(("path", p));
}
fields.push(("reason", &reason_text));
Diagnostic::new(
"dsl.eval.ls_resolve_failed",
message,
Diagnostic::make_fields(&fields),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_ls_read_failed(display: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_LS} {display}");
Diagnostic::new(
"dsl.eval.ls_read_failed",
message,
Diagnostic::make_fields(&[("path", display), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_read_resolve_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_READ} {path}");
Diagnostic::new(
"dsl.eval.read_resolve_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_read_open_failed(display: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("failed to open {display}");
Diagnostic::new(
"dsl.eval.read_open_failed",
message,
Diagnostic::make_fields(&[("path", display), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_read_file_failed(reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
Diagnostic::new(
"dsl.eval.read_file_failed",
"failed to read from file".to_string(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new(std::io::Error::new(
reason.kind(),
reason.to_string(),
)))
}
pub fn eval_read_write_failed(reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
Diagnostic::new(
"dsl.eval.read_write_failed",
"failed to write to output".to_string(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new(std::io::Error::new(
reason.kind(),
reason.to_string(),
)))
}
pub fn eval_read_needs_stdin() -> Diagnostic {
let message =
format!("{KEYWORD_READ} requires stdin (use {KEYWORD_WITH_IO} [stdin=...] {KEYWORD_READ})");
Diagnostic::new(
"dsl.eval.read_needs_stdin",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn eval_read_line_needs_stdin() -> Diagnostic {
let message = format!(
"{KEYWORD_READ_LINE} requires stdin (use {KEYWORD_WITH_IO} [stdin=...] {KEYWORD_READ_LINE} $var)"
);
Diagnostic::new(
"dsl.eval.read_line_needs_stdin",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn eval_read_line_not_utf8(reason: &std::string::FromUtf8Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("{KEYWORD_READ_LINE} received non-UTF8 bytes");
Diagnostic::new(
"dsl.eval.read_line_not_utf8",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_write_resolve_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_WRITE} {path}");
Diagnostic::new(
"dsl.eval.write_resolve_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_ensure_parent_failed(display: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("failed to create parent for {display}");
Diagnostic::new(
"dsl.eval.ensure_parent_failed",
message,
Diagnostic::make_fields(&[("path", display), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_write_file_failed(display: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("failed to write {display}");
Diagnostic::new(
"dsl.eval.write_file_failed",
message,
Diagnostic::make_fields(&[("path", display), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_write_needs_stdin(path: &str) -> Diagnostic {
let message = format!(
"{KEYWORD_WRITE} {path} requires stdin (use {KEYWORD_WITH_IO} [stdin=...] {KEYWORD_WRITE})"
);
Diagnostic::new(
"dsl.eval.write_needs_stdin",
message,
Diagnostic::make_fields(&[("path", path)]),
)
}
pub fn eval_write_open_failed(display: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("failed to open {display} for writing");
Diagnostic::new(
"dsl.eval.write_open_failed",
message,
Diagnostic::make_fields(&[("path", display), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_write_stream_failed(display: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("failed to write to {display}");
Diagnostic::new(
"dsl.eval.write_stream_failed",
message,
Diagnostic::make_fields(&[("path", display), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_append_resolve_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_APPEND} {path}");
Diagnostic::new(
"dsl.eval.append_resolve_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_append_failed(display: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("failed to append to {display}");
Diagnostic::new(
"dsl.eval.append_failed",
message,
Diagnostic::make_fields(&[("path", display), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_append_needs_stdin(path: &str) -> Diagnostic {
let message = format!(
"{KEYWORD_APPEND} {path} requires stdin (use {KEYWORD_WITH_IO} [stdin=...] {KEYWORD_APPEND})"
);
Diagnostic::new(
"dsl.eval.append_needs_stdin",
message,
Diagnostic::make_fields(&[("path", path)]),
)
}
pub fn eval_append_open_failed(display: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("failed to open {display} for appending");
Diagnostic::new(
"dsl.eval.append_open_failed",
message,
Diagnostic::make_fields(&[("path", display), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_append_line_resolve_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_APPEND_LINE} {path}");
Diagnostic::new(
"dsl.eval.append_line_resolve_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_remove_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_REMOVE} {path}");
Diagnostic::new(
"dsl.eval.remove_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_remove_protected(path: &str) -> Diagnostic {
let message =
format!("{KEYWORD_REMOVE} {path}: cannot remove working directory or workspace root");
Diagnostic::new(
"dsl.eval.remove_protected",
message,
Diagnostic::make_fields(&[("path", path)]),
)
}
pub fn eval_remove_missing(path: &str) -> Diagnostic {
let message = format!("{KEYWORD_REMOVE} {path}: no such file or directory");
Diagnostic::new(
"dsl.eval.remove_missing",
message,
Diagnostic::make_fields(&[("path", path)]),
)
}
pub fn eval_remove_link_changed(path: &str) -> Diagnostic {
let message = format!("{KEYWORD_REMOVE} {path}: link changed during removal");
Diagnostic::new(
"dsl.eval.remove_link_changed",
message,
Diagnostic::make_fields(&[("path", path)]),
)
}
pub fn eval_remove_not_empty_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_REMOVE} {path}: directory not empty (use --recursive)");
Diagnostic::new(
"dsl.eval.remove_not_empty_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_expand_resolve_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_EXPAND} {path}");
Diagnostic::new(
"dsl.eval.expand_resolve_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_expand_read_failed(display: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("failed to read {display}");
Diagnostic::new(
"dsl.eval.expand_read_failed",
message,
Diagnostic::make_fields(&[("path", display), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_expand_write_failed(reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
Diagnostic::new(
"dsl.eval.expand_write_failed",
"failed to write output".to_string(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new(std::io::Error::new(
reason.kind(),
reason.to_string(),
)))
}
pub fn eval_expand_needs_stdin() -> Diagnostic {
let message = format!(
"{KEYWORD_EXPAND} requires stdin when no file path is given (use {KEYWORD_WITH_IO} [stdin=...] {KEYWORD_EXPAND})"
);
Diagnostic::new(
"dsl.eval.expand_needs_stdin",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn eval_install_failed(from: &str, to: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{KEYWORD_INSTALL} {from} {to}");
Diagnostic::new(
"dsl.eval.install_failed",
message,
Diagnostic::make_fields(&[("from", from), ("to", to), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new((*reason).clone()))
}
pub fn eval_prompt_no_answer(message: &str) -> Diagnostic {
let rendered =
format!("{KEYWORD_PROMPT} {message}: non-TTY stdin has no answer and no default");
Diagnostic::new(
"dsl.eval.prompt_no_answer",
rendered,
Diagnostic::make_fields(&[("message", message)]),
)
}
pub fn eval_prompt_write_failed(message: &str, reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let rendered = format!("{KEYWORD_PROMPT} {message}: failed to write prompt");
Diagnostic::new(
"dsl.eval.prompt_write_failed",
rendered,
Diagnostic::make_fields(&[("message", message), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new(std::io::Error::new(
reason.kind(),
reason.to_string(),
)))
}
pub fn eval_prompt_flush_failed(message: &str, reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let rendered = format!("{KEYWORD_PROMPT} {message}: failed to flush prompt");
Diagnostic::new(
"dsl.eval.prompt_flush_failed",
rendered,
Diagnostic::make_fields(&[("message", message), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new(std::io::Error::new(
reason.kind(),
reason.to_string(),
)))
}
pub fn eval_prompt_read_failed(message: &str, reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let rendered = format!("{KEYWORD_PROMPT} {message}: failed reading stdin");
Diagnostic::new(
"dsl.eval.prompt_read_failed",
rendered,
Diagnostic::make_fields(&[("message", message), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new(std::io::Error::new(
reason.kind(),
reason.to_string(),
)))
}
pub fn eval_prompt_eof(message: &str) -> Diagnostic {
let rendered = format!("{KEYWORD_PROMPT} {message}: EOF on stdin before any input");
Diagnostic::new(
"dsl.eval.prompt_eof",
rendered,
Diagnostic::make_fields(&[("message", message)]),
)
}
pub fn eval_prompt_bind_failed(var: &str, reason: Diagnostic) -> Diagnostic {
let reason_text = reason.to_string();
let message = format!("{KEYWORD_PROMPT} ${var}");
Diagnostic::new(
"dsl.eval.prompt_bind_failed",
message,
Diagnostic::make_fields(&[("var", var), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new(reason))
}
pub fn eval_list_append_failed(var: &str, reason: Diagnostic) -> Diagnostic {
let reason_text = reason.to_string();
let message = format!("{KEYWORD_LIST_APPEND} ${var}");
Diagnostic::new(
"dsl.eval.list_append_failed",
message,
Diagnostic::make_fields(&[("var", var), ("reason", &reason_text)]),
)
.with_source(std::sync::Arc::new(reason))
}
pub fn eval_int_arg_resolve(reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
Diagnostic::new(
"dsl.eval.int_arg_resolve",
reason_text.clone(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn eval_arg_expr_needs_step_ctx(expr: &Expr) -> Diagnostic {
let rendered = format!("{expr:?}");
let message = format!("Arg::Expr cannot be resolved without StepCtx: {rendered}");
Diagnostic::new(
"dsl.eval.arg_expr_needs_step_ctx",
message,
Diagnostic::make_fields(&[("expr", &rendered)]),
)
}
pub fn eval_arg_expand_failed(reason: Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
Diagnostic::new(
"dsl.eval.arg_expand_failed",
reason_text.clone(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn coerce_type_mismatch(ctx: &str, expected: &TypeTag, value: &super::Value) -> Diagnostic {
let expected_text = render_structural(expected);
let actual = value.type_name();
let message = format!("{ctx}: TypeMismatch: expected {expected_text}, got {actual}");
Diagnostic::new(
"dsl.coerce.type_mismatch",
message,
Diagnostic::make_fields(&[
("ctx", ctx),
("expected", &expected_text),
("actual", actual),
]),
)
}
pub fn coerce_string_to_pipe(s: &str) -> Diagnostic {
let message = format!(
"TypeMismatch: expected {PIPE_TYPE_NAME}, got {STRING_TYPE_NAME} ({s:?}); declare {KEYWORD_LET} $x: {PIPE_TYPE_NAME} and pass $x"
);
Diagnostic::new(
"dsl.coerce.string_to_pipe",
message,
Diagnostic::make_fields(&[("got", s)]),
)
}
pub fn coerce_pipe_to_string() -> Diagnostic {
let message = format!(
"coercion: TypeMismatch: expected {STRING_TYPE_NAME}, got {PIPE_TYPE_NAME}: pipes carry streams between steps, not text. Capture the producing step's output with {KEYWORD_LET} $var: {STRING_TYPE_NAME} = ... instead."
);
Diagnostic::new(
"dsl.coerce.pipe_to_string",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn coerce_check_failed(reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
Diagnostic::new(
"dsl.coerce.check_failed",
reason_text.clone(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn eval_host_return_failed(reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
Diagnostic::new(
"dsl.eval.host_return_failed",
reason_text.clone(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn eval_scope_underflow() -> Diagnostic {
Diagnostic::new(
"dsl.eval.scope_underflow",
"scope stack underflow during pop".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_redeclare_var(key: &str) -> Diagnostic {
let message = format!(
"redeclaration error: ${key} already declared in this scope; use ${key} = ... to mutate"
);
Diagnostic::new(
"dsl.eval.redeclare_var",
message,
Diagnostic::make_fields(&[("key", key)]),
)
}
pub fn eval_redeclare_const(key: &str) -> Diagnostic {
let message = format!(
"redeclaration error: {key} already declared in this scope; {} bindings are immutable and cannot redeclare it",
oxdock_parser::constants::KEYWORD_CONST,
);
Diagnostic::new(
"dsl.eval.redeclare_const",
message,
Diagnostic::make_fields(&[("key", key)]),
)
}
pub fn eval_no_var_scope() -> Diagnostic {
Diagnostic::new(
"dsl.eval.no_var_scope",
"no variable scope for declaration".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_const_mutation(what: &str) -> Diagnostic {
let message = format!(
"cannot mutate {} {what}: {} bindings are deeply immutable",
oxdock_parser::constants::KEYWORD_CONST,
oxdock_parser::constants::KEYWORD_CONST,
);
Diagnostic::new(
"dsl.eval.const_mutation",
message,
Diagnostic::make_fields(&[("what", what)]),
)
}
pub fn eval_undeclared_declare(key: &str, expected: &str) -> Diagnostic {
let message = format!(
"undeclared variable ${key}: declare it first with {KEYWORD_LET} ${key}: {expected} = ..."
);
Diagnostic::new(
"dsl.eval.undeclared_declare",
message,
Diagnostic::make_fields(&[("key", key), ("expected", expected)]),
)
}
pub fn eval_undeclared(key: &str) -> Diagnostic {
let message = format!("undeclared variable ${key}");
Diagnostic::new(
"dsl.eval.undeclared",
message,
Diagnostic::make_fields(&[("key", key)]),
)
}
pub fn eval_list_not_list(key: &str, actual: &str) -> Diagnostic {
let message =
format!("{KEYWORD_LIST_APPEND} ${key}: variable is {actual}, not {LIST_TYPE_NAME}");
Diagnostic::new(
"dsl.eval.list_not_list",
message,
Diagnostic::make_fields(&[("key", key), ("actual", actual)]),
)
}
pub fn eval_list_value_not_list(key: &str) -> Diagnostic {
let message = format!("{KEYWORD_LIST_APPEND} ${key}: variable is not a {LIST_TYPE_NAME} value");
Diagnostic::new(
"dsl.eval.list_value_not_list",
message,
Diagnostic::make_fields(&[("key", key)]),
)
}
pub fn eval_list_element_failed(reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
Diagnostic::new(
"dsl.eval.list_element_failed",
reason_text.clone(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn eval_const_arg_keypath() -> Diagnostic {
let message = qualified_keypath_error();
Diagnostic::new(
"dsl.eval.const_arg_keypath",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn eval_const_arg_bare_sigil(src: &str) -> Diagnostic {
let message = bare_sigil_error(src);
Diagnostic::new(
"dsl.eval.const_arg_bare_sigil",
message,
Diagnostic::make_fields(&[("src", src)]),
)
}
pub fn eval_template_missing_key(key: &str, env_hint: bool) -> Diagnostic {
let suggestion = if env_hint {
format!("env:{key}")
} else {
format!("${key}")
};
let message = if env_hint {
format!(
"undefined script variable: '{key}'; did you mean 'env:{key}' (environment variable)?"
)
} else {
format!("undefined script variable: '{key}'; did you mean '${key}'?")
};
Diagnostic::new(
"dsl.eval.template_missing_key",
message,
Diagnostic::make_fields(&[("key", key), ("suggestion", &suggestion)]),
)
}
pub fn eval_template_empty_placeholder() -> Diagnostic {
Diagnostic::new(
"dsl.eval.template_empty_placeholder",
"empty template placeholder".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_template_invalid_key(rest: &str) -> Diagnostic {
let message = format!("invalid placeholder key: '${rest}'");
Diagnostic::new(
"dsl.eval.template_invalid_key",
message,
Diagnostic::make_fields(&[("key", rest)]),
)
}
pub fn eval_template_empty_env() -> Diagnostic {
Diagnostic::new(
"dsl.eval.template_empty_env",
"undefined environment variable: ''".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_template_keypath() -> Diagnostic {
let message = qualified_keypath_error();
Diagnostic::new(
"dsl.eval.template_keypath",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn eval_template_bare_sigil(src: &str) -> Diagnostic {
let message = bare_sigil_error(src);
Diagnostic::new(
"dsl.eval.template_bare_sigil",
message,
Diagnostic::make_fields(&[("src", src)]),
)
}
pub fn eval_template_placeholder_miss(text: &str) -> Diagnostic {
Diagnostic::new(
"dsl.eval.template_placeholder_miss",
text.to_string(),
Diagnostic::make_fields(&[("reason", text)]),
)
}
pub fn std_pipe_read_failed(func: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("{func} cannot read {PIPE_TYPE_NAME} input: {reason_text}");
Diagnostic::new(
"dsl.std.pipe_read_failed",
message,
Diagnostic::make_fields(&[("func", func), ("reason", &reason_text)]),
)
}
pub fn std_pipe_create_failed(func: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("{func} cannot create {PIPE_TYPE_NAME} output: {reason_text}");
Diagnostic::new(
"dsl.std.pipe_create_failed",
message,
Diagnostic::make_fields(&[("func", func), ("reason", &reason_text)]),
)
}
pub fn std_pipe_spawn_failed(func: &str, reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("{func} cannot spawn pump thread: {reason_text}");
Diagnostic::new(
"dsl.std.pipe_spawn_failed",
message,
Diagnostic::make_fields(&[("func", func), ("reason", &reason_text)]),
)
}
pub fn std_pipe_reader_lock_poisoned(func: &str) -> Diagnostic {
let message = format!("{func} pipe reader lock poisoned");
Diagnostic::new(
"dsl.std.pipe_reader_lock_poisoned",
message,
Diagnostic::make_fields(&[("func", func)]),
)
}
pub fn std_pipe_writer_lock_poisoned(func: &str) -> Diagnostic {
let message = format!("{func} pipe writer lock poisoned");
Diagnostic::new(
"dsl.std.pipe_writer_lock_poisoned",
message,
Diagnostic::make_fields(&[("func", func)]),
)
}
pub fn std_pump_not_utf8() -> Diagnostic {
Diagnostic::new(
"dsl.std.pump_not_utf8",
"text pump input is not valid UTF-8".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn std_pump_writer_lock_poisoned() -> Diagnostic {
Diagnostic::new(
"dsl.std.pump_writer_lock_poisoned",
"text pump writer lock poisoned".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn std_pump_write_failed(reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("text pump write failed: {reason_text}");
Diagnostic::new(
"dsl.std.pump_write_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_pump_downstream_closed() -> Diagnostic {
Diagnostic::new(
KEY_STD_PUMP_DOWNSTREAM_CLOSED,
"text pump downstream closed its read end".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn std_pump_spill_drain_failed(reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("text pump spill drain failed: {reason_text}");
Diagnostic::new(
"dsl.std.pump_spill_drain_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_pump_spill_failed(reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("text pump spill failed: {reason_text}");
Diagnostic::new(
"dsl.std.pump_spill_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_pipe_handle_spent() -> Diagnostic {
Diagnostic::new(
"dsl.std.pipe_handle_spent",
format!(
"OS pipe handle has already been consumed by another binding; declare a fresh {KEYWORD_LET} $x: {PIPE_TYPE_NAME} for a new session"
),
Diagnostic::make_fields(&[]),
)
}
pub fn std_pipe_needs_pipe(func: &str, actual: &str) -> Diagnostic {
let message = format!("host {func} needs a {PIPE_TYPE_NAME} value, got {actual}");
Diagnostic::new(
"dsl.std.pipe_needs_pipe",
message,
Diagnostic::make_fields(&[("func", func), ("actual", actual)]),
)
}
pub fn std_pipe_close_needs_script() -> Diagnostic {
Diagnostic::new(
"dsl.std.pipe_close_needs_script",
"host close_pipe needs a script-materialized pipe (unbound and OS handles cannot be force-closed)".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn std_assert_lock_poisoned(lock: &str) -> Diagnostic {
let message = format!("{lock} poisoned");
Diagnostic::new(
"dsl.std.assert_lock_poisoned",
message,
Diagnostic::make_fields(&[("lock", lock)]),
)
}
pub fn std_pipe_chunk_read_failed(func: &str, reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("{func} cannot read {PIPE_TYPE_NAME} input: {reason_text}");
Diagnostic::new(
"dsl.std.pipe_chunk_read_failed",
message,
Diagnostic::make_fields(&[("func", func), ("reason", &reason_text)]),
)
}
pub fn std_pipe_input_not_utf8(func: &str) -> Diagnostic {
let message = format!("{func} {PIPE_TYPE_NAME} input is not valid UTF-8");
Diagnostic::new(
"dsl.std.pipe_input_not_utf8",
message,
Diagnostic::make_fields(&[("func", func)]),
)
}
pub fn std_pipe_spill_failed(func: &str, reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("{func} {PIPE_TYPE_NAME} input exceeds the spill backlog: {reason_text}");
Diagnostic::new(
"dsl.std.pipe_spill_failed",
message,
Diagnostic::make_fields(&[("func", func), ("reason", &reason_text)]),
)
}
pub fn std_pipe_write_failed(func: &str, reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("{func} cannot write {PIPE_TYPE_NAME} output: {reason_text}");
Diagnostic::new(
"dsl.std.pipe_write_failed",
message,
Diagnostic::make_fields(&[("func", func), ("reason", &reason_text)]),
)
}
pub fn eval_compare_equality_shape() -> Diagnostic {
Diagnostic::new(
"dsl.eval.compare_equality_shape",
"internal error: equality shape".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_ordering_needs_numeric(left: &super::Value, right: &super::Value) -> Diagnostic {
let message = format!(
"Type Error: ordering comparison requires Int or Float, found {left:?} and {right:?}"
);
Diagnostic::new(
"dsl.eval.ordering_needs_numeric",
message,
Diagnostic::make_fields(&[
("left", &format!("{left:?}")),
("right", &format!("{right:?}")),
]),
)
}
pub fn eval_unstaged_int_boundary(n: u64) -> Diagnostic {
let message = format!("internal error: unstaged integer boundary {n}");
Diagnostic::new(
"dsl.eval.unstaged_int_boundary",
message,
Diagnostic::make_fields(&[("got", &n.to_string())]),
)
}
pub fn eval_undefined_var(name: &str) -> Diagnostic {
let message = format!("undefined variable ${name}");
Diagnostic::new(
"dsl.eval.undefined_var",
message,
Diagnostic::make_fields(&[("name", name)]),
)
}
pub fn eval_key_not_found(key: &str) -> Diagnostic {
let message = format!("Key '{key}' not found in map");
Diagnostic::new(
"dsl.eval.key_not_found",
message,
Diagnostic::make_fields(&[("key", key)]),
)
}
pub fn eval_invalid_array_index(key: &str) -> Diagnostic {
let message = format!("Invalid array index '{key}'");
Diagnostic::new(
"dsl.eval.invalid_array_index",
message,
Diagnostic::make_fields(&[("key", key)]),
)
}
pub fn eval_index_out_of_bounds(idx: usize) -> Diagnostic {
let message = format!("Index {idx} out of bounds");
Diagnostic::new(
"dsl.eval.index_out_of_bounds",
message,
Diagnostic::make_fields(&[("index", &idx.to_string())]),
)
}
pub fn eval_traverse_scalar(key: &str) -> Diagnostic {
let message = format!("Cannot traverse into scalar value at key '{key}'");
Diagnostic::new(
"dsl.eval.traverse_scalar",
message,
Diagnostic::make_fields(&[("key", key)]),
)
}
pub fn eval_path_type_needs_arg() -> Diagnostic {
Diagnostic::new(
"dsl.eval.path_type_needs_arg",
format!("{FUNC_PATH_TYPE} requires a path argument"),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_path_type_needs_string() -> Diagnostic {
Diagnostic::new(
"dsl.eval.path_type_needs_string",
format!("{FUNC_PATH_TYPE} path argument must evaluate to a string"),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_is_exec_needs_arg() -> Diagnostic {
Diagnostic::new(
"dsl.eval.is_exec_needs_arg",
format!("{FUNC_IS_EXEC} requires a name argument"),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_is_exec_needs_string() -> Diagnostic {
Diagnostic::new(
"dsl.eval.is_exec_needs_string",
format!("{FUNC_IS_EXEC} name argument must evaluate to a string"),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_path_writable_needs_arg() -> Diagnostic {
Diagnostic::new(
"dsl.eval.path_writable_needs_arg",
format!("{FUNC_PATH_WRITABLE} requires a path argument"),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_path_writable_needs_string() -> Diagnostic {
Diagnostic::new(
"dsl.eval.path_writable_needs_string",
format!("{FUNC_PATH_WRITABLE} path argument must evaluate to a string"),
Diagnostic::make_fields(&[]),
)
}
pub fn eval_path_resolve_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("failed to resolve path '{path}': {reason_text}");
Diagnostic::new(
"dsl.eval.path_resolve_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
}
pub fn eval_workdir_resolve_failed(reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("failed to resolve working directory: {reason_text}");
Diagnostic::new(
"dsl.eval.workdir_resolve_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn eval_scratch_materialize_failed(reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
Diagnostic::new(
"dsl.eval.scratch_materialize_failed",
reason_text.clone(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn eval_task_cap_exceeded(max: u64) -> Diagnostic {
let message =
format!("concurrency limit exceeded: maximum of {max} running background tasks allowed");
Diagnostic::new(
"dsl.eval.task_cap_exceeded",
message,
Diagnostic::make_fields(&[("max", &max.to_string())]),
)
}
pub fn std_format_byte_count_negative(bytes: i64) -> Diagnostic {
let message = format!("{FUNC_FORMAT_BYTE_COUNT} needs a non-negative byte count, got {bytes}");
Diagnostic::new(
"dsl.std.format_byte_count_negative",
message,
Diagnostic::make_fields(&[("got", &bytes.to_string())]),
)
}
pub fn std_format_duration_negative(millis: i64) -> Diagnostic {
let message = format!("{FUNC_FORMAT_DURATION} needs non-negative milliseconds, got {millis}");
Diagnostic::new(
"dsl.std.format_duration_negative",
message,
Diagnostic::make_fields(&[("got", &millis.to_string())]),
)
}
pub fn std_parse_duration_range(text: &str) -> Diagnostic {
let message = format!("{FUNC_PARSE_DURATION} out of {INT_TYPE_NAME} range: {text:?}");
Diagnostic::new(
"dsl.std.parse_duration_range",
message,
Diagnostic::make_fields(&[("got", text)]),
)
}
pub fn std_to_json_non_finite_float(f: f64) -> Diagnostic {
let message = format!("{FUNC_TO_JSON} cannot encode non-finite float {f}");
Diagnostic::new(
"dsl.std.to_json_non_finite_float",
message,
Diagnostic::make_fields(&[("got", &f.to_string())]),
)
}
pub fn std_to_json_unencodable(actual: &str) -> Diagnostic {
let message = format!(
"{FUNC_TO_JSON} cannot encode {actual} values; use {STRING_TYPE_NAME}, {INT_TYPE_NAME}, {FLOAT_TYPE_NAME}, {BOOL_TYPE_NAME}, {LIST_TYPE_NAME}, or {MAP_TYPE_NAME}"
);
Diagnostic::new(
"dsl.std.to_json_unencodable",
message,
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn std_to_json_encode_failed(reason: &serde_json::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("encode JSON: {reason_text}");
Diagnostic::new(
"dsl.std.to_json_encode_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_base64_encode_needs_string(actual: &str) -> Diagnostic {
let message = format!("{FUNC_BASE64_ENCODE} expects a {STRING_TYPE_NAME}, got {actual}");
Diagnostic::new(
"dsl.std.base64_encode_needs_string",
message,
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn std_base64_decode_needs_string(actual: &str) -> Diagnostic {
let message = format!("{FUNC_BASE64_DECODE} expects a {STRING_TYPE_NAME}, got {actual}");
Diagnostic::new(
"dsl.std.base64_decode_needs_string",
message,
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn std_base64_decode_failed(input: &str, reason: &base64::DecodeError) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("{FUNC_BASE64_DECODE} cannot decode {input:?}: {reason_text}");
Diagnostic::new(
"dsl.std.base64_decode_failed",
message,
Diagnostic::make_fields(&[("input", input), ("reason", &reason_text)]),
)
}
pub fn std_base64_decode_not_utf8() -> Diagnostic {
Diagnostic::new(
"dsl.std.base64_decode_not_utf8",
format!("{FUNC_BASE64_DECODE} decoded bytes are not UTF-8"),
Diagnostic::make_fields(&[]),
)
}
pub fn std_load_toml_needs_arg() -> Diagnostic {
Diagnostic::new(
"dsl.std.load_toml_needs_arg",
format!("{FUNC_LOAD_TOML} requires a path argument"),
Diagnostic::make_fields(&[]),
)
}
pub fn std_load_toml_needs_string() -> Diagnostic {
Diagnostic::new(
"dsl.std.load_toml_needs_string",
format!("{FUNC_LOAD_TOML} path argument must evaluate to a string"),
Diagnostic::make_fields(&[]),
)
}
pub fn std_load_toml_resolve_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("failed to resolve TOML path '{path}': {reason_text}");
Diagnostic::new(
"dsl.std.load_toml_resolve_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
}
pub fn std_load_toml_read_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("failed to read TOML file '{path}': {reason_text}");
Diagnostic::new(
"dsl.std.load_toml_read_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
}
pub fn std_load_toml_not_utf8(path: &str, reason: &std::str::Utf8Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("invalid UTF-8 in TOML file '{path}': {reason_text}");
Diagnostic::new(
"dsl.std.load_toml_not_utf8",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
}
pub fn std_toml_parse_failed(reason: &toml::de::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("TOML parse error: {reason_text}");
Diagnostic::new(
"dsl.std.toml_parse_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_parse_toml_needs_string(actual: &str) -> Diagnostic {
let message = format!("{FUNC_PARSE_TOML} expects a {STRING_TYPE_NAME}, got {actual}");
Diagnostic::new(
"dsl.std.parse_toml_needs_string",
message,
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn std_load_json_needs_arg() -> Diagnostic {
Diagnostic::new(
"dsl.std.load_json_needs_arg",
format!("{FUNC_LOAD_JSON} requires a path argument"),
Diagnostic::make_fields(&[]),
)
}
pub fn std_load_json_needs_string() -> Diagnostic {
Diagnostic::new(
"dsl.std.load_json_needs_string",
format!("{FUNC_LOAD_JSON} path argument must evaluate to a string"),
Diagnostic::make_fields(&[]),
)
}
pub fn std_load_json_resolve_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("failed to resolve JSON path '{path}': {reason_text}");
Diagnostic::new(
"dsl.std.load_json_resolve_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
}
pub fn std_load_json_read_failed(path: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
let message = format!("failed to read JSON file '{path}': {reason_text}");
Diagnostic::new(
"dsl.std.load_json_read_failed",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
}
pub fn std_load_json_not_utf8(path: &str, reason: &std::str::Utf8Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("invalid UTF-8 in JSON file '{path}': {reason_text}");
Diagnostic::new(
"dsl.std.load_json_not_utf8",
message,
Diagnostic::make_fields(&[("path", path), ("reason", &reason_text)]),
)
}
pub fn std_json_parse_failed(reason: &serde_json::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("JSON parse error: {reason_text}");
Diagnostic::new(
"dsl.std.json_parse_failed",
message,
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_parse_json_needs_string(actual: &str) -> Diagnostic {
let message = format!("{FUNC_PARSE_JSON} expects a {STRING_TYPE_NAME}, got {actual}");
Diagnostic::new(
"dsl.std.parse_json_needs_string",
message,
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn std_glob_needs_arg() -> Diagnostic {
Diagnostic::new(
"dsl.std.glob_needs_arg",
format!("{FUNC_GLOB} requires a pattern argument"),
Diagnostic::make_fields(&[]),
)
}
pub fn std_glob_needs_string() -> Diagnostic {
Diagnostic::new(
"dsl.std.glob_needs_string",
format!("{FUNC_GLOB} pattern argument must evaluate to a string"),
Diagnostic::make_fields(&[]),
)
}
pub fn std_glob_resolve_failed(reason: &Diagnostic) -> Diagnostic {
let reason_text = flatten_chain(reason);
Diagnostic::new(
"dsl.std.glob_resolve_failed",
reason_text.clone(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_glob_list_failed(reason: &std::io::Error) -> Diagnostic {
let reason_text = format!("{reason}");
Diagnostic::new(
"dsl.std.glob_list_failed",
reason_text.clone(),
Diagnostic::make_fields(&[("reason", &reason_text)]),
)
}
pub fn std_has_key_needs_map(actual: &str) -> Diagnostic {
let message = format!(
"{FUNC_HAS_KEY} expects a {} as its first argument, got {actual}",
MAP_TYPE_NAME
);
Diagnostic::new(
"dsl.std.has_key_needs_map",
message,
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn std_map_set_needs_map(actual: &str) -> Diagnostic {
let message = format!(
"{FUNC_MAP_SET} expects a {} as its first argument, got {actual}",
MAP_TYPE_NAME
);
Diagnostic::new(
"dsl.std.map_set_needs_map",
message,
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn std_map_set_duplicate(key: &str) -> Diagnostic {
let message = format!("{FUNC_MAP_SET} duplicate key '{key}'");
Diagnostic::new(
"dsl.std.map_set_duplicate",
message,
Diagnostic::make_fields(&[("key", key)]),
)
}
pub fn std_merge_maps_needs_list(actual: &str) -> Diagnostic {
let message = format!(
"{FUNC_MERGE_MAPS} expects a {} of {}s, got {actual}",
LIST_TYPE_NAME, MAP_TYPE_NAME
);
Diagnostic::new(
"dsl.std.merge_maps_needs_list",
message,
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn std_merge_maps_needs_map(index: usize, actual: &str) -> Diagnostic {
let message = format!("{FUNC_MERGE_MAPS} element {index} is {actual}, not {MAP_TYPE_NAME}");
Diagnostic::new(
"dsl.std.merge_maps_needs_map",
message,
Diagnostic::make_fields(&[("index", &index.to_string()), ("actual", actual)]),
)
}
pub fn std_merge_maps_duplicate(key: &str) -> Diagnostic {
let message = format!(
"duplicate values key '{key}'; later files must not repeat it under fail_on_duplicate"
);
Diagnostic::new(
"dsl.std.merge_maps_duplicate",
message,
Diagnostic::make_fields(&[("key", key)]),
)
}
pub fn std_text_invalid_pattern(func: &str, pattern: &str, reason: ®ex::Error) -> Diagnostic {
let reason_text = format!("{reason}");
let message = format!("{func} invalid pattern {pattern:?}: {reason_text}");
Diagnostic::new(
"dsl.std.text_invalid_pattern",
message,
Diagnostic::make_fields(&[
("func", func),
("pattern", pattern),
("reason", &reason_text),
]),
)
}
pub fn std_text_needs_search(func: &str) -> Diagnostic {
let message = format!("{func} needs a non-empty search string");
Diagnostic::new(
"dsl.std.text_needs_search",
message,
Diagnostic::make_fields(&[("func", func)]),
)
}
pub fn std_text_needs_needle(func: &str) -> Diagnostic {
let message = format!("{func} needs a non-empty needle");
Diagnostic::new(
"dsl.std.text_needs_needle",
message,
Diagnostic::make_fields(&[("func", func)]),
)
}
pub fn std_text_needs_one_based_start(func: &str, from: i64) -> Diagnostic {
let message = format!("{func} needs a 1-based start line, got {from}");
Diagnostic::new(
"dsl.std.text_needs_one_based_start",
message,
Diagnostic::make_fields(&[("func", func), ("from", &from.to_string())]),
)
}
pub fn std_text_needs_ordered_range(func: &str, from: i64, to: i64) -> Diagnostic {
let message = format!("{func} needs start <= end, got {from}..={to}");
Diagnostic::new(
"dsl.std.text_needs_ordered_range",
message,
Diagnostic::make_fields(&[
("func", func),
("from", &from.to_string()),
("to", &to.to_string()),
]),
)
}
pub fn std_pipe_needs_step_io(func: &str) -> Diagnostic {
let message = format!(
"{func} on {PIPE_TYPE_NAME} input needs step IO, unavailable to placeholder calls; pass a {STRING_TYPE_NAME} there"
);
Diagnostic::new(
"dsl.std.pipe_needs_step_io",
message,
Diagnostic::make_fields(&[("func", func)]),
)
}
pub fn json_handle_needs_object(other: &serde_json::Value) -> Diagnostic {
let message = format!(
"{HANDLE_TYPE_NAME} argument must be an object like {{\"task_id\": 7}}, got {other}"
);
Diagnostic::new(
"dsl.json.handle_needs_object",
message,
Diagnostic::make_fields(&[("got", &other.to_string())]),
)
}
pub fn json_handle_exact_shape() -> Diagnostic {
Diagnostic::new(
"dsl.json.handle_exact_shape",
format!(
"{HANDLE_TYPE_NAME} argument must be exactly {{\"task_id\": N}} with no other keys"
),
Diagnostic::make_fields(&[]),
)
}
pub fn json_handle_task_id_positive() -> Diagnostic {
Diagnostic::new(
"dsl.json.handle_task_id_positive",
format!("{HANDLE_TYPE_NAME} argument `task_id` must be a positive integer"),
Diagnostic::make_fields(&[]),
)
}
pub fn json_handle_encode_needs_handle(actual: &str) -> Diagnostic {
let message = format!("cannot encode {actual} as {HANDLE_TYPE_NAME}; expected a task handle");
Diagnostic::new(
"dsl.json.handle_encode_needs_handle",
message,
Diagnostic::make_fields(&[("actual", actual)]),
)
}
pub fn import_not_in_closure(path: &str) -> Diagnostic {
let message = format!("{KEYWORD_IMPORT} `{path}` cannot be read: not in the import closure");
Diagnostic::new(
"dsl.import.not_in_closure",
message,
Diagnostic::make_fields(&[("path", path)]),
)
}
pub fn import_export_type_mismatch(path: &str, name: &str) -> Diagnostic {
let message = format!(
"{KEYWORD_IMPORT} `{path}` {KEYWORD_EXPORT} {KEYWORD_TYPE} `{name}` does not match any top-level {KEYWORD_TYPE} in that file"
);
Diagnostic::new(
"dsl.import.export_type_mismatch",
message,
Diagnostic::make_fields(&[("path", path), ("name", name)]),
)
}
pub fn check_var_tag(var: &str, reason: Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("variable `${var}`: {reason_text}");
Diagnostic::new(
"dsl.check.var_tag",
message,
Diagnostic::make_fields(&[("var", var), ("reason", &reason_text)]),
)
}
pub fn check_func_tag(name: &str, reason: Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("function `{name}`: {reason_text}");
Diagnostic::new(
"dsl.check.func_tag",
message,
Diagnostic::make_fields(&[("function", name), ("reason", &reason_text)]),
)
}
pub fn check_step_wrap(step: usize, reason: Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("step {step}: {reason_text}");
Diagnostic::new(
"dsl.check.step_wrap",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("reason", &reason_text)]),
)
}
pub fn check_ctx_wrap(ctx: &str, reason: &Diagnostic) -> Diagnostic {
let reason_text = format!("{reason:#}");
let message = format!("{ctx}: {reason_text}");
Diagnostic::new(
"dsl.check.ctx_wrap",
message,
Diagnostic::make_fields(&[("ctx", ctx), ("reason", &reason_text)]),
)
}
pub fn check_exact_mismatch(ctx: &str, expected: &TypeTag, actual: &TypeTag) -> Diagnostic {
let exp = render_structural(expected);
let act = render_structural(actual);
let message = format!("{ctx}: TypeMismatch: expected `{exp}`, got `{act}`");
Diagnostic::new(
"dsl.check.exact_mismatch",
message,
Diagnostic::make_fields(&[("ctx", ctx), ("expected", &exp), ("actual", &act)]),
)
}
pub fn check_cannot_unify(ctx: &str, left: &TypeTag, right: &TypeTag) -> Diagnostic {
let l = render_structural(left);
let r = render_structural(right);
let message = format!("{ctx}: cannot unify `{l}` and `{r}`");
Diagnostic::new(
"dsl.check.cannot_unify",
message,
Diagnostic::make_fields(&[("ctx", ctx), ("left", &l), ("right", &r)]),
)
}
pub fn check_undefined_var(prefix: &str, key: &str) -> Diagnostic {
let message = format!("{prefix}undefined variable `${key}`");
Diagnostic::new(
"dsl.check.undefined_var",
message,
Diagnostic::make_fields(&[("prefix", prefix), ("key", key)]),
)
}
pub fn check_var_not_guaranteed(key: &str) -> Diagnostic {
let message = format!(
"variable `${key}` is not guaranteed to be defined on all reachable paths for this step"
);
Diagnostic::new(
"dsl.check.var_not_guaranteed",
message,
Diagnostic::make_fields(&[("key", key)]),
)
}
pub fn check_unknown_field(prefix: &str, part: &str, fields: &[Field]) -> Diagnostic {
let expected = fields
.iter()
.map(|f| f.name.as_str())
.collect::<Vec<_>>()
.join(", ");
let message = format!("{prefix}unknown field `{part}`; expected fields: {expected}");
Diagnostic::new(
"dsl.check.unknown_field",
message,
Diagnostic::make_fields(&[("prefix", prefix), ("part", part), ("expected", &expected)]),
)
}
pub fn check_invalid_array_index(prefix: &str, part: &str) -> Diagnostic {
let message = format!("{prefix}invalid array index `{part}`");
Diagnostic::new(
"dsl.check.invalid_array_index",
message,
Diagnostic::make_fields(&[("prefix", prefix), ("part", part)]),
)
}
pub fn check_cannot_traverse(prefix: &str, part: &str) -> Diagnostic {
let message = format!("{prefix}cannot traverse into scalar value at key `{part}`");
Diagnostic::new(
"dsl.check.cannot_traverse",
message,
Diagnostic::make_fields(&[("prefix", prefix), ("part", part)]),
)
}
pub fn check_duplicate_func(key: &str, display: &str) -> Diagnostic {
let message = format!("duplicate function `{key}` from `{display}` collides across imports");
Diagnostic::new(
"dsl.check.duplicate_func",
message,
Diagnostic::make_fields(&[("key", key), ("display", display)]),
)
}
pub fn check_redeclare_const(step: usize, key: &str) -> Diagnostic {
let message = format!(
"step {step}: redeclaration error: `{key}` is a {KEYWORD_CONST} binding and cannot be redeclared; {KEYWORD_CONST} and {KEYWORD_LET} share one namespace"
);
Diagnostic::new(
"dsl.check.redeclare_const",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("key", key)]),
)
}
pub fn check_redeclare_let(step: usize, key: &str) -> Diagnostic {
let message = format!(
"step {step}: redeclaration error: `${key}` already declared in this scope; use `${key}` = ... to mutate"
);
Diagnostic::new(
"dsl.check.redeclare_let",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("key", key)]),
)
}
pub fn check_undeclared_env(pos: &str, label: &str, prefix: &str, name: &str) -> Diagnostic {
let message = format!(
"{pos} in {label}: uses undeclared environment variable `{prefix}{name}`: declare it first with {KEYWORD_ENV} or {KEYWORD_INHERIT_ENV}"
);
Diagnostic::new(
"dsl.check.undeclared_env",
message,
Diagnostic::make_fields(&[
("pos", pos),
("scope", label),
("prefix", prefix),
("name", name),
]),
)
}
pub fn check_placeholder_keypath() -> Diagnostic {
let message = oxdock_parser::template::qualified_keypath_error();
Diagnostic::new(
"dsl.check.placeholder_keypath",
message,
Diagnostic::make_fields(&[]),
)
}
pub fn check_empty_placeholder_var() -> Diagnostic {
Diagnostic::new(
"dsl.check.empty_placeholder_var",
"invalid placeholder variable: empty variable reference".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn check_bare_sigil(src: &str) -> Diagnostic {
let message = oxdock_parser::template::bare_sigil_error(src);
Diagnostic::new(
"dsl.check.bare_sigil",
message,
Diagnostic::make_fields(&[("src", src)]),
)
}
pub fn check_undefined_script_var(key: &str) -> Diagnostic {
let message = format!("undefined script variable: `{key}`");
Diagnostic::new(
"dsl.check.undefined_script_var",
message,
Diagnostic::make_fields(&[("key", key)]),
)
}
pub fn check_placeholder_unknown(qualified: &str) -> Diagnostic {
let message = format!("unknown placeholder function `{qualified}`");
Diagnostic::new(
"dsl.check.placeholder_unknown",
message,
Diagnostic::make_fields(&[("name", qualified)]),
)
}
pub fn check_disjoint_alias_miss(
module: &str,
name: &str,
base: &str,
files: &std::collections::HashSet<String>,
has_host: bool,
is_script: &dyn Fn(&str) -> bool,
) -> Diagnostic {
let message = super::native::disjoint_alias_placeholder_miss(
module, name, base, files, has_host, is_script,
);
Diagnostic::new(
"dsl.check.disjoint_alias_miss",
message,
Diagnostic::make_fields(&[("alias", module), ("name", name), ("base", base)]),
)
}
pub fn check_placeholder_miss(
module: &str,
name: &str,
is_script: bool,
is_stateful: bool,
alias_known: bool,
) -> Option<Diagnostic> {
let text = super::native::describe_placeholder_miss(
module,
name,
is_script,
is_stateful,
alias_known,
)?;
Some(Diagnostic::new(
"dsl.check.placeholder_miss",
text,
Diagnostic::make_fields(&[("alias", module), ("name", name)]),
))
}
pub fn check_template_arity_exact(
pos: &str,
label: &str,
qualified: &str,
total: usize,
got: usize,
) -> Diagnostic {
let message = format!("{pos} in {label}: {qualified}() expects {total} argument(s), got {got}");
Diagnostic::new(
"dsl.check.template_arity_exact",
message,
Diagnostic::make_fields(&[
("pos", pos),
("scope", label),
("function", qualified),
("expected", &total.to_string()),
("got", &got.to_string()),
]),
)
}
pub fn check_template_arity_range(
pos: &str,
label: &str,
qualified: &str,
min: usize,
max: usize,
got: usize,
) -> Diagnostic {
let message =
format!("{pos} in {label}: {qualified}() expects {min} to {max} argument(s), got {got}");
Diagnostic::new(
"dsl.check.template_arity_range",
message,
Diagnostic::make_fields(&[
("pos", pos),
("scope", label),
("function", qualified),
("min", &min.to_string()),
("max", &max.to_string()),
("got", &got.to_string()),
]),
)
}
pub fn check_template_arg_allowed(
pos: &str,
label: &str,
qualified: &str,
param: &str,
allowed: &[&str],
got: &str,
) -> Diagnostic {
let joined = allowed.join(", ");
let message = format!(
"{pos} in {label}: {qualified}() argument `${param}` must be one of: {joined}, got {got:?}"
);
Diagnostic::new(
"dsl.check.template_arg_allowed",
message,
Diagnostic::make_fields(&[
("pos", pos),
("scope", label),
("function", qualified),
("param", param),
("allowed", &joined),
("got", got),
]),
)
}
pub fn check_template_arg_depth() -> Diagnostic {
let max = oxdock_parser::template::MAX_TEMPLATE_ARG_DEPTH;
let message = format!("placeholder call argument nests too deep (limit {max})");
Diagnostic::new(
"dsl.check.template_arg_depth",
message,
Diagnostic::make_fields(&[("max", &max.to_string())]),
)
}
pub fn check_empty_placeholder_arg() -> Diagnostic {
Diagnostic::new(
"dsl.check.empty_placeholder_arg",
"invalid placeholder call argument: empty variable reference".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn check_depth_function(key: &str) -> Diagnostic {
let message = format!("static analysis depth exceeded in function `{key}`");
Diagnostic::new(
"dsl.check.depth_function",
message,
Diagnostic::make_fields(&[("function", key)]),
)
}
pub fn check_depth_scope(label: &str) -> Diagnostic {
let message = format!("static analysis depth exceeded in `{label}`");
Diagnostic::new(
"dsl.check.depth_scope",
message,
Diagnostic::make_fields(&[("scope", label)]),
)
}
pub fn check_invalid_placeholder_arg(src: &str) -> Diagnostic {
let message = format!("invalid placeholder call argument `{src}`");
Diagnostic::new(
"dsl.check.invalid_placeholder_arg",
message,
Diagnostic::make_fields(&[("src", src)]),
)
}
pub fn check_invalid_map_entry(entry: &str) -> Diagnostic {
let message = format!("invalid map literal entry `{entry}`: use key: value");
Diagnostic::new(
"dsl.check.invalid_map_entry",
message,
Diagnostic::make_fields(&[("entry", entry)]),
)
}
pub fn check_duplicate_map_key(key: &str) -> Diagnostic {
let message = format!("duplicate key `{key}` in map literal");
Diagnostic::new(
"dsl.check.duplicate_map_key",
message,
Diagnostic::make_fields(&[("key", key)]),
)
}
pub fn check_void_block_bind(step: usize, var: &str) -> Diagnostic {
let message = format!("step {step}: {VOID_TYPE_NAME} block has no value to bind to `${var}`");
Diagnostic::new(
"dsl.check.void_block_bind",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("var", var)]),
)
}
pub fn check_capture_mismatch(
step: usize,
kw: &str,
var: &str,
yield_tag: &TypeTag,
tag: &TypeTag,
) -> Diagnostic {
let y = render_structural(yield_tag);
let t = render_structural(tag);
let message = format!("step {step}: {kw} `${var}` captures {y} but declares {t}");
Diagnostic::new(
"dsl.check.capture_mismatch",
message,
Diagnostic::make_fields(&[
(FIELD_STEP, &step.to_string()),
(FIELD_COMMAND, kw),
(FIELD_VAR, var),
(FIELD_YIELD, &y),
(FIELD_DECLARES, &t),
]),
)
}
pub fn check_await_not_handle(step: usize, task_var: &str, actual: &TypeTag) -> Diagnostic {
let a = render_structural(actual);
let message =
format!("step {step}: {KEYWORD_AWAIT} `${task_var}` is {a}, not {HANDLE_TYPE_NAME}");
Diagnostic::new(
"dsl.check.await_not_handle",
message,
Diagnostic::make_fields(&[
("step", &step.to_string()),
("task", task_var),
("actual", &a),
]),
)
}
pub fn check_await_void_payload(step: usize, task_var: &str, out_var: &str) -> Diagnostic {
let message = format!(
"step {step}: {KEYWORD_AWAIT} `${task_var}` is {HANDLE_TYPE_NAME}<{VOID_TYPE_NAME}>: no value to bind to `${out_var}`; use bare {KEYWORD_AWAIT} for join"
);
Diagnostic::new(
"dsl.check.await_void_payload",
message,
Diagnostic::make_fields(&[
("step", &step.to_string()),
("task", task_var),
("var", out_var),
]),
)
}
pub fn check_await_yield_mismatch(
step: usize,
task_var: &str,
payload: &TypeTag,
out_var: &str,
tag: &TypeTag,
) -> Diagnostic {
let p = render_structural(payload);
let t = render_structural(tag);
let message = format!(
"step {step}: {KEYWORD_AWAIT} `${task_var}` yields {p} but `${out_var}` declares {t}"
);
Diagnostic::new(
"dsl.check.await_yield_mismatch",
message,
Diagnostic::make_fields(&[
("step", &step.to_string()),
("task", task_var),
("yield", &p),
("var", out_var),
("declares", &t),
]),
)
}
pub fn check_async_not_handle(step: usize, var: &str, tag: &TypeTag) -> Diagnostic {
let t = render_structural(tag);
let message = format!(
"step {step}: {KEYWORD_ASYNC} `${var}` declares {t}, not {HANDLE_TYPE_NAME}; every {KEYWORD_ASYNC} position is {HANDLE_TYPE_NAME}-headed"
);
Diagnostic::new(
"dsl.check.async_not_handle",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("var", var), ("declares", &t)]),
)
}
pub fn check_async_bare_return(step: usize, var: &str, tag: &TypeTag) -> Diagnostic {
let t = render_structural(tag);
let message = format!(
"step {step}: {KEYWORD_ASYNC} `${var}` declares {t} but task has a bare {KEYWORD_RETURN}; bare {KEYWORD_RETURN} is only a void exit"
);
Diagnostic::new(
"dsl.check.async_bare_return",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("var", var), ("declares", &t)]),
)
}
pub fn check_async_void_yield(step: usize, line: usize, ty: &TypeTag) -> Diagnostic {
let t = render_structural(ty);
let message = format!(
"step {step}: {HANDLE_TYPE_NAME}<{VOID_TYPE_NAME}> task {KEYWORD_RETURN} at line {line} yields {t}"
);
Diagnostic::new(
"dsl.check.async_void_yield",
message,
Diagnostic::make_fields(&[
("step", &step.to_string()),
("line", &line.to_string()),
("yield", &t),
]),
)
}
pub fn check_async_no_return(step: usize, var: &str, tag: &TypeTag) -> Diagnostic {
let t = render_structural(tag);
let message = format!(
"step {step}: {KEYWORD_ASYNC} `${var}` declares {t} but task has no value {KEYWORD_RETURN}"
);
Diagnostic::new(
"dsl.check.async_no_return",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("var", var), ("declares", &t)]),
)
}
pub fn check_async_return_mismatch(
step: usize,
var: &str,
tag: &TypeTag,
line: usize,
ty: &TypeTag,
) -> Diagnostic {
let t = render_structural(tag);
let y = render_structural(ty);
let message = format!(
"step {step}: {KEYWORD_ASYNC} `${var}` declares {t} but task {KEYWORD_RETURN} at line {line} yields {y}"
);
Diagnostic::new(
"dsl.check.async_return_mismatch",
message,
Diagnostic::make_fields(&[
("step", &step.to_string()),
("var", var),
("declares", &t),
("line", &line.to_string()),
("yield", &y),
]),
)
}
pub fn check_return_outside(step: usize) -> Diagnostic {
let message = format!(
"step {step}: {KEYWORD_RETURN} outside function, {KEYWORD_ASYNC} task, or {KEYWORD_LET} block"
);
Diagnostic::new(
"dsl.check.return_outside",
message,
Diagnostic::make_fields(&[("step", &step.to_string())]),
)
}
pub fn check_return_crosses_async(step: usize) -> Diagnostic {
let message = format!("step {step}: {KEYWORD_RETURN} cannot cross {KEYWORD_ASYNC} boundary");
Diagnostic::new(
"dsl.check.return_crosses_async",
message,
Diagnostic::make_fields(&[("step", &step.to_string())]),
)
}
pub fn check_undeclared_set(step: usize, key: &str) -> Diagnostic {
let message = format!(
"step {step}: undeclared variable `${key}`: declare it first with {KEYWORD_LET} `${key}`: {KEYWORD_TYPE} = ..."
);
Diagnostic::new(
"dsl.check.undeclared_set",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("key", key)]),
)
}
pub fn check_mutate_const(step: usize, key: &str) -> Diagnostic {
let message = format!(
"step {step}: cannot mutate {KEYWORD_CONST} `{key}`: {KEYWORD_CONST} bindings are deeply immutable"
);
Diagnostic::new(
"dsl.check.mutate_const",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("key", key)]),
)
}
pub fn check_isolated_allowlist(step: usize) -> Diagnostic {
let message = format!("step {step}: isolated allowlist outside {KEYWORD_ISOLATED}");
Diagnostic::new(
"dsl.check.isolated_allowlist",
message,
Diagnostic::make_fields(&[("step", &step.to_string())]),
)
}
pub fn check_remote_unknown_var(target: &str, key: &str) -> Diagnostic {
let message = format!("{KEYWORD_REMOTE} `{target}` uses unknown variable `${key}`");
Diagnostic::new(
"dsl.check.remote_unknown_var",
message,
Diagnostic::make_fields(&[("target", target), ("key", key)]),
)
}
pub fn check_remote_undeclared_env(pos: &str, label: &str, target: &str, name: &str) -> Diagnostic {
let message = format!(
"{pos} in {label}: {KEYWORD_REMOTE} `{target}` ships undeclared environment variable `env:{name}`: declare it first with {KEYWORD_ENV} or {KEYWORD_INHERIT_ENV}"
);
Diagnostic::new(
"dsl.check.remote_undeclared_env",
message,
Diagnostic::make_fields(&[
("pos", pos),
("scope", label),
("target", target),
("name", name),
]),
)
}
pub fn check_list_not_list(step: usize, list: &str, actual: &TypeTag) -> Diagnostic {
let a = render_structural(actual);
let message = format!(
"step {step}: {KEYWORD_LIST_APPEND} `${list}`: variable is {a}, not {LIST_TYPE_NAME}"
);
Diagnostic::new(
"dsl.check.list_not_list",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("list", list), ("actual", &a)]),
)
}
pub fn check_list_void_push(step: usize, list: &str) -> Diagnostic {
let message = format!(
"step {step}: {KEYWORD_LIST_APPEND} `${list}`: {VOID_TYPE_NAME} has no value to push"
);
Diagnostic::new(
"dsl.check.list_void_push",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("list", list)]),
)
}
pub fn check_pipe_mismatch(step: usize, actual: &str) -> Diagnostic {
let message = format!("step {step}: TypeMismatch: expected `{PIPE_TYPE_NAME}`, got `{actual}`");
Diagnostic::new(
"dsl.check.pipe_mismatch",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("actual", actual)]),
)
}
pub fn check_missing_field(ctx: &str, name: &str) -> Diagnostic {
let message = format!("{ctx}: missing field `{name}`");
Diagnostic::new(
"dsl.check.missing_field",
message,
Diagnostic::make_fields(&[("ctx", ctx), ("field", name)]),
)
}
pub fn check_record_unknown_field(ctx: &str, name: &str) -> Diagnostic {
let message = format!("{ctx}: unknown field `{name}`");
Diagnostic::new(
"dsl.check.record_unknown_field",
message,
Diagnostic::make_fields(&[("ctx", ctx), ("field", name)]),
)
}
pub fn check_break_outside_switch(step: usize) -> Diagnostic {
let message = format!("step {step}: {KEYWORD_BREAK} outside loop or {KEYWORD_SWITCH}");
Diagnostic::new(
"dsl.check.break_outside_switch",
message,
Diagnostic::make_fields(&[("step", &step.to_string())]),
)
}
pub fn check_flow_outside_loop(step: usize, word: &str) -> Diagnostic {
let message = format!("step {step}: {word} outside loop");
Diagnostic::new(
"dsl.check.flow_outside_loop",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("flow", word)]),
)
}
pub fn check_flow_crosses_func(step: usize, word: &str, name: &str) -> Diagnostic {
let message = format!("step {step}: {word} cannot cross function boundary (in {name}())");
Diagnostic::new(
"dsl.check.flow_crosses_func",
message,
Diagnostic::make_fields(&[
("step", &step.to_string()),
("flow", word),
("function", name),
]),
)
}
pub fn check_flow_crosses_block(step: usize, word: &str) -> Diagnostic {
let message = format!("step {step}: {word} cannot cross block boundary");
Diagnostic::new(
"dsl.check.flow_crosses_block",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("flow", word)]),
)
}
pub fn check_flow_crosses_async(step: usize, word: &str) -> Diagnostic {
let message = format!("step {step}: {word} cannot cross {KEYWORD_ASYNC} boundary");
Diagnostic::new(
"dsl.check.flow_crosses_async",
message,
Diagnostic::make_fields(&[("step", &step.to_string()), ("flow", word)]),
)
}
pub fn check_arg_void(ctx: &str) -> Diagnostic {
let message = format!("{ctx}: {VOID_TYPE_NAME} has no value to pass");
Diagnostic::new(
"dsl.check.arg_void",
message,
Diagnostic::make_fields(&[("ctx", ctx)]),
)
}
pub fn check_any_into_concrete(ctx: &str, expected: &TypeTag) -> Diagnostic {
let exp = render_structural(expected);
let message = format!(
"{ctx}: untyped ANY value flows into `{exp}` parameter; bind through {KEYWORD_LET} `$x`: `{exp}` first"
);
Diagnostic::new(
"dsl.check.any_into_concrete",
message,
Diagnostic::make_fields(&[("ctx", ctx), ("expected", &exp)]),
)
}
pub fn check_async_decl_not_handle(key: &str, declared: &TypeTag) -> Diagnostic {
let d = render_structural(declared);
let message = format!(
"function `{key}` declares {d}, but {KEYWORD_ASYNC} {KEYWORD_FUNC} must declare {HANDLE_TYPE_NAME} or {HANDLE_TYPE_NAME}<T>"
);
Diagnostic::new(
"dsl.check.async_decl_not_handle",
message,
Diagnostic::make_fields(&[("function", key), ("declares", &d)]),
)
}
pub fn check_func_fallthrough(key: &str, declared: &TypeTag) -> Diagnostic {
let d = render_structural(declared);
let message = format!(
"function `{key}` declares {d} but may fall through with no {KEYWORD_RETURN} on some path"
);
Diagnostic::new(
"dsl.check.func_fallthrough",
message,
Diagnostic::make_fields(&[("function", key), ("declares", &d)]),
)
}
pub fn check_func_no_return(key: &str, declared: &TypeTag) -> Diagnostic {
let d = render_structural(declared);
let message = format!("function `{key}` declares {d} but has no {KEYWORD_RETURN} on any path");
Diagnostic::new(
"dsl.check.func_no_return",
message,
Diagnostic::make_fields(&[("function", key), ("declares", &d)]),
)
}
pub fn check_func_bare_return(key: &str, declared: &TypeTag) -> Diagnostic {
let d = render_structural(declared);
let message = format!(
"function `{key}` declares {d} but has a bare {KEYWORD_RETURN} on some path; bare {KEYWORD_RETURN} is only a void exit"
);
Diagnostic::new(
"dsl.check.func_bare_return",
message,
Diagnostic::make_fields(&[("function", key), ("declares", &d)]),
)
}
pub fn check_func_void_yield(key: &str, line: usize, ty: &TypeTag) -> Diagnostic {
let t = render_structural(ty);
let message = format!(
"function `{key}` declares {VOID_TYPE_NAME} but {KEYWORD_RETURN} at line {line} yields {t}"
);
Diagnostic::new(
"dsl.check.func_void_yield",
message,
Diagnostic::make_fields(&[
("function", key),
("line", &line.to_string()),
("yield", &t),
]),
)
}
pub fn check_func_no_value_return(key: &str, declared: &TypeTag) -> Diagnostic {
let d = render_structural(declared);
let message =
format!("function `{key}` declares {d} but has no value {KEYWORD_RETURN} on any path");
Diagnostic::new(
"dsl.check.func_no_value_return",
message,
Diagnostic::make_fields(&[("function", key), ("declares", &d)]),
)
}
pub fn check_func_return_mismatch(
key: &str,
declared: &TypeTag,
line: usize,
ty: &TypeTag,
) -> Diagnostic {
let d = render_structural(declared);
let t = render_structural(ty);
let message =
format!("function `{key}` declares {d} but {KEYWORD_RETURN} at line {line} yields {t}");
Diagnostic::new(
"dsl.check.func_return_mismatch",
message,
Diagnostic::make_fields(&[
("function", key),
("declares", &d),
("line", &line.to_string()),
("yield", &t),
]),
)
}
pub fn check_unknown_function(name: &str, hint: &str) -> Diagnostic {
let message = format!("unknown function `{name}`{hint}");
Diagnostic::new(
"dsl.check.unknown_function",
message,
Diagnostic::make_fields(&[("name", name), ("hint", hint)]),
)
}
pub fn check_const_no_alias_at(pos: &str, qualified: &str, alias: &str) -> Diagnostic {
let message = format!(
"{pos}: unknown {KEYWORD_CONST} `{qualified}`: no import alias `{alias}` exports that name"
);
Diagnostic::new(
"dsl.check.const_no_alias_at",
message,
Diagnostic::make_fields(&[("pos", pos), ("name", qualified), ("alias", alias)]),
)
}
pub fn check_const_ambiguous_at(
pos: &str,
alias: &str,
name: &str,
files: &std::collections::HashSet<String>,
) -> Diagnostic {
let message = format!(
"{pos}: {}",
super::native::const_ambiguous_message(alias, name, files)
);
Diagnostic::new(
"dsl.check.const_ambiguous_at",
message,
Diagnostic::make_fields(&[("pos", pos), ("alias", alias), ("name", name)]),
)
}
pub fn check_const_is_let_at(pos: &str, qualified: &str) -> Diagnostic {
let message = format!(
"{pos}: `{qualified}` is a {KEYWORD_LET} binding and cannot be exported: only {KEYWORD_CONST} bindings cross the module boundary"
);
Diagnostic::new(
"dsl.check.const_is_let_at",
message,
Diagnostic::make_fields(&[("pos", pos), ("name", qualified)]),
)
}
pub fn check_const_hinted_at(pos: &str, qualified: &str, hint: &str) -> Diagnostic {
let message = format!("{pos}: unknown {KEYWORD_CONST} `{qualified}`: {hint}");
Diagnostic::new(
"dsl.check.const_hinted_at",
message,
Diagnostic::make_fields(&[("pos", pos), ("name", qualified), ("hint", hint)]),
)
}
pub fn check_call_arity_exact(step: usize, display: &str, total: usize, got: usize) -> Diagnostic {
let message = format!("step {step}: {display}() expects {total} argument(s), got {got}");
Diagnostic::new(
"dsl.check.call_arity_exact",
message,
Diagnostic::make_fields(&[
("step", &step.to_string()),
("function", display),
("expected", &total.to_string()),
("got", &got.to_string()),
]),
)
}
pub fn check_call_arity_range(
step: usize,
display: &str,
min: usize,
max: usize,
got: usize,
) -> Diagnostic {
let message = format!("step {step}: {display}() expects {min} to {max} argument(s), got {got}");
Diagnostic::new(
"dsl.check.call_arity_range",
message,
Diagnostic::make_fields(&[
("step", &step.to_string()),
("function", display),
("min", &min.to_string()),
("max", &max.to_string()),
("got", &got.to_string()),
]),
)
}
pub fn check_apply_arity_exact(
prefix: &str,
display: &str,
total: usize,
got: usize,
) -> Diagnostic {
let message = format!("{prefix}{display}() expects {total} argument(s), got {got}");
Diagnostic::new(
"dsl.check.apply_arity_exact",
message,
Diagnostic::make_fields(&[
("prefix", prefix),
("function", display),
("expected", &total.to_string()),
("got", &got.to_string()),
]),
)
}
pub fn check_apply_arity_range(
prefix: &str,
display: &str,
min: usize,
max: usize,
got: usize,
) -> Diagnostic {
let message = format!("{prefix}{display}() expects {min} to {max} argument(s), got {got}");
Diagnostic::new(
"dsl.check.apply_arity_range",
message,
Diagnostic::make_fields(&[
("prefix", prefix),
("function", display),
("min", &min.to_string()),
("max", &max.to_string()),
("got", &got.to_string()),
]),
)
}
pub fn check_call_arg_allowed(pat: &str, allowed: &[&str], text: &str) -> Diagnostic {
let joined = allowed.join(", ");
let message = format!("{pat} must be one of: {joined}, got {text:?}");
Diagnostic::new(
"dsl.check.call_arg_allowed",
message,
Diagnostic::make_fields(&[("ctx", pat), ("allowed", &joined), ("got", text)]),
)
}
pub fn check_void_in_arithmetic(prefix: &str) -> Diagnostic {
let message = format!("{prefix}{VOID_TYPE_NAME} has no value in arithmetic");
Diagnostic::new(
"dsl.check.void_in_arithmetic",
message,
Diagnostic::make_fields(&[("prefix", prefix)]),
)
}
pub fn check_arithmetic_type(prefix: &str) -> Diagnostic {
let message = format!("{prefix}Type Error: arithmetic requires Int or Float");
Diagnostic::new(
"dsl.check.arithmetic_type",
message,
Diagnostic::make_fields(&[("prefix", prefix)]),
)
}
pub fn check_void_to_negate(prefix: &str) -> Diagnostic {
let message = format!("{prefix}{VOID_TYPE_NAME} has no value to negate");
Diagnostic::new(
"dsl.check.void_to_negate",
message,
Diagnostic::make_fields(&[("prefix", prefix)]),
)
}
pub fn check_negate_type(prefix: &str, actual: &str) -> Diagnostic {
let message = format!("{prefix}Type Error: unary '-' requires Int or Float, got {actual}");
Diagnostic::new(
"dsl.check.negate_type",
message,
Diagnostic::make_fields(&[("prefix", prefix), ("actual", actual)]),
)
}
pub fn check_void_to_compare(prefix: &str) -> Diagnostic {
let message = format!("{prefix}{VOID_TYPE_NAME} has no value to compare");
Diagnostic::new(
"dsl.check.void_to_compare",
message,
Diagnostic::make_fields(&[("prefix", prefix)]),
)
}
pub fn check_ordering_type(prefix: &str) -> Diagnostic {
let message = format!("{prefix}Type Error: ordering comparison requires Int or Float");
Diagnostic::new(
"dsl.check.ordering_type",
message,
Diagnostic::make_fields(&[("prefix", prefix)]),
)
}
pub fn check_rpn_underflow() -> Diagnostic {
Diagnostic::new(
"dsl.check.rpn_underflow",
"internal error: RPN stack underflow".to_string(),
Diagnostic::make_fields(&[]),
)
}
pub fn check_rpn_leftover(count: usize) -> Diagnostic {
let message = format!("internal error: RPN stack left {count} values");
Diagnostic::new(
"dsl.check.rpn_leftover",
message,
Diagnostic::make_fields(&[("count", &count.to_string())]),
)
}
pub fn check_block_fallthrough(pos: &str) -> Diagnostic {
let message = format!("{pos}: block may fall through with no {KEYWORD_RETURN} on some path");
Diagnostic::new(
"dsl.check.block_fallthrough",
message,
Diagnostic::make_fields(&[("pos", pos)]),
)
}
pub fn check_void_no_value() -> Diagnostic {
Diagnostic::new(
"dsl.check.void_no_value",
"VOID has no value to pass".to_string(),
Diagnostic::make_fields(&[]),
)
}
#[cfg(test)]
pub(crate) fn reason_sample(msg: &str) -> Diagnostic {
Diagnostic::new(
"test.reason.sample",
msg.to_string(),
Diagnostic::make_fields(&[]),
)
}
#[cfg(test)]
mod tests {
use super::*;
fn utf8_err_sample() -> std::str::Utf8Error {
String::from_utf8(vec![0xff]).unwrap_err().utf8_error()
}
fn regex_err_sample() -> regex::Error {
let pattern = "[".to_owned();
regex::Regex::new(&pattern).unwrap_err()
}
fn parse_err_sample() -> ParseError {
use oxdock_parser::{ParseErrorKind, SpanContext};
ParseError::from_diagnostic(
ParseErrorKind::Syntax,
typing_max_depth(8, "X"),
&SpanContext::line_only(0),
)
}
fn parse_err_fallback_sample() -> ParseError {
use oxdock_parser::SpanContext;
ParseError::syntax(
"boom".to_string(),
Vec::new(),
None,
&SpanContext::line_only(0),
)
}
fn exit_status_sample() -> std::process::ExitStatus {
oxdock_sys_test_utils::exit_status_from_code(1)
}
#[cfg(unix)]
fn exit_status_signal_sample() -> std::process::ExitStatus {
use std::os::unix::process::ExitStatusExt;
std::process::ExitStatus::from_raw(9)
}
#[test]
fn exit_status_fields_carry_code_for_normal_exits() {
let status = exit_status_sample();
assert_eq!(status.code(), Some(1));
for diag in [
eval_run_exit_status("echo hi", &status),
eval_run_argv_exit_status(&["echo".to_string()], &status),
eval_async_exit_status(None, &status),
eval_await_exit_status("t", &status),
] {
assert_eq!(diag.fields().get(FIELD_CODE), Some(&"1".to_string()));
assert!(!diag.fields().contains_key(FIELD_STATUS));
}
}
#[cfg(unix)]
#[test]
fn exit_status_fields_carry_status_for_signals() {
let status = exit_status_signal_sample();
assert_eq!(status.code(), None);
for diag in [
eval_run_exit_status("echo hi", &status),
eval_run_argv_exit_status(&["echo".to_string()], &status),
eval_async_exit_status(None, &status),
eval_await_exit_status("t", &status),
] {
assert!(diag.fields().contains_key(FIELD_STATUS));
assert!(!diag.fields().contains_key(FIELD_CODE));
}
}
#[test]
fn clash_names_both_sides() {
let d = alias_clash("x", "y", "z");
assert_eq!(d.key(), "dsl.alias.clash");
assert_eq!(d.message(), "alias `x` for field `y` clashes with `z`");
}
#[test]
fn self_and_duplicate_have_distinct_keys() {
assert_eq!(alias_self("a", "a").key(), "dsl.alias.self");
assert_eq!(map_duplicate_field("a").key(), "dsl.map.duplicate_field");
}
#[test]
fn every_resolution_error_has_a_distinct_key() {
let types = vec!["STRING".to_string()];
let empty: Vec<String> = vec![];
let keys = [
typing_max_depth(8, "INT").key(),
typing_bare_map().key(),
typing_bare_list().key(),
typing_bare_handle().key(),
alias_cycle(&["A".to_string(), "A".to_string()]).key(),
typing_unknown("NOPE", &types, &empty, &empty).key(),
typing_unregistered("LET $x", "NOPE", &types).key(),
typing_void_position("LET $x").key(),
check_unknown_option("F", "k", &["a", "b"]).key(),
check_option_value(&reason_sample("x")).key(),
typing_no_args("STRING").key(),
typing_handle_arity().key(),
typing_list_arity().key(),
typing_map_bare("MAP").key(),
typing_default_mismatch("f", "INT").key(),
typing_empty_union().key(),
alias_already_defined("A").key(),
alias_builtin_collision("A").key(),
alias_host_collision("A").key(),
alias_schema_collision("A").key(),
alias_func_collision("A").key(),
mcp_export_type_unknown("T").key(),
mcp_break_outside_loop(1).key(),
mcp_continue_outside_loop(1).key(),
mcp_return_outside_function(1).key(),
mcp_unknown_tool("FOO").key(),
mcp_call_failed(&reason_sample("boom"), "", "").key(),
import_cycle(&["a".to_string(), "b".to_string()]).key(),
import_depth_limit(8, "f").key(),
import_not_found("f").key(),
import_cannot_resolve("f", &reason_sample("x")).key(),
import_cannot_read("f", &reason_sample("x")).key(),
import_bad_utf8("f", &utf8_err_sample()).key(),
import_parse_failed("f", &parse_err_sample()).key(),
engine_parse_failed(&parse_err_fallback_sample()).key(),
import_missing_export("f", "FUNC", "g").key(),
import_unknown_member("f", "function", "g").key(),
import_unknown_type("f", "T", None).key(),
import_failed_validation("f", typing_max_depth(8, "X")).key(),
import_stateful_harvest("f", "g").key(),
import_unknown_function("f", "g").key(),
import_type_collision("f", "T", "a", "b").key(),
import_const_no_alias("q", "A").key(),
import_const_ambiguous("A", "N", &std::collections::HashSet::new()).key(),
import_const_hinted("q", "h").key(),
import_const_unknown("q").key(),
import_const_uninitialized("q").key(),
import_const_is_let("q").key(),
import_const_forward_failed("x").key(),
import_not_in_closure("f").key(),
import_export_type_mismatch("f", "T").key(),
check_var_tag("v", typing_max_depth(8, "X")).key(),
check_func_tag("f", typing_max_depth(8, "X")).key(),
check_step_wrap(3, typing_max_depth(8, "X")).key(),
check_ctx_wrap("ctx", &import_const_forward_failed("x")).key(),
check_exact_mismatch("ctx", &TypeTag::Int, &TypeTag::String).key(),
check_cannot_unify("ctx", &TypeTag::Int, &TypeTag::String).key(),
check_undefined_var("step 1: ", "x").key(),
check_var_not_guaranteed("x").key(),
check_unknown_field("step 1: ", "a", &[]).key(),
check_invalid_array_index("", "0").key(),
check_cannot_traverse("", "k").key(),
check_duplicate_func("F", "f.oxdock").key(),
check_redeclare_const(1, "x").key(),
check_redeclare_let(1, "x").key(),
check_undeclared_env("step 1", "top", "env:", "K").key(),
check_placeholder_keypath().key(),
check_empty_placeholder_var().key(),
check_bare_sigil("$x").key(),
check_undefined_script_var("k").key(),
check_placeholder_unknown("A::F").key(),
check_disjoint_alias_miss(
"A",
"F",
"F",
&std::collections::HashSet::new(),
false,
&|_| false,
)
.key(),
check_placeholder_miss("M", "F", true, false, false)
.expect("described")
.key(),
check_template_arity_exact("step 1", "top", "F", 1, 2).key(),
check_template_arity_range("step 1", "top", "F", 1, 2, 3).key(),
check_template_arg_allowed("step 1", "top", "F", "p", &["a"], "b").key(),
check_template_arg_depth().key(),
check_empty_placeholder_arg().key(),
check_invalid_placeholder_arg("x").key(),
check_invalid_map_entry("e").key(),
check_duplicate_map_key("k").key(),
check_void_no_value().key(),
check_depth_function("F").key(),
check_depth_scope("top").key(),
check_void_block_bind(1, "x").key(),
check_capture_mismatch(1, "LET", "x", &TypeTag::String, &TypeTag::Int).key(),
check_await_not_handle(1, "t", &TypeTag::String).key(),
check_await_void_payload(1, "t", "x").key(),
check_await_yield_mismatch(1, "t", &TypeTag::String, "x", &TypeTag::Int).key(),
check_async_not_handle(1, "x", &TypeTag::Int).key(),
check_async_bare_return(1, "x", &TypeTag::Int).key(),
check_async_void_yield(1, 3, &TypeTag::Int).key(),
check_async_no_return(1, "x", &TypeTag::Int).key(),
check_async_return_mismatch(1, "x", &TypeTag::Int, 3, &TypeTag::String).key(),
check_return_outside(1).key(),
check_return_crosses_async(1).key(),
check_undeclared_set(1, "x").key(),
check_mutate_const(1, "x").key(),
check_isolated_allowlist(1).key(),
check_remote_unknown_var("t", "x").key(),
check_remote_undeclared_env("step 1", "top", "t", "K").key(),
check_list_not_list(1, "l", &TypeTag::String).key(),
check_list_void_push(1, "l").key(),
check_pipe_mismatch(1, "STRING").key(),
check_missing_field("ctx", "f").key(),
check_record_unknown_field("ctx", "f").key(),
check_break_outside_switch(1).key(),
check_flow_outside_loop(1, "CONTINUE").key(),
check_flow_crosses_func(1, "BREAK", "F").key(),
check_flow_crosses_block(1, "BREAK").key(),
check_flow_crosses_async(1, "BREAK").key(),
check_arg_void("ctx").key(),
check_any_into_concrete("ctx", &TypeTag::String).key(),
check_async_decl_not_handle("F", &TypeTag::Int).key(),
check_func_fallthrough("F", &TypeTag::Int).key(),
check_func_no_return("F", &TypeTag::Int).key(),
check_func_bare_return("F", &TypeTag::Int).key(),
check_func_void_yield("F", 3, &TypeTag::Int).key(),
check_func_no_value_return("F", &TypeTag::Int).key(),
check_func_return_mismatch("F", &TypeTag::Int, 3, &TypeTag::String).key(),
check_unknown_function("F", "").key(),
check_const_no_alias_at("step 1", "A::C", "A").key(),
check_const_ambiguous_at("step 1", "A", "C", &std::collections::HashSet::new()).key(),
check_const_is_let_at("step 1", "A::C").key(),
check_const_hinted_at("step 1", "A::C", "h").key(),
check_call_arity_exact(1, "F", 1, 2).key(),
check_call_arity_range(1, "F", 1, 2, 3).key(),
check_apply_arity_exact("", "F", 1, 2).key(),
check_apply_arity_range("", "F", 1, 2, 3).key(),
check_call_arg_allowed("ctx", &["a"], "b").key(),
check_void_in_arithmetic("").key(),
check_arithmetic_type("").key(),
check_void_to_negate("").key(),
check_negate_type("", "STRING").key(),
check_void_to_compare("").key(),
check_ordering_type("").key(),
check_rpn_underflow().key(),
check_rpn_leftover(2).key(),
check_block_fallthrough("step 1").key(),
import_flow_crosses_boundary("BREAK", 3, "f").key(),
func_zero_value_missing("MAP").key(),
func_param_type("F", std_unknown_type("T")).key(),
func_optional_param("F", "p", func_zero_value_missing("INT")).key(),
func_shadow_reserved("F").key(),
func_duplicate_in_scope("F").key(),
func_param_values_without_type("p", "F").key(),
func_optional_before_required("p", "F").key(),
func_optional_without_map("p", "F").key(),
func_ambiguous_alias("A", "F", &std::collections::HashSet::new()).key(),
func_export_unknown("F").key(),
func_placeholder_unknown("M", "F", &["M::F".to_string()]).key(),
func_describe_unqualified("F").key(),
func_unknown("F").key(),
func_arg_arity_exact("F", 1, 0).key(),
func_arg_arity_range("F", 1, 2, 3).key(),
func_arg_must_be_string("F", "p").key(),
func_arg_must_be_one_of("F", "p", &["a", "b"], "c").key(),
func_arg_must_be_finite("F", "p", f64::INFINITY).key(),
func_arg_must_be_bool("F", "p", "x").key(),
func_arg_must_be_bool_or_string("F", "p", &crate::Value::string("x".to_string())).key(),
func_arg_must_be_pipe("F", "p", "STRING").key(),
func_arg_must_be_semaphore("F", "p", "STRING").key(),
func_arg_must_be_handle("F", "p", "STRING").key(),
func_arg_expects_custom("F", "p", "T", "STRING").key(),
eval_call_unknown("F", "").key(),
eval_call_unknown_rpn("F", "").key(),
eval_call_return_tag_failed("F", eval_remove_missing("x")).key(),
eval_call_failed("F", &reason_sample("x")).key(),
eval_call_recursion_limit("F").key(),
eval_call_arity_exact("F", 1, 0).key(),
eval_call_arity_range("F", 1, 2, 0).key(),
eval_call_missing_param("p", "F").key(),
eval_call_zero_value_failed("F", "p", eval_remove_missing("x")).key(),
eval_call_flow_crosses_func(3, "BREAK", "F").key(),
eval_for_needs_key_value().key(),
eval_for_map_key_type("INT").key(),
eval_for_needs_list_or_map(&crate::Value::string("x".to_string())).key(),
std_unknown_type("T").key(),
std_contains_needle_type("INT").key(),
std_contains_haystack_type("INT").key(),
std_len_unexpected_type("INT").key(),
std_is_terminal_expected("nope").key(),
std_semaphore_needs_positive(0).key(),
std_bool_needs_bool_or_string(&crate::Value::string("x".to_string())).key(),
std_bool_cannot_coerce("BOOL", "x").key(),
std_shell_split_failed(&shell_words::ParseError).key(),
std_path_base_failed(&reason_sample("x")).key(),
std_path_rel_failed(&reason_sample("x")).key(),
std_parse_args_arity(2).key(),
std_parse_args_bool_flag("f", "x").key(),
std_parse_args_bool_type("f", "INT").key(),
std_parse_args_needs_value("f").key(),
std_parse_args_expects_int("f").key(),
std_parse_args_expects_float("f").key(),
std_parse_args_not_utf8().key(),
std_parse_args_lex_error(&lexopt::Error::UnexpectedOption("--x".to_string())).key(),
std_parse_args_schema_flag_empty().key(),
std_parse_args_duplicate_flag("f", None).key(),
std_parse_args_missing_flag("f", None).key(),
std_parse_args_unknown_flag("f").key(),
std_parse_args_schema_type("S", &reason_sample("x")).key(),
std_parse_args_schema_shape("S").key(),
std_parse_args_schema_field_type("f", "INT").key(),
std_parse_args_arg_shape(&reason_sample("x")).key(),
std_parse_flags_arity(2).key(),
std_parse_flags_positional(&["a".to_string()]).key(),
std_parse_positionals_arity(2).key(),
std_parse_byte_count_negative(-1).key(),
std_parse_byte_count_integral(1.5).key(),
std_parse_byte_count_shape(&crate::Value::string("x".to_string())).key(),
std_parse_byte_count_range("x").key(),
std_int_non_integer_float(1.5).key(),
std_int_bad_string("x").key(),
std_int_bad_type(&crate::Value::string("x".to_string())).key(),
std_float_non_finite_float(f64::INFINITY).key(),
std_float_bad_string("x").key(),
std_float_non_finite_string("inf").key(),
std_float_bad_type(&crate::Value::string("x".to_string())).key(),
eval_math_stack_underflow().key(),
eval_math_stack_len(2).key(),
eval_arith_overflow_div_zero().key(),
eval_arith_needs_numeric(
&crate::Value::string("x".to_string()),
&crate::Value::string("y".to_string()),
)
.key(),
eval_float_div_zero().key(),
eval_non_finite_result().key(),
eval_neg_overflow().key(),
eval_neg_needs_numeric(&crate::Value::string("x".to_string())).key(),
eval_condition_needs_bool(&crate::Value::string("x".to_string())).key(),
eval_expected_int("x").key(),
eval_int_arg_resolve(&reason_sample("x")).key(),
eval_dispatch_failed(&reason_sample("x")).key(),
eval_pipe_assertion_read_failed(&reason_sample("x")).key(),
eval_with_io_unexpanded().key(),
eval_with_io_geometry_needs_tty().key(),
eval_with_io_tty_no_stderr().key(),
eval_with_io_tty_needs_run().key(),
eval_with_io_duplicate_stream("stdin").key(),
eval_pipe_handle_mismatch("STRING", &crate::Value::string("x".to_string())).key(),
eval_async_cancelled().key(),
eval_flow_crosses_remote(1, "BREAK").key(),
eval_stdin_lock_failed("READ").key(),
eval_stdin_read_failed(None, &std::io::Error::other("x")).key(),
eval_assert_stdin_overflow("ASSERT_EQ").key(),
eval_assert_stdout_overflow("ASSERT_EQ").key(),
eval_assert_no_exact_capture("ASSERT_EQ").key(),
eval_assert_hash_mismatch("ASSERT_EQ", "a", "b").key(),
eval_assert_hash_match("ASSERT_EQ", "a").key(),
eval_assert_hash_needs_string("ASSERT_EQ", &crate::Value::string("x".to_string()))
.key(),
eval_assert_stream_mismatch("ASSERT_EQ", None, "a").key(),
eval_assert_stream_mismatch_text("ASSERT_EQ", "a", "b").key(),
eval_assert_stream_unexpected_equal("ASSERT_NE", "a").key(),
eval_assert_stderr_unsupported("ASSERT_EQ").key(),
eval_assert_requires_expected("ASSERT_EQ").key(),
eval_assert_value_mismatch(
"ASSERT_EQ",
&crate::Value::string("a".to_string()),
&crate::Value::string("b".to_string()),
)
.key(),
eval_assert_value_unexpected_equal(
"ASSERT_NE",
&crate::Value::string("a".to_string()),
&crate::Value::string("a".to_string()),
)
.key(),
eval_assert_pipe_mismatch("ASSERT_EQ", None, "a").key(),
eval_assert_pipe_mismatch_text("ASSERT_EQ", "a", "b").key(),
eval_assert_pipe_unexpected_equal("ASSERT_NE", "a").key(),
eval_assert_contains_str_mismatch("ASSERT_CONTAINS", "n", "h").key(),
eval_assert_contains_value_mismatch(
"ASSERT_CONTAINS",
"n",
&crate::Value::string("x".to_string()),
)
.key(),
eval_assert_contains_missing("ASSERT_CONTAINS", "n").key(),
eval_assert_contains_needs_haystack(
"ASSERT_CONTAINS",
&crate::Value::string("x".to_string()),
)
.key(),
eval_assert_contains_emitted_mismatch("ASSERT_CONTAINS", "n", "e").key(),
eval_assert_contains_pipe_mismatch("ASSERT_CONTAINS", "n", "h").key(),
eval_break_outside_loop().key(),
eval_continue_outside_loop().key(),
eval_capture_flow_outside_loop(1, "BREAK").key(),
eval_capture_return_outside_function(1).key(),
eval_block_flow_crosses_block(1, "BREAK").key(),
eval_async_flow_crosses_async(1, "BREAK").key(),
eval_capture_with_io_stdout("LET").key(),
eval_capture_not_utf8("LET", "a", eval_remove_missing("x")).key(),
eval_async_entry_unavailable().key(),
eval_task_var_undefined("t").key(),
eval_task_not_handle("t").key(),
eval_task_not_found("$t").key(),
eval_await_cancelled("t").key(),
eval_await_member_not_handle("$w[0]", "INT").key(),
eval_await_timeout("t").key(),
eval_await_exit_status("t", &exit_status_sample()).key(),
eval_await_fell_off("LET", "o", "t").key(),
eval_cancel_gone("t").key(),
eval_cancel_already("t").key(),
eval_timeout_deadline("1s").key(),
eval_inside_isolated().key(),
eval_isolated_outside_allowlist().key(),
eval_placeholder_miss_text("placeholder miss").key(),
eval_remote_copy_outside_guest().key(),
eval_remote_rewind_failed(&std::io::Error::other("rewind")).key(),
eval_remote_push_file_read_failed(&std::io::Error::other("r")).key(),
eval_remote_push_file_write_failed(&std::io::Error::other("w")).key(),
eval_remote_unknown_var("t", "v").key(),
eval_remote_unrenderable_var("v", "HANDLE", "t").key(),
eval_remote_unknown_env("t", "N").key(),
eval_remote_fetch_missing("a/b", None).key(),
eval_remote_fetch_entry_cap("a/b", 100_000).key(),
eval_remote_fetch_no_file_name("a/b").key(),
eval_remote_no_session("t").key(),
eval_remote_exit_status("t", 3).key(),
eval_remote_transport_failed("t").key(),
eval_remote_push_destination_escapes("a", &reason_sample("x")).key(),
eval_remote_push_target_outside("a", &reason_sample("x")).key(),
eval_remote_push_symlink_over_dir("a").key(),
eval_with_io_tty_live_pipe("stdin").key(),
eval_write_live_pipe("stdout").key(),
eval_run_cancelled("echo hi").key(),
eval_run_argv_cancelled(&["echo".to_string()]).key(),
eval_run_unexpected_capture("echo hi").key(),
eval_run_argv_unexpected_capture(&["echo".to_string()]).key(),
eval_run_exit_status("echo hi", &exit_status_sample()).key(),
eval_run_argv_exit_status(&["echo".to_string()], &exit_status_sample()).key(),
eval_run_needs_program("[]").key(),
eval_run_pty_exit_status("echo hi", 1).key(),
eval_run_exec_requires_arg().key(),
eval_pipe_not_utf8("ASSERT", &String::from_utf8(vec![0xff]).unwrap_err()).key(),
eval_run_spawn_failed("echo hi", &reason_sample("x")).key(),
eval_run_argv_spawn_failed(&["echo".to_string()], &reason_sample("x")).key(),
eval_run_exec_pipe_arg().key(),
eval_run_exec_semaphore_arg().key(),
eval_run_exec_permit_arg().key(),
eval_run_exec_element_needs_string("map").key(),
eval_sleep_cancelled().key(),
eval_copy_failed("a", "b", &reason_sample("x")).key(),
eval_copy_git_failed("r", "a", "b", &reason_sample("x")).key(),
eval_copy_no_file_name("p").key(),
eval_copy_destination_escapes("p", &reason_sample("x")).key(),
eval_symlink_failed("a", "b", &reason_sample("x")).key(),
eval_symlink_no_file_name("a").key(),
eval_archive_failed("a", "b", &reason_sample("x")).key(),
eval_archive_no_file_name("a", "b", "d").key(),
eval_archive_refuses_symlink_source("a", "b").key(),
eval_archive_refuses_symlink("a", "b", "c").key(),
eval_archive_destination_is_source("a", "a").key(),
eval_archive_destination_inside_tree("a", "b").key(),
eval_unarchive_failed("a", "b", &reason_sample("x")).key(),
eval_unarchive_member_failed("a", "b", &reason_sample("x")).key(),
eval_unarchive_bad_max_bytes(
"a",
"b",
"r",
oxdock_parser::diagnostics::invalid_byte_count("r"),
)
.key(),
eval_unarchive_expansion_cap("a", "b", 8, "p").key(),
eval_unarchive_refuses_symlink("a", "b", "p", "t").key(),
eval_unarchive_restore_mode_failed("a", "b", &reason_sample("x")).key(),
eval_workdir_failed("p", &reason_sample("x")).key(),
eval_mkdir_resolve_failed("p", &reason_sample("x")).key(),
eval_mkdir_create_failed("p", &reason_sample("x")).key(),
eval_set_executable_failed("p", &reason_sample("x")).key(),
eval_ls_resolve_failed(Some("p"), &reason_sample("x")).key(),
eval_ls_read_failed("p", &reason_sample("x")).key(),
eval_read_resolve_failed("p", &reason_sample("x")).key(),
eval_read_open_failed("p", &reason_sample("x")).key(),
eval_read_file_failed(&std::io::Error::other("x")).key(),
eval_read_write_failed(&std::io::Error::other("x")).key(),
eval_read_needs_stdin().key(),
eval_read_line_needs_stdin().key(),
eval_read_line_not_utf8(&String::from_utf8(vec![0xff]).unwrap_err()).key(),
eval_write_resolve_failed("p", &reason_sample("x")).key(),
eval_ensure_parent_failed("p", &reason_sample("x")).key(),
eval_write_file_failed("p", &reason_sample("x")).key(),
eval_write_needs_stdin("p").key(),
eval_write_open_failed("p", &reason_sample("x")).key(),
eval_write_stream_failed("p", &reason_sample("x")).key(),
eval_append_resolve_failed("p", &reason_sample("x")).key(),
eval_append_failed("p", &reason_sample("x")).key(),
eval_append_needs_stdin("p").key(),
eval_append_open_failed("p", &reason_sample("x")).key(),
eval_append_line_resolve_failed("p", &reason_sample("x")).key(),
eval_remove_failed("p", &reason_sample("x")).key(),
eval_remove_protected("p").key(),
eval_remove_missing("p").key(),
eval_remove_link_changed("p").key(),
eval_remove_not_empty_failed("p", &reason_sample("x")).key(),
eval_expand_resolve_failed("p", &reason_sample("x")).key(),
eval_expand_read_failed("p", &reason_sample("x")).key(),
eval_expand_write_failed(&std::io::Error::other("x")).key(),
eval_stream_write_failed(&std::io::Error::other("x")).key(),
eval_expand_needs_stdin().key(),
eval_install_failed("a", "b", &reason_sample("x")).key(),
eval_prompt_no_answer("m").key(),
eval_prompt_write_failed("m", &std::io::Error::other("x")).key(),
eval_prompt_flush_failed("m", &std::io::Error::other("x")).key(),
eval_prompt_read_failed("m", &std::io::Error::other("x")).key(),
eval_prompt_eof("m").key(),
eval_prompt_bind_failed("v", eval_remove_missing("x")).key(),
eval_list_append_failed("v", eval_remove_missing("x")).key(),
eval_async_exit_status(None, &exit_status_sample()).key(),
eval_arg_expr_needs_step_ctx(&Expr::Env("X".to_string())).key(),
eval_arg_expand_failed(eval_template_placeholder_miss("x")).key(),
coerce_type_mismatch(
"coercion",
&TypeTag::Int,
&crate::Value::string("x".to_string()),
)
.key(),
coerce_string_to_pipe("x").key(),
coerce_pipe_to_string().key(),
coerce_check_failed(&reason_sample("x")).key(),
eval_host_return_failed(&reason_sample("x")).key(),
eval_scope_underflow().key(),
eval_redeclare_var("x").key(),
eval_redeclare_const("x").key(),
eval_no_var_scope().key(),
eval_const_mutation("x").key(),
eval_undeclared_declare("x", "TYPE").key(),
eval_undeclared("x").key(),
eval_list_not_list("x", "STRING").key(),
eval_list_value_not_list("x").key(),
eval_list_element_failed(&reason_sample("x")).key(),
eval_scratch_materialize_failed(&reason_sample("x")).key(),
eval_task_cap_exceeded(64).key(),
eval_const_arg_keypath().key(),
eval_const_arg_bare_sigil("foo").key(),
eval_template_missing_key("foo", false).key(),
eval_template_empty_placeholder().key(),
eval_template_invalid_key("foo").key(),
eval_template_empty_env().key(),
eval_template_keypath().key(),
eval_template_bare_sigil("foo").key(),
eval_template_placeholder_miss("unknown placeholder").key(),
std_pipe_read_failed("TEXT_REPLACE", &reason_sample("x")).key(),
std_pipe_create_failed("TEXT_REPLACE", &reason_sample("x")).key(),
std_pipe_spawn_failed("TEXT_REPLACE", &std::io::Error::other("x")).key(),
std_pipe_reader_lock_poisoned("TEXT_REPLACE").key(),
std_pipe_writer_lock_poisoned("TEXT_REPLACE").key(),
std_pump_not_utf8().key(),
std_pump_writer_lock_poisoned().key(),
std_pump_write_failed(&std::io::Error::other("x")).key(),
std_pump_spill_drain_failed(&std::io::Error::other("x")).key(),
std_pump_spill_failed(&std::io::Error::other("x")).key(),
std_pump_downstream_closed().key(),
std_pipe_handle_spent().key(),
std_pipe_needs_pipe("TEXT_REPLACE", "STRING").key(),
std_pipe_close_needs_script().key(),
std_assert_lock_poisoned("TEXT_REPLACE").key(),
std_pipe_chunk_read_failed("TEXT_REPLACE", &std::io::Error::other("x")).key(),
std_pipe_input_not_utf8("TEXT_REPLACE").key(),
std_pipe_spill_failed("TEXT_REPLACE", &std::io::Error::other("x")).key(),
std_pipe_write_failed("TEXT_REPLACE", &std::io::Error::other("x")).key(),
eval_compare_equality_shape().key(),
eval_ordering_needs_numeric(
&crate::Value::string("x".to_string()),
&crate::Value::string("y".to_string()),
)
.key(),
eval_unstaged_int_boundary(9223372036854775808).key(),
eval_undefined_var("x").key(),
eval_key_not_found("k").key(),
eval_invalid_array_index("k").key(),
eval_index_out_of_bounds(7).key(),
eval_traverse_scalar("k").key(),
eval_path_type_needs_arg().key(),
eval_path_type_needs_string().key(),
eval_is_exec_needs_arg().key(),
eval_is_exec_needs_string().key(),
eval_path_writable_needs_arg().key(),
eval_path_writable_needs_string().key(),
eval_path_resolve_failed("p", &reason_sample("x")).key(),
eval_workdir_resolve_failed(&reason_sample("x")).key(),
std_text_invalid_pattern("TEXT_MATCH", "[", ®ex_err_sample()).key(),
std_text_needs_search("TEXT_REPLACE").key(),
std_text_needs_needle("TEXT_COUNT").key(),
std_text_needs_one_based_start("TEXT_LINES_RANGE", 0).key(),
std_text_needs_ordered_range("TEXT_LINES_RANGE", 3, 2).key(),
std_pipe_needs_step_io("TEXT_REPLACE").key(),
std_format_byte_count_negative(-1).key(),
std_format_duration_negative(-1).key(),
std_parse_duration_range("x").key(),
std_to_json_non_finite_float(f64::NAN).key(),
std_to_json_unencodable("VOID").key(),
std_to_json_encode_failed(
&serde_json::from_str::<serde_json::Value>("{bad").unwrap_err(),
)
.key(),
std_load_toml_needs_arg().key(),
std_load_toml_needs_string().key(),
std_load_toml_resolve_failed("p", &reason_sample("x")).key(),
std_load_toml_read_failed("p", &reason_sample("x")).key(),
std_load_toml_not_utf8("p", &utf8_err_sample()).key(),
std_toml_parse_failed(&toml::from_str::<serde_json::Value>("a = ").unwrap_err()).key(),
std_parse_toml_needs_string("INT").key(),
std_load_json_needs_arg().key(),
std_load_json_needs_string().key(),
std_load_json_resolve_failed("p", &reason_sample("x")).key(),
std_load_json_read_failed("p", &reason_sample("x")).key(),
std_load_json_not_utf8("p", &utf8_err_sample()).key(),
std_json_parse_failed(&serde_json::from_str::<serde_json::Value>("{bad").unwrap_err())
.key(),
std_parse_json_needs_string("INT").key(),
std_glob_needs_arg().key(),
std_glob_needs_string().key(),
std_glob_resolve_failed(&reason_sample("x")).key(),
std_glob_list_failed(&std::io::Error::other("x")).key(),
std_has_key_needs_map("INT").key(),
std_map_set_needs_map("INT").key(),
std_map_set_duplicate("k").key(),
std_merge_maps_needs_list("INT").key(),
std_merge_maps_needs_map(0, "INT").key(),
std_merge_maps_duplicate("k").key(),
std_base64_encode_needs_string("INT").key(),
std_base64_decode_needs_string("INT").key(),
std_base64_decode_failed("!!!", &base64::DecodeError::InvalidByte(0, b'!')).key(),
std_base64_decode_not_utf8().key(),
json_handle_needs_object(&serde_json::json!(7)).key(),
json_handle_exact_shape().key(),
json_handle_task_id_positive().key(),
json_handle_encode_needs_handle("STRING").key(),
];
let mut seen = std::collections::HashSet::new();
for k in keys {
assert!(seen.insert(k), "duplicate key {k}");
}
}
#[test]
fn messages_match_canonical_wording() {
assert_eq!(
typing_bare_map().message(),
"bare `MAP` is not a declaration type: write a shape (`MAP<name: TYPE, ...>`) or `MAP<ANY>` for maps with unknown keys"
);
assert_eq!(
typing_bare_list().message(),
"bare `LIST` is not a declaration type: write a shape (`LIST<TYPE>`) or `LIST<ANY>` for lists with unknown elements"
);
assert_eq!(
typing_bare_handle().message(),
"bare `HANDLE` is not a declaration type: write `HANDLE<T>` for a known payload or `HANDLE<ANY>` for an unknown one"
);
assert_eq!(
typing_no_args("STRING").message(),
"`STRING` takes no type arguments"
);
assert_eq!(
typing_handle_arity().message(),
"`HANDLE` takes exactly one bare type argument"
);
assert_eq!(
typing_list_arity().message(),
"`LIST` takes exactly one bare type argument"
);
assert_eq!(
typing_empty_union().message(),
"empty union: no member shapes to admit"
);
assert_eq!(
typing_unregistered("LET $x", "NOPE", &["STRING".to_string()]).message(),
"LET $x declares unregistered type 'NOPE'; known types: STRING"
);
assert_eq!(
typing_void_position("LET $x").message(),
"LET $x declares VOID outside a return annotation: VOID is only a return type (or HANDLE<VOID> payload)"
);
assert_eq!(
check_unknown_option("F", "k", &["a", "b"]).message(),
"F() unknown option 'k' (expected: a, b)"
);
assert_eq!(
check_option_value(&reason_sample("F() option 'k': expected INT, got STRING"))
.message(),
"F() option 'k': expected INT, got STRING"
);
assert_eq!(
alias_cycle(&["A".to_string(), "B".to_string(), "A".to_string()]).message(),
"type alias cycle: A -> B -> A"
);
}
#[test]
fn func_and_std_messages_match_canonical_wording() {
assert_eq!(
func_export_unknown("F").message(),
"EXPORT `F` matches no defined script function or known host function"
);
assert!(
func_placeholder_unknown("M", "F", &["M::F".to_string()])
.message()
.contains("`M::F`")
);
assert_eq!(func_unknown("F").message(), "unknown function `F`");
assert_eq!(
func_arg_arity_exact("F", 1, 0).key(),
"dsl.func.arg_arity_exact"
);
assert_eq!(
func_arg_arity_exact("F", 1, 0).message(),
"F() expects 1 argument(s), got 0"
);
assert_eq!(
func_arg_arity_range("F", 1, 2, 3).key(),
"dsl.func.arg_arity_range"
);
assert_eq!(
func_arg_arity_range("F", 1, 2, 3).message(),
"F() expects 1 to 2 argument(s), got 3"
);
assert_eq!(
func_arg_must_be_string("F", "p").key(),
"dsl.func.arg_must_be_string"
);
assert_eq!(
func_arg_must_be_string("F", "p").message(),
"F() argument `$p` must be a STRING"
);
assert_eq!(
func_arg_must_be_one_of("F", "p", &["a", "b"], "c").key(),
"dsl.func.arg_must_be_one_of"
);
assert_eq!(
func_arg_must_be_one_of("F", "p", &["a", "b"], "c").message(),
"F() argument `$p` must be one of: a, b, got \"c\""
);
assert_eq!(
func_arg_must_be_finite("F", "p", f64::INFINITY).key(),
"dsl.func.arg_must_be_finite"
);
assert_eq!(
func_arg_must_be_finite("F", "p", f64::INFINITY).message(),
"F() argument `$p` must be finite, found FLOAT (inf)"
);
assert_eq!(
func_arg_must_be_bool("F", "p", "x").key(),
"dsl.func.arg_must_be_bool"
);
assert_eq!(
func_arg_must_be_bool("F", "p", "x").message(),
"F() argument `$p` must be a Bool, found \"x\""
);
assert_eq!(
func_arg_must_be_bool_or_string("F", "p", &crate::Value::string("x".to_string())).key(),
"dsl.func.arg_must_be_bool_or_string"
);
assert_eq!(
func_arg_must_be_bool_or_string("F", "p", &crate::Value::string("x".to_string()))
.message(),
"F() argument `$p` must be a Bool or String, found STRING(\"x\")"
);
assert_eq!(
func_arg_must_be_pipe("F", "p", "STRING").key(),
"dsl.func.arg_must_be_pipe"
);
assert_eq!(
func_arg_must_be_pipe("F", "p", "STRING").message(),
"F() argument `$p` must be a PIPE, got STRING"
);
assert_eq!(
func_arg_must_be_semaphore("F", "p", "STRING").key(),
"dsl.func.arg_must_be_semaphore"
);
assert_eq!(
func_arg_must_be_semaphore("F", "p", "STRING").message(),
"F() argument `$p` must be a SEMAPHORE, got STRING"
);
assert_eq!(
func_arg_must_be_handle("F", "p", "STRING").key(),
"dsl.func.arg_must_be_handle"
);
assert_eq!(
func_arg_must_be_handle("F", "p", "STRING").message(),
"F() argument `$p` must be a HANDLE, got STRING"
);
assert_eq!(
func_arg_expects_custom("F", "p", "T", "STRING").key(),
"dsl.func.arg_expects_custom"
);
assert_eq!(
func_arg_expects_custom("F", "p", "T", "STRING").message(),
"F() argument `$p` expects a T value, got STRING"
);
assert_eq!(eval_call_unknown("F", "").message(), "unknown function `F`");
assert_eq!(
eval_call_unknown("F", " (did you mean `X`?)").message(),
"unknown function `F` (did you mean `X`?)"
);
assert_eq!(
eval_call_unknown_rpn("F", "").message(),
"unknown function F"
);
assert_eq!(
eval_call_return_tag_failed("F", eval_remove_missing("x")).message(),
"function `F`: REMOVE x: no such file or directory"
);
assert_eq!(
eval_call_failed("F", &reason_sample("boom")).message(),
"function `F` failed"
);
assert_eq!(
eval_call_recursion_limit("BOOM").message(),
"recursion depth limit exceeded in FUNC BOOM"
);
assert_eq!(
eval_call_arity_exact("F", 1, 0).message(),
"F() expects 1 argument(s), got 0"
);
assert_eq!(
eval_call_arity_range("F", 1, 2, 3).message(),
"F() expects 1 to 2 argument(s), got 3"
);
assert_eq!(
eval_call_missing_param("p", "F").message(),
"internal error: missing non-optional param `$p` in F()"
);
assert_eq!(
eval_call_zero_value_failed("F", "p", eval_remove_missing("x")).message(),
"function `F` optional param `$p` has no zero value"
);
assert_eq!(
func_param_type("F", std_unknown_type("T")).message(),
"function `F`"
);
assert_eq!(
func_optional_param("F", "p", func_zero_value_missing("INT")).message(),
"function `F` optional param `$p`"
);
assert_eq!(
format!(
"{:#}",
anyhow::Error::new(func_param_type("F", std_unknown_type("T")))
),
"function `F`: unknown type `T`"
);
assert_eq!(
eval_call_flow_crosses_func(3, "BREAK", "F").message(),
"step 3: BREAK cannot cross function boundary (in F())"
);
assert_eq!(
eval_for_needs_key_value().message(),
"FOR loop over Map requires key and value bindings: FOR $k: STRING, $v: TYPE IN $map"
);
assert_eq!(
eval_for_map_key_type("INT").message(),
"FOR loop over MAP requires a STRING key variable, got INT"
);
assert_eq!(
eval_for_needs_list_or_map(&crate::Value::string("x".to_string())).message(),
"FOR loop requires a List or Map iterable, found STRING(\"x\")"
);
assert_eq!(
func_param_values_without_type("p", "F").message(),
"param 'p' of 'F' declares values without a type"
);
assert_eq!(
func_optional_before_required("p", "F").message(),
"param 'p' of 'F' is optional before a required param"
);
assert_eq!(
func_optional_without_map("p", "F").message(),
"param 'p' of 'F' is optional without a MAP type"
);
assert_eq!(std_unknown_type("T").message(), "unknown type `T`");
assert_eq!(
std_parse_args_arity(2).message(),
"PARSE_ARGS() expects 1 argument, got 2"
);
assert_eq!(
std_parse_args_needs_value("f").message(),
"PARSE_ARGS flag --f needs a value: use --f=<value>"
);
assert_eq!(
std_parse_args_duplicate_flag("f", Some("g")).message(),
"PARSE_ARGS duplicate flag --f/--g"
);
assert_eq!(
std_parse_args_missing_flag("f", None).message(),
"PARSE_ARGS missing required flag --f"
);
assert_eq!(
std_parse_args_arg_shape(&reason_sample(
"PARSE_FLAGS() argument `$args`: expected LIST<STRING>, got INT"
))
.message(),
"PARSE_FLAGS() argument `$args`: expected LIST<STRING>, got INT"
);
assert_eq!(
std_int_non_integer_float(1.5).message(),
"INT() requires an integer value, found FLOAT (1.5)"
);
assert_eq!(
std_int_bad_string("x").message(),
"INT() requires an integer string, found \"x\""
);
assert_eq!(
std_int_bad_type(&crate::Value::string("x".to_string())).message(),
"INT() requires an Int, Float, Bool, or String, found STRING(\"x\")"
);
assert_eq!(
std_float_non_finite_float(f64::INFINITY).message(),
"FLOAT() requires a finite value, found FLOAT (inf)"
);
assert_eq!(
std_float_bad_string("x").message(),
"FLOAT() requires a numeric string, found \"x\""
);
assert_eq!(
std_float_non_finite_string("inf").message(),
"FLOAT() requires a finite value, found \"inf\""
);
assert_eq!(
std_float_bad_type(&crate::Value::string("x".to_string())).message(),
"FLOAT() requires an Int, Float, or String, found STRING(\"x\")"
);
assert_eq!(
eval_math_stack_underflow().message(),
"compiled math stack underflow"
);
assert_eq!(
eval_math_stack_len(2).message(),
"compiled math left 2 values on the stack"
);
assert_eq!(
eval_arith_overflow_div_zero().message(),
"arithmetic error: integer overflow or division by zero"
);
assert_eq!(
eval_arith_needs_numeric(
&crate::Value::string("x".to_string()),
&crate::Value::string("y".to_string()),
)
.message(),
"Type Error: arithmetic requires Int or Float, found STRING(\"x\") and STRING(\"y\")"
);
assert_eq!(
eval_float_div_zero().message(),
"arithmetic error: float division by zero"
);
assert_eq!(
eval_non_finite_result().message(),
"arithmetic error: non-finite float result"
);
assert_eq!(
eval_neg_overflow().message(),
"arithmetic error: integer overflow"
);
assert_eq!(
eval_neg_needs_numeric(&crate::Value::string("x".to_string())).message(),
"Type Error: unary '-' requires Int or Float, found STRING(\"x\")"
);
assert_eq!(
eval_condition_needs_bool(&crate::Value::string("x".to_string())).message(),
"Type Error: condition must be a Bool, found STRING(\"x\")"
);
assert_eq!(
eval_expected_int("12x").message(),
"expected int, got \"12x\""
);
assert_eq!(
eval_int_arg_resolve(&reason_sample("undefined variable `$x`")).message(),
"undefined variable `$x`"
);
assert_eq!(
eval_dispatch_failed(&reason_sample("boom")).message(),
"boom"
);
assert_eq!(
eval_pipe_assertion_read_failed(&reason_sample("boom")).message(),
"step pipe assertion cannot read pipe: boom"
);
assert_eq!(
eval_with_io_unexpanded().message(),
"WITH_IO block should have been expanded during parsing"
);
assert_eq!(
eval_with_io_geometry_needs_tty().message(),
"WITH_IO [rows]/[cols] need [tty] on the same step: geometry without a terminal has nothing to size"
);
assert_eq!(
eval_with_io_tty_no_stderr().message(),
"WITH_IO [tty] cannot bind stderr: the pty master carries stdout and stderr interleaved, so the two streams cannot demultiplex"
);
assert_eq!(
eval_with_io_tty_needs_run().message(),
"WITH_IO [tty] only wraps a RUN step: the pty master is one interleaved child stream, so terminal-unaware commands cannot run under it"
);
assert_eq!(
eval_with_io_duplicate_stream("stdin").message(),
"WITH_IO declared stdin more than once"
);
assert_eq!(
eval_pipe_handle_mismatch("STRING", &crate::Value::string("x".to_string())).message(),
"TypeMismatch: expected PIPE, got STRING (STRING(\"x\"))"
);
assert_eq!(eval_async_cancelled().message(), "ASYNC task cancelled");
assert_eq!(
eval_flow_crosses_remote(3, "BREAK").message(),
"step 3: BREAK cannot cross a REMOTE boundary"
);
assert_eq!(
eval_stdin_lock_failed("READ").message(),
"failed to lock stdin for READ"
);
assert_eq!(
eval_stdin_read_failed(None, &std::io::Error::other("boom")).message(),
"failed to read from stdin: boom"
);
assert_eq!(
eval_stdin_read_failed(Some("WRITE"), &std::io::Error::other("boom")).message(),
"failed to read from stdin for WRITE: boom"
);
assert_eq!(
eval_assert_stdin_overflow("ASSERT_EQ").message(),
"ASSERT_EQ stdin exceeded the 8 MiB exact buffer; assert via pipe targets or harness expect.stdout"
);
assert_eq!(
eval_assert_stdout_overflow("ASSERT_EQ").message(),
"ASSERT_EQ stdout overflowed the 8 MiB exact buffer; assert via pipe targets or harness expect.stdout"
);
assert_eq!(
eval_assert_no_exact_capture("ASSERT_EQ").message(),
"ASSERT_EQ stdout has no exact capture registered"
);
assert_eq!(
eval_assert_hash_mismatch("ASSERT_EQ", "a", "b").message(),
"ASSERT_EQ --hash mismatch: expected a, computed b"
);
assert_eq!(
eval_assert_hash_match("ASSERT_NE", "a").message(),
"ASSERT_NE --hash match: content matches a"
);
assert_eq!(
eval_assert_stream_mismatch("ASSERT_EQ", None, "a").message(),
"ASSERT_EQ stream mismatch\nexpected: None\nactual: \"a\""
);
assert_eq!(
eval_assert_stream_mismatch_text("ASSERT_EQ", "a", "b").message(),
"ASSERT_EQ stream mismatch\nexpected: \"a\"\nactual: \"b\""
);
assert_eq!(
eval_assert_stream_unexpected_equal("ASSERT_NE", "a").message(),
"ASSERT_NE stream unexpectedly equal: \"a\""
);
assert_eq!(
eval_assert_stderr_unsupported("ASSERT_EQ").message(),
"ASSERT_EQ over stderr is not supported; use ASSERT_CONTAINS stderr ..."
);
assert_eq!(
eval_assert_requires_expected("ASSERT_EQ").message(),
"ASSERT_EQ requires an expected value"
);
assert_eq!(
eval_assert_pipe_mismatch_text("ASSERT_EQ", "a", "b").message(),
"ASSERT_EQ pipe mismatch\nexpected: \"a\"\nactual: \"b\""
);
assert_eq!(
eval_assert_pipe_unexpected_equal("ASSERT_NE", "a").message(),
"ASSERT_NE pipe unexpectedly equal: \"a\""
);
assert_eq!(
eval_assert_contains_str_mismatch("ASSERT_CONTAINS", "n", "h").message(),
"ASSERT_CONTAINS did not contain 'n'; actual: \"h\""
);
assert_eq!(
eval_assert_contains_missing("ASSERT_CONTAINS", "n").message(),
"ASSERT_CONTAINS did not contain 'n'"
);
assert_eq!(
eval_assert_contains_emitted_mismatch("ASSERT_CONTAINS", "n", "e ").message(),
"ASSERT_CONTAINS did not contain 'n'; emitted:\ne"
);
assert_eq!(
eval_assert_contains_pipe_mismatch("ASSERT_CONTAINS", "n", "h").message(),
"ASSERT_CONTAINS did not contain 'n'; pipe held \"h\""
);
assert_eq!(eval_break_outside_loop().message(), "BREAK outside loop");
assert_eq!(
eval_continue_outside_loop().message(),
"CONTINUE outside loop"
);
assert_eq!(
eval_capture_flow_outside_loop(1, "BREAK").message(),
"step 1: BREAK outside loop (cannot be captured)"
);
assert_eq!(
eval_capture_return_outside_function(1).message(),
"step 1: RETURN outside function (cannot be captured)"
);
assert_eq!(
eval_block_flow_crosses_block(1, "BREAK").message(),
"step 1: BREAK cannot cross block boundary"
);
assert_eq!(
eval_async_flow_crosses_async(1, "RETURN").message(),
"step 1: RETURN cannot cross ASYNC boundary"
);
assert_eq!(
eval_capture_with_io_stdout("LET").message(),
"LET capture cannot use WITH_IO [stdout=$var]; the capture binds the RETURN value"
);
assert_eq!(
eval_capture_not_utf8("LET", "a", eval_remove_missing("x")).message(),
"LET $a capture is not valid UTF-8"
);
assert_eq!(
eval_with_io_tty_live_pipe("stdin").message(),
"WITH_IO [tty] stdin cannot arrive on a live OS pipe; bind a script pipe with stdin=$var"
);
assert_eq!(
eval_with_io_tty_live_pipe("stdout").message(),
"WITH_IO [tty] stdout cannot arrive on a live OS pipe; bind a script pipe with stdout=$var"
);
assert_eq!(
eval_write_live_pipe("stdout").message(),
"cannot write DSL output to a live OS pipe"
);
assert_eq!(
eval_write_live_pipe("stderr").message(),
"cannot write DSL output to a live OS pipe"
);
assert_eq!(
eval_async_entry_unavailable().message(),
"ASYNC task entry unavailable"
);
assert_eq!(
eval_task_var_undefined("t").message(),
"variable '$t' is not defined"
);
assert_eq!(
eval_task_not_handle("t").message(),
"variable '$t' is not a task handle"
);
assert_eq!(
eval_task_not_found("$t").message(),
"task handle for '$t' was not found or has already been awaited"
);
assert_eq!(
eval_await_cancelled("t").message(),
"AWAIT task '$t' was cancelled"
);
assert_eq!(
eval_await_member_not_handle("$w[0]", "INT").message(),
"AWAIT '$w[0]' is not a task handle, got INT"
);
assert_eq!(
eval_await_timeout("t").message(),
"AWAIT task '$t' interrupted by TIMEOUT"
);
assert!(
eval_await_exit_status("t", &exit_status_sample())
.message()
.starts_with("AWAIT task '$t' failed with status ")
);
assert_eq!(
eval_await_fell_off("LET", "o", "t").message(),
"LET $o = AWAIT $t fell off the end without RETURN: the task body can return a value on some path but this run produced none"
);
assert_eq!(
eval_cancel_gone("t").message(),
"CANCEL: task '$t' has already been awaited or does not exist"
);
assert_eq!(
eval_cancel_already("t").message(),
"CANCEL: task '$t' was already cancelled"
);
assert_eq!(
eval_timeout_deadline("1s").message(),
"TIMEOUT after 1s — deadline exceeded"
);
assert_eq!(eval_inside_isolated().message(), "inside ISOLATED block");
assert_eq!(
eval_isolated_outside_allowlist().message(),
"isolated allowlist outside ISOLATED"
);
assert_eq!(
eval_placeholder_miss_text("placeholder miss").message(),
"placeholder miss"
);
assert_eq!(
eval_remote_copy_outside_guest().message(),
"COPY --from-host and --to-host execute only inside a remote guest session"
);
assert_eq!(
eval_remote_rewind_failed(&std::io::Error::other("boom")).message(),
"transfer stage rewind failed: boom"
);
assert_eq!(
eval_remote_push_file_read_failed(&std::io::Error::other("boom")).message(),
"REMOTE push file read failed: boom"
);
assert_eq!(
eval_remote_push_file_write_failed(&std::io::Error::other("boom")).message(),
"REMOTE push file write failed: boom"
);
assert_eq!(
eval_remote_unknown_var("t", "v").message(),
"REMOTE 't' uses unknown variable $v"
);
assert_eq!(
eval_remote_unrenderable_var("v", "HANDLE", "t").message(),
"cannot pass $v: HANDLE into REMOTE 't' (pass bytes via WITH_IO, files via the workspace)"
);
assert_eq!(
eval_remote_unknown_env("t", "N").message(),
"REMOTE 't' uses unknown env N"
);
assert_eq!(
eval_remote_fetch_missing("a/b", None).message(),
"REMOTE fetch source missing: a/b"
);
assert_eq!(
eval_remote_fetch_missing("a/b", Some(&reason_sample("gone"))).message(),
"REMOTE fetch source missing: a/b (gone)"
);
assert_eq!(
eval_remote_fetch_entry_cap("a/b", 100_000).message(),
"REMOTE fetch hit the 100000 entry cap: a/b names too many paths"
);
assert_eq!(
eval_remote_fetch_no_file_name("a/b").message(),
"REMOTE fetch source has no file name: a/b"
);
assert_eq!(
eval_remote_no_session("t").message(),
"REMOTE 't' has no registered session (bind it with --remote t=\"<command>\")"
);
assert_eq!(
eval_remote_exit_status("t", 3).message(),
"REMOTE 't' exited with code 3"
);
assert_eq!(
eval_remote_transport_failed("t").message(),
"REMOTE 't' transport failed"
);
assert_eq!(
eval_remote_push_destination_escapes("a", &reason_sample("gone")).message(),
"REMOTE push symlink destination \"a\" escapes the workspace: gone"
);
assert_eq!(
eval_remote_push_target_outside("a", &reason_sample("gone")).message(),
"REMOTE push symlink \"a\" points outside the workspace: gone"
);
assert_eq!(
eval_remote_push_symlink_over_dir("a").message(),
"REMOTE sync-back cannot replace directory \"a\" with a symlink"
);
assert_eq!(
eval_run_cancelled("echo hi").message(),
"RUN echo hi interrupted by cancellation"
);
assert_eq!(
eval_run_argv_cancelled(&["echo".to_string()]).message(),
"RUN [\"echo\"] interrupted by cancellation"
);
assert_eq!(
eval_run_unexpected_capture("echo hi").message(),
"RUN echo hi unexpectedly captured output"
);
assert_eq!(
eval_run_needs_program("[]").message(),
"RUN [] needs at least a program"
);
assert_eq!(
eval_run_pty_exit_status("echo hi", 1).message(),
"RUN echo hi exited with status 1"
);
assert_eq!(
eval_run_exec_requires_arg().message(),
"RUN exec form requires at least one argument"
);
assert!(
eval_pipe_not_utf8("ASSERT", &String::from_utf8(vec![0xff]).unwrap_err())
.message()
.starts_with("ASSERT pipe content is not UTF-8: ")
);
assert!(
eval_run_spawn_failed("echo hi", &reason_sample("boom"))
.message()
.starts_with("RUN echo hi: ")
);
assert!(
eval_run_argv_spawn_failed(&["echo".to_string()], &reason_sample("boom"))
.message()
.starts_with("RUN [\"echo\"]: ")
);
assert_eq!(
eval_run_exec_pipe_arg().message(),
"cannot pass PIPE as a command argument: pipes carry streams between steps, not text. Capture the producing step's output with LET $var: STRING = ... instead."
);
assert_eq!(
eval_run_exec_semaphore_arg().message(),
"cannot pass SEMAPHORE as a command argument: semaphores coordinate task access between steps, not text."
);
assert_eq!(
eval_run_exec_permit_arg().message(),
"cannot pass PERMIT as a command argument: permits grant scoped task access, not text."
);
assert_eq!(
eval_run_exec_element_needs_string("map").message(),
"RUN exec form element must be a string, got map"
);
assert_eq!(
eval_run_exec_element_needs_string("task handle task#7").message(),
"RUN exec form element must be a string, got task handle task#7"
);
assert_eq!(
eval_sleep_cancelled().message(),
"SLEEP interrupted by cancellation"
);
assert!(
eval_copy_failed("a", "b", &reason_sample("boom"))
.message()
.starts_with("COPY a b: ")
);
assert!(
eval_copy_git_failed("r", "a", "b", &reason_sample("boom"))
.message()
.starts_with("COPY_GIT r a b: ")
);
assert_eq!(
eval_copy_no_file_name("/x").message(),
"COPY source has no file name: /x"
);
assert!(
eval_copy_destination_escapes("/x", &reason_sample("boom"))
.message()
.starts_with("COPY destination escapes root: /x: ")
);
assert_eq!(
eval_symlink_failed("a", "b", &reason_sample("boom")).message(),
"SYMLINK a b"
);
assert_eq!(
eval_symlink_no_file_name("a").message(),
"SYMLINK source has no file name: a"
);
assert_eq!(
eval_archive_failed("a", "b", &reason_sample("boom")).message(),
"ARCHIVE a b"
);
assert_eq!(
eval_archive_no_file_name("a", "b", "d").message(),
"ARCHIVE a b: source has no file name: d"
);
assert_eq!(
eval_archive_refuses_symlink_source("a", "b").message(),
"ARCHIVE a b: refuses to pack symlink source \"a\""
);
assert_eq!(
eval_archive_refuses_symlink("a", "b", "c").message(),
"ARCHIVE a b: refuses to pack symlink \"c\""
);
assert_eq!(
eval_archive_destination_is_source("a", "a").message(),
"ARCHIVE a a: destination \"a\" cannot be the source itself"
);
assert_eq!(
eval_archive_destination_inside_tree("a", "a/b").message(),
"ARCHIVE a a/b: destination \"a/b\" cannot overwrite inside the packed tree"
);
assert_eq!(
eval_unarchive_failed("a", "b", &reason_sample("boom")).message(),
"UNARCHIVE a b"
);
assert_eq!(
eval_unarchive_member_failed("a", "b", &reason_sample("boom")).message(),
"UNARCHIVE a b: member"
);
assert_eq!(
eval_unarchive_bad_max_bytes(
"a",
"b",
"r",
oxdock_parser::diagnostics::invalid_byte_count("r")
)
.message(),
"UNARCHIVE a b: --max-bytes \"r\""
);
assert_eq!(
format!(
"{:#}",
anyhow::Error::new(eval_unarchive_bad_max_bytes(
"a",
"b",
"r",
oxdock_parser::diagnostics::invalid_byte_count("r")
))
),
"UNARCHIVE a b: --max-bytes \"r\": invalid byte count: r"
);
assert_eq!(
eval_unarchive_expansion_cap("a", "b", 8, "p").message(),
"UNARCHIVE a b: member: archive exceeds the 8-byte expansion cap at \"p\""
);
assert_eq!(
eval_unarchive_refuses_symlink("a", "b", "p", "t").message(),
"UNARCHIVE a b: member: refuses symlink member \"p\" -> \"t\""
);
assert_eq!(
eval_unarchive_restore_mode_failed("a", "b", &reason_sample("boom")).message(),
"UNARCHIVE a b: restoring mode"
);
assert_eq!(
eval_workdir_failed("sub", &reason_sample("boom")).message(),
"WORKDIR sub"
);
assert_eq!(
eval_mkdir_resolve_failed("d", &reason_sample("boom")).message(),
"MKDIR d"
);
assert_eq!(
eval_mkdir_create_failed("/x", &reason_sample("boom")).message(),
"failed to create dir /x"
);
assert_eq!(
eval_set_executable_failed("bin", &reason_sample("boom")).message(),
"SET_EXECUTABLE bin"
);
assert_eq!(
eval_ls_resolve_failed(Some("dir"), &reason_sample("boom")).message(),
"LS dir"
);
assert_eq!(
eval_ls_resolve_failed(None, &reason_sample("boom")).message(),
"LS"
);
assert_eq!(
eval_ls_read_failed("/x", &reason_sample("boom")).message(),
"LS /x"
);
assert_eq!(
eval_read_resolve_failed("f", &reason_sample("boom")).message(),
"READ f"
);
assert_eq!(
eval_read_open_failed("/x", &reason_sample("boom")).message(),
"failed to open /x"
);
assert_eq!(
eval_read_file_failed(&std::io::Error::other("boom")).message(),
"failed to read from file"
);
assert_eq!(
eval_read_write_failed(&std::io::Error::other("boom")).message(),
"failed to write to output"
);
assert_eq!(
eval_read_needs_stdin().message(),
"READ requires stdin (use WITH_IO [stdin=...] READ)"
);
assert_eq!(
eval_read_line_needs_stdin().message(),
"READ_LINE requires stdin (use WITH_IO [stdin=...] READ_LINE $var)"
);
assert_eq!(
eval_read_line_not_utf8(&String::from_utf8(vec![0xff]).unwrap_err()).message(),
"READ_LINE received non-UTF8 bytes"
);
assert_eq!(
eval_write_resolve_failed("f", &reason_sample("boom")).message(),
"WRITE f"
);
assert_eq!(
eval_ensure_parent_failed("/x", &reason_sample("boom")).message(),
"failed to create parent for /x"
);
assert_eq!(
eval_write_file_failed("/x", &reason_sample("boom")).message(),
"failed to write /x"
);
assert_eq!(
eval_write_needs_stdin("f").message(),
"WRITE f requires stdin (use WITH_IO [stdin=...] WRITE)"
);
assert_eq!(
eval_write_open_failed("/x", &reason_sample("boom")).message(),
"failed to open /x for writing"
);
assert_eq!(
eval_write_stream_failed("/x", &reason_sample("boom")).message(),
"failed to write to /x"
);
assert_eq!(
eval_append_resolve_failed("f", &reason_sample("boom")).message(),
"APPEND f"
);
assert_eq!(
eval_append_failed("/x", &reason_sample("boom")).message(),
"failed to append to /x"
);
assert_eq!(
eval_append_needs_stdin("f").message(),
"APPEND f requires stdin (use WITH_IO [stdin=...] APPEND)"
);
assert_eq!(
eval_append_open_failed("/x", &reason_sample("boom")).message(),
"failed to open /x for appending"
);
assert_eq!(
eval_append_line_resolve_failed("f", &reason_sample("boom")).message(),
"APPEND_LINE f"
);
assert_eq!(
eval_remove_failed("f", &reason_sample("boom")).message(),
"REMOVE f"
);
assert_eq!(
eval_remove_protected("f").message(),
"REMOVE f: cannot remove working directory or workspace root"
);
assert_eq!(
eval_remove_missing("f").message(),
"REMOVE f: no such file or directory"
);
assert_eq!(
eval_remove_link_changed("f").message(),
"REMOVE f: link changed during removal"
);
assert_eq!(
eval_remove_not_empty_failed("f", &reason_sample("boom")).message(),
"REMOVE f: directory not empty (use --recursive)"
);
assert_eq!(
eval_expand_resolve_failed("f", &reason_sample("boom")).message(),
"EXPAND f"
);
assert_eq!(
eval_expand_read_failed("/x", &reason_sample("boom")).message(),
"failed to read /x"
);
assert_eq!(
eval_expand_write_failed(&std::io::Error::other("boom")).message(),
"failed to write output"
);
assert_eq!(
eval_stream_write_failed(&std::io::Error::other("boom")).message(),
"boom"
);
assert_eq!(
eval_expand_needs_stdin().message(),
"EXPAND requires stdin when no file path is given (use WITH_IO [stdin=...] EXPAND)"
);
assert_eq!(
eval_install_failed("a", "b", &reason_sample("boom")).message(),
"INSTALL a b"
);
assert_eq!(
eval_prompt_no_answer("hi").message(),
"PROMPT hi: non-TTY stdin has no answer and no default"
);
assert_eq!(
eval_prompt_write_failed("hi", &std::io::Error::other("boom")).message(),
"PROMPT hi: failed to write prompt"
);
assert_eq!(
eval_prompt_flush_failed("hi", &std::io::Error::other("boom")).message(),
"PROMPT hi: failed to flush prompt"
);
assert_eq!(
eval_prompt_read_failed("hi", &std::io::Error::other("boom")).message(),
"PROMPT hi: failed reading stdin"
);
assert_eq!(
eval_prompt_eof("hi").message(),
"PROMPT hi: EOF on stdin before any input"
);
assert_eq!(
eval_prompt_bind_failed("v", eval_remove_missing("x")).message(),
"PROMPT $v"
);
assert_eq!(
eval_list_append_failed("v", eval_remove_missing("x")).message(),
"LIST_APPEND $v"
);
assert!(
eval_run_exit_status("echo hi", &exit_status_sample())
.message()
.starts_with("RUN echo hi exited with status ")
);
assert!(
eval_run_argv_exit_status(&["echo".to_string()], &exit_status_sample())
.message()
.starts_with("RUN [\"echo\"] exited with status ")
);
assert!(
eval_async_exit_status(None, &exit_status_sample())
.message()
.starts_with("ASYNC process exited with status ")
);
assert!(
eval_async_exit_status(Some(7), &exit_status_sample())
.message()
.starts_with("named ASYNC task 7 exited with status ")
);
assert_eq!(
eval_arg_expr_needs_step_ctx(&Expr::Env("X".to_string())).message(),
"Arg::Expr cannot be resolved without StepCtx: Env(\"X\")"
);
assert_eq!(
eval_arg_expand_failed(eval_template_placeholder_miss("undefined variable `$x`"))
.message(),
"undefined variable `$x`"
);
assert_eq!(
coerce_type_mismatch(
"coercion",
&TypeTag::Int,
&crate::Value::string("x".to_string()),
)
.message(),
"coercion: TypeMismatch: expected INT, got STRING"
);
assert_eq!(
coerce_string_to_pipe("x").message(),
"TypeMismatch: expected PIPE, got STRING (\"x\"); declare LET $x: PIPE and pass $x"
);
assert_eq!(
coerce_pipe_to_string().message(),
"coercion: TypeMismatch: expected STRING, got PIPE: pipes carry streams between steps, not text. Capture the producing step's output with LET $var: STRING = ... instead."
);
assert_eq!(coerce_check_failed(&reason_sample("x")).message(), "x");
assert_eq!(eval_host_return_failed(&reason_sample("x")).message(), "x");
assert_eq!(
eval_scope_underflow().message(),
"scope stack underflow during pop"
);
assert_eq!(
eval_redeclare_var("x").message(),
"redeclaration error: $x already declared in this scope; use $x = ... to mutate"
);
assert_eq!(
eval_redeclare_const("x").message(),
"redeclaration error: x already declared in this scope; CONST bindings are immutable and cannot redeclare it"
);
assert_eq!(
eval_no_var_scope().message(),
"no variable scope for declaration"
);
assert_eq!(
eval_const_mutation("$x").message(),
"cannot mutate CONST $x: CONST bindings are deeply immutable"
);
assert_eq!(
eval_undeclared_declare("x", "TYPE").message(),
"undeclared variable $x: declare it first with LET $x: TYPE = ..."
);
assert_eq!(eval_undeclared("x").message(), "undeclared variable $x");
assert_eq!(
eval_list_not_list("x", "STRING").message(),
"LIST_APPEND $x: variable is STRING, not LIST"
);
assert_eq!(
eval_list_value_not_list("x").message(),
"LIST_APPEND $x: variable is not a LIST value"
);
assert_eq!(eval_list_element_failed(&reason_sample("x")).message(), "x");
assert_eq!(
eval_scratch_materialize_failed(&reason_sample("x")).message(),
"x"
);
assert_eq!(
eval_task_cap_exceeded(64).message(),
"concurrency limit exceeded: maximum of 64 running background tasks allowed"
);
assert_eq!(
eval_const_arg_keypath().message(),
"key paths on $ALIAS::NAME are not supported; copy to a local with LET or CONST first"
);
assert_eq!(
eval_const_arg_bare_sigil("foo").message(),
"bare `foo` never reads a binding here; use `$foo`"
);
assert_eq!(
eval_template_missing_key("foo", false).message(),
"undefined script variable: 'foo'; did you mean '$foo'?"
);
assert_eq!(
eval_template_missing_key("foo", true).message(),
"undefined script variable: 'foo'; did you mean 'env:foo' (environment variable)?"
);
assert_eq!(
eval_template_empty_placeholder().message(),
"empty template placeholder"
);
assert_eq!(
eval_template_invalid_key("foo").message(),
"invalid placeholder key: '$foo'"
);
assert_eq!(
eval_template_empty_env().message(),
"undefined environment variable: ''"
);
assert_eq!(
eval_template_keypath().message(),
"key paths on $ALIAS::NAME are not supported; copy to a local with LET or CONST first"
);
assert_eq!(
eval_template_bare_sigil("foo").message(),
"bare `foo` never reads a binding here; use `$foo`"
);
assert_eq!(
eval_template_placeholder_miss("unknown placeholder function `M::F`").message(),
"unknown placeholder function `M::F`"
);
assert_eq!(
std_pipe_read_failed("TEXT_REPLACE", &reason_sample("denied")).message(),
"TEXT_REPLACE cannot read PIPE input: denied"
);
assert_eq!(
std_pipe_create_failed("TEXT_REPLACE", &reason_sample("denied")).message(),
"TEXT_REPLACE cannot create PIPE output: denied"
);
assert_eq!(
std_pipe_spawn_failed("TEXT_REPLACE", &std::io::Error::other("denied"),).message(),
"TEXT_REPLACE cannot spawn pump thread: denied"
);
assert_eq!(
std_pipe_reader_lock_poisoned("TEXT_REPLACE").message(),
"TEXT_REPLACE pipe reader lock poisoned"
);
assert_eq!(
std_pipe_writer_lock_poisoned("TEXT_REPLACE").message(),
"TEXT_REPLACE pipe writer lock poisoned"
);
assert_eq!(
std_pump_not_utf8().message(),
"text pump input is not valid UTF-8"
);
assert_eq!(
std_pump_writer_lock_poisoned().message(),
"text pump writer lock poisoned"
);
assert_eq!(
std_pump_write_failed(&std::io::Error::other("denied")).message(),
"text pump write failed: denied"
);
assert_eq!(
std_pump_spill_drain_failed(&std::io::Error::other("denied")).message(),
"text pump spill drain failed: denied"
);
assert_eq!(
std_pump_spill_failed(&std::io::Error::other("denied")).message(),
"text pump spill failed: denied"
);
assert_eq!(
std_pump_downstream_closed().message(),
"text pump downstream closed its read end"
);
assert_eq!(
std_pipe_handle_spent().message(),
"OS pipe handle has already been consumed by another binding; declare a fresh LET $x: PIPE for a new session"
);
assert_eq!(
std_pipe_needs_pipe("TEXT_REPLACE", "STRING").message(),
"host TEXT_REPLACE needs a PIPE value, got STRING"
);
assert_eq!(
std_pipe_close_needs_script().message(),
"host close_pipe needs a script-materialized pipe (unbound and OS handles cannot be force-closed)"
);
assert_eq!(
std_assert_lock_poisoned("TEXT_REPLACE").message(),
"TEXT_REPLACE poisoned"
);
assert_eq!(
std_pipe_chunk_read_failed("TEXT_REPLACE", &std::io::Error::other("denied"),).message(),
"TEXT_REPLACE cannot read PIPE input: denied"
);
assert_eq!(
std_pipe_input_not_utf8("TEXT_REPLACE").message(),
"TEXT_REPLACE PIPE input is not valid UTF-8"
);
assert_eq!(
std_pipe_spill_failed("TEXT_REPLACE", &std::io::Error::other("denied"),).message(),
"TEXT_REPLACE PIPE input exceeds the spill backlog: denied"
);
assert_eq!(
std_pipe_write_failed("TEXT_REPLACE", &std::io::Error::other("denied"),).message(),
"TEXT_REPLACE cannot write PIPE output: denied"
);
assert_eq!(
eval_compare_equality_shape().message(),
"internal error: equality shape"
);
assert_eq!(
eval_ordering_needs_numeric(
&crate::Value::string("x".to_string()),
&crate::Value::string("y".to_string()),
)
.message(),
"Type Error: ordering comparison requires Int or Float, found STRING(\"x\") and STRING(\"y\")"
);
assert_eq!(
eval_unstaged_int_boundary(9223372036854775808).message(),
"internal error: unstaged integer boundary 9223372036854775808"
);
assert_eq!(
eval_undefined_var("nope").message(),
"undefined variable $nope"
);
assert_eq!(
eval_key_not_found("k").message(),
"Key 'k' not found in map"
);
assert_eq!(
eval_invalid_array_index("k").message(),
"Invalid array index 'k'"
);
assert_eq!(
eval_index_out_of_bounds(7).message(),
"Index 7 out of bounds"
);
assert_eq!(
eval_traverse_scalar("k").message(),
"Cannot traverse into scalar value at key 'k'"
);
assert_eq!(
eval_path_type_needs_arg().message(),
"PATH_TYPE requires a path argument"
);
assert_eq!(
eval_path_type_needs_string().message(),
"PATH_TYPE path argument must evaluate to a string"
);
assert_eq!(
eval_is_exec_needs_arg().message(),
"IS_EXEC requires a name argument"
);
assert_eq!(
eval_is_exec_needs_string().message(),
"IS_EXEC name argument must evaluate to a string"
);
assert_eq!(
eval_path_writable_needs_arg().message(),
"PATH_WRITABLE requires a path argument"
);
assert_eq!(
eval_path_writable_needs_string().message(),
"PATH_WRITABLE path argument must evaluate to a string"
);
assert_eq!(
eval_path_resolve_failed("p", &reason_sample("denied")).message(),
"failed to resolve path 'p': denied"
);
assert_eq!(
eval_workdir_resolve_failed(&reason_sample("denied")).message(),
"failed to resolve working directory: denied"
);
assert!(
std_text_invalid_pattern("TEXT_MATCH", "[", ®ex_err_sample())
.message()
.starts_with("TEXT_MATCH invalid pattern \"[\": "),
"pattern failure must keep its prefix"
);
assert_eq!(
std_text_needs_search("TEXT_REPLACE").message(),
"TEXT_REPLACE needs a non-empty search string"
);
assert_eq!(
std_text_needs_needle("TEXT_COUNT").message(),
"TEXT_COUNT needs a non-empty needle"
);
assert_eq!(
std_text_needs_one_based_start("TEXT_LINES_RANGE", 0).message(),
"TEXT_LINES_RANGE needs a 1-based start line, got 0"
);
assert_eq!(
std_text_needs_ordered_range("TEXT_LINES_RANGE", 3, 2).message(),
"TEXT_LINES_RANGE needs start <= end, got 3..=2"
);
assert_eq!(
std_pipe_needs_step_io("TEXT_REPLACE").message(),
"TEXT_REPLACE on PIPE input needs step IO, unavailable to placeholder calls; pass a STRING there"
);
assert_eq!(
std_bool_cannot_coerce("BOOL_OR", "x").message(),
"BOOL_OR cannot coerce \"x\" to BOOL"
);
assert_eq!(
std_contains_haystack_type("INT").message(),
"CONTAINS needs a STRING or LIST haystack, found `INT`"
);
assert_eq!(
std_to_json_non_finite_float(f64::INFINITY).message(),
"TO_JSON cannot encode non-finite float inf"
);
assert_eq!(
std_to_json_unencodable("VOID").message(),
"TO_JSON cannot encode VOID values; use STRING, INT, FLOAT, BOOL, LIST, or MAP"
);
assert!(
std_to_json_encode_failed(
&serde_json::from_str::<serde_json::Value>("{bad").unwrap_err(),
)
.message()
.starts_with("encode JSON: "),
"json encode failure must keep its prefix"
);
assert_eq!(
std_load_toml_needs_arg().message(),
"LOAD_TOML requires a path argument"
);
assert_eq!(
std_load_toml_needs_string().message(),
"LOAD_TOML path argument must evaluate to a string"
);
assert_eq!(
std_load_toml_resolve_failed("p", &reason_sample("denied")).message(),
"failed to resolve TOML path 'p': denied"
);
assert_eq!(
std_load_toml_read_failed("p", &reason_sample("denied")).message(),
"failed to read TOML file 'p': denied"
);
assert_eq!(
std_load_toml_not_utf8("p", &utf8_err_sample()).message(),
"invalid UTF-8 in TOML file 'p': invalid utf-8 sequence of 1 bytes from index 0"
);
assert_eq!(
std_parse_toml_needs_string("INT").message(),
"PARSE_TOML expects a STRING, got INT"
);
assert_eq!(
std_load_json_needs_arg().message(),
"LOAD_JSON requires a path argument"
);
assert_eq!(
std_load_json_needs_string().message(),
"LOAD_JSON path argument must evaluate to a string"
);
assert_eq!(
std_load_json_resolve_failed("p", &reason_sample("denied")).message(),
"failed to resolve JSON path 'p': denied"
);
assert_eq!(
std_load_json_read_failed("p", &reason_sample("denied")).message(),
"failed to read JSON file 'p': denied"
);
assert_eq!(
std_load_json_not_utf8("p", &utf8_err_sample()).message(),
"invalid UTF-8 in JSON file 'p': invalid utf-8 sequence of 1 bytes from index 0"
);
assert_eq!(
std_parse_json_needs_string("INT").message(),
"PARSE_JSON expects a STRING, got INT"
);
assert_eq!(
std_glob_needs_arg().message(),
"GLOB requires a pattern argument"
);
assert_eq!(
std_glob_needs_string().message(),
"GLOB pattern argument must evaluate to a string"
);
assert_eq!(
std_glob_resolve_failed(&reason_sample("denied")).message(),
"denied"
);
assert_eq!(
std_glob_list_failed(&std::io::Error::other("denied")).message(),
"denied"
);
assert_eq!(
std_has_key_needs_map("INT").message(),
"HAS_KEY expects a MAP as its first argument, got INT"
);
assert_eq!(
std_map_set_needs_map("INT").message(),
"MAP_SET expects a MAP as its first argument, got INT"
);
assert_eq!(
std_map_set_duplicate("k").message(),
"MAP_SET duplicate key 'k'"
);
assert_eq!(
std_merge_maps_needs_list("INT").message(),
"MERGE_MAPS expects a LIST of MAPs, got INT"
);
assert_eq!(
std_merge_maps_needs_map(1, "INT").message(),
"MERGE_MAPS element 1 is INT, not MAP"
);
assert_eq!(
std_merge_maps_duplicate("k").message(),
"duplicate values key 'k'; later files must not repeat it under fail_on_duplicate"
);
assert!(
std_json_parse_failed(&serde_json::from_str::<serde_json::Value>("{bad").unwrap_err())
.message()
.starts_with("JSON parse error: "),
"json failure must keep its prefix"
);
assert!(
std_toml_parse_failed(&toml::from_str::<serde_json::Value>("a = ").unwrap_err())
.message()
.starts_with("TOML parse error: "),
"toml failure must keep its prefix"
);
assert_eq!(
std_base64_encode_needs_string("INT").message(),
"BASE64_ENCODE expects a STRING, got INT"
);
assert_eq!(
std_base64_decode_needs_string("INT").message(),
"BASE64_DECODE expects a STRING, got INT"
);
assert_eq!(
std_base64_decode_failed("!!!", &base64::DecodeError::InvalidByte(0, b'!')).message(),
"BASE64_DECODE cannot decode \"!!!\": Invalid symbol 33, offset 0."
);
assert_eq!(
json_handle_needs_object(&serde_json::json!(7)).message(),
"HANDLE argument must be an object like {\"task_id\": 7}, got 7"
);
assert_eq!(
std_base64_decode_not_utf8().message(),
"BASE64_DECODE decoded bytes are not UTF-8"
);
assert_eq!(
json_handle_exact_shape().message(),
"HANDLE argument must be exactly {\"task_id\": N} with no other keys"
);
assert_eq!(
json_handle_task_id_positive().message(),
"HANDLE argument `task_id` must be a positive integer"
);
assert_eq!(
json_handle_encode_needs_handle("STRING").message(),
"cannot encode STRING as HANDLE; expected a task handle"
);
}
#[test]
fn check_messages_match_canonical_wording() {
assert_eq!(
import_not_in_closure("f").message(),
"IMPORT `f` cannot be read: not in the import closure"
);
assert_eq!(
import_export_type_mismatch("f", "T").message(),
"IMPORT `f` EXPORT TYPE `T` does not match any top-level TYPE in that file"
);
assert_eq!(
check_var_tag("v", typing_max_depth(8, "X")).message(),
"variable `$v`: type spelling exceeds maximum generic depth of 8: `X`"
);
assert_eq!(
check_func_tag("F", typing_max_depth(8, "X")).message(),
"function `F`: type spelling exceeds maximum generic depth of 8: `X`"
);
assert_eq!(
check_step_wrap(3, typing_max_depth(8, "X")).message(),
"step 3: type spelling exceeds maximum generic depth of 8: `X`"
);
assert_eq!(
check_ctx_wrap("ctx", &import_const_forward_failed("boom")).message(),
"ctx: boom"
);
assert_eq!(
check_exact_mismatch("ctx", &TypeTag::Int, &TypeTag::String).message(),
"ctx: TypeMismatch: expected `INT`, got `STRING`"
);
assert_eq!(
check_cannot_unify("ctx", &TypeTag::Int, &TypeTag::String).message(),
"ctx: cannot unify `INT` and `STRING`"
);
assert_eq!(
check_undefined_var("step 1: ", "x").message(),
"step 1: undefined variable `$x`"
);
assert_eq!(
check_var_not_guaranteed("x").message(),
"variable `$x` is not guaranteed to be defined on all reachable paths for this step"
);
assert_eq!(
check_unknown_field("step 1: ", "a", &[]).message(),
"step 1: unknown field `a`; expected fields: "
);
assert_eq!(
check_invalid_array_index("", "0").message(),
"invalid array index `0`"
);
assert_eq!(
check_cannot_traverse("", "k").message(),
"cannot traverse into scalar value at key `k`"
);
assert_eq!(
check_duplicate_func("F", "f.oxdock").message(),
"duplicate function `F` from `f.oxdock` collides across imports"
);
assert_eq!(
check_redeclare_let(2, "x").message(),
"step 2: redeclaration error: `$x` already declared in this scope; use `$x` = ... to mutate"
);
assert_eq!(
check_redeclare_const(2, "x").message(),
"step 2: redeclaration error: `x` is a CONST binding and cannot be redeclared; CONST and LET share one namespace"
);
assert_eq!(
check_undeclared_env("step 1", "top", "env:", "K").message(),
"step 1 in top: uses undeclared environment variable `env:K`: declare it first with ENV or INHERIT_ENV"
);
assert_eq!(
check_placeholder_keypath().message(),
"key paths on $ALIAS::NAME are not supported; copy to a local with LET or CONST first"
);
assert_eq!(
check_empty_placeholder_var().message(),
"invalid placeholder variable: empty variable reference"
);
assert!(check_bare_sigil("$x").message().contains("`$x`"));
assert_eq!(
check_undefined_script_var("k").message(),
"undefined script variable: `k`"
);
assert_eq!(
check_placeholder_unknown("A::F").message(),
"unknown placeholder function `A::F`"
);
assert_eq!(
check_template_arity_exact("step 1", "top", "F", 1, 2).message(),
"step 1 in top: F() expects 1 argument(s), got 2"
);
assert_eq!(
check_template_arity_range("step 1", "top", "F", 1, 2, 3).message(),
"step 1 in top: F() expects 1 to 2 argument(s), got 3"
);
assert_eq!(
check_template_arg_allowed("step 1", "top", "F", "p", &["a"], "b").message(),
"step 1 in top: F() argument `$p` must be one of: a, got \"b\""
);
assert!(
check_template_arg_depth()
.message()
.contains("nests too deep")
);
assert_eq!(
check_empty_placeholder_arg().message(),
"invalid placeholder call argument: empty variable reference"
);
assert_eq!(
check_invalid_placeholder_arg("x").message(),
"invalid placeholder call argument `x`"
);
assert_eq!(
check_invalid_map_entry("e").message(),
"invalid map literal entry `e`: use key: value"
);
assert_eq!(
check_duplicate_map_key("k").message(),
"duplicate key `k` in map literal"
);
assert_eq!(check_void_no_value().message(), "VOID has no value to pass");
assert_eq!(
check_redeclare_const(2, "x").message(),
"step 2: redeclaration error: `x` is a CONST binding and cannot be redeclared; CONST and LET share one namespace"
);
assert_eq!(
check_capture_mismatch(1, "LET", "x", &TypeTag::String, &TypeTag::Int).message(),
"step 1: LET `$x` captures STRING but declares INT"
);
assert_eq!(
check_flow_outside_loop(1, "CONTINUE").message(),
"step 1: CONTINUE outside loop"
);
assert_eq!(
check_flow_crosses_func(1, "BREAK", "F").message(),
"step 1: BREAK cannot cross function boundary (in F())"
);
assert_eq!(
check_unknown_function("F", " (did you mean G?)").message(),
"unknown function `F` (did you mean G?)"
);
assert_eq!(
check_call_arity_exact(1, "F", 1, 2).message(),
"step 1: F() expects 1 argument(s), got 2"
);
assert_eq!(
check_arithmetic_type("step 1: ").message(),
"step 1: Type Error: arithmetic requires Int or Float"
);
assert_eq!(
check_rpn_underflow().message(),
"internal error: RPN stack underflow"
);
assert_eq!(
check_block_fallthrough("step 1").message(),
"step 1: block may fall through with no RETURN on some path"
);
}
#[test]
fn mcp_messages_match_canonical_wording() {
assert_eq!(
mcp_export_type_unknown("T").message(),
"EXPORT TYPE `T` matches no local TYPE and no imported file exports it"
);
assert_eq!(
mcp_break_outside_loop(3).message(),
"step 3: BREAK outside loop"
);
assert_eq!(
mcp_continue_outside_loop(3).message(),
"step 3: CONTINUE outside loop"
);
assert_eq!(
mcp_return_outside_function(3).message(),
"step 3: RETURN outside function, ASYNC task, or LET block"
);
assert_eq!(mcp_unknown_tool("FOO").message(), "unknown MCP tool `FOO`");
let err = reason_sample("boom");
assert_eq!(mcp_call_failed(&err, "", "").message(), "boom");
assert_eq!(
mcp_call_failed(&err, "out", "oops").message(),
"boom\n--- captured stdout ---\nout\n--- captured stderr ---\noops"
);
let big = "x".repeat(5000);
let d = mcp_call_failed(&err, &big, "");
assert!(
d.message().ends_with(&"x".repeat(4096)),
"{}",
d.message().len()
);
assert!(!d.message().contains(&"x".repeat(4097)));
}
#[test]
fn import_messages_match_canonical_wording() {
assert_eq!(
import_cycle(&["a".to_string(), "b".to_string()]).message(),
"IMPORT cycle detected: a -> b"
);
assert_eq!(
import_depth_limit(8, "f").message(),
"IMPORT depth limit exceeded (8): `f`"
);
assert!(import_not_found("f").message().contains("not found"));
assert!(
import_cannot_resolve("f", &reason_sample("root"))
.message()
.contains("cannot be resolved")
);
assert!(
import_cannot_read("f", &reason_sample("root"))
.message()
.contains("cannot be read")
);
assert!(
import_bad_utf8("f", &utf8_err_sample())
.message()
.contains("not valid UTF-8")
);
assert!(
import_parse_failed("f", &parse_err_sample())
.message()
.contains("failed to parse")
);
assert_eq!(
engine_parse_failed(&parse_err_fallback_sample()).key(),
"dsl.engine.parse_failed"
);
assert!(
engine_parse_failed(&parse_err_fallback_sample())
.message()
.contains("boom")
);
assert_eq!(
engine_parse_failed(&parse_err_sample()).key(),
typing_max_depth(8, "X").key()
);
assert_eq!(
engine_parse_failed(&parse_err_sample()).message(),
typing_max_depth(8, "X").message()
);
assert_eq!(
import_missing_export("f", "TYPE", "T").message(),
"IMPORT `f` does not export TYPE `T`"
);
assert_eq!(
import_missing_export("f", "FUNC", "g").message(),
"IMPORT `f` does not export `g`"
);
assert_eq!(
import_unknown_member("f", "function", "g").message(),
"IMPORT `f` has no such function `g`"
);
assert_eq!(
import_unknown_type("f", "T", None).message(),
"IMPORT `f` has no such TYPE `T`"
);
assert!(
import_unknown_type("f", "T", Some(typing_max_depth(8, "X")))
.message()
.contains(": type spelling exceeds maximum generic depth of 8: `X`")
);
assert_eq!(
import_failed_validation("f", typing_max_depth(8, "X")).message(),
"IMPORT `f` failed validation: type spelling exceeds maximum generic depth of 8: `X`"
);
assert_eq!(
import_stateful_harvest("f", "g").message(),
"IMPORT `f` cannot harvest stateful function `g`: import the file"
);
assert_eq!(
import_unknown_function("f", "g").message(),
"IMPORT `f` has no such function `g`"
);
assert!(
import_type_collision("f", "T", "a", "b")
.message()
.contains("already defined with target `a`, new target `b`")
);
assert_eq!(
import_const_no_alias("q", "A").message(),
"unknown CONST `q`: no import alias `A` exports that name"
);
assert_eq!(
import_const_hinted("q", "h").message(),
"unknown CONST `q`: h"
);
assert_eq!(import_const_unknown("q").message(), "unknown CONST `q`");
assert!(
import_const_uninitialized("q")
.message()
.contains("never initialized")
);
assert!(import_const_is_let("q").message().contains("LET binding"));
assert_eq!(
import_const_forward_failed("unknown CONST `U::N`").message(),
"unknown CONST `U::N`"
);
assert_eq!(
import_flow_crosses_boundary("BREAK", 3, "f").message(),
"step 3: BREAK cannot cross import boundary (in IMPORT `f`)"
);
}
}