Commit: 0e90eee
Parent: 6e190e4

Write errors when EDITOR is missing

Mårten Åsberg committed on 2026-07-31 at 22:10
src/NewNote.cs +17 -3
diff --git a/src/NewNote.cs b/src/NewNote.cs
index 860fde1..a469c12 100644
@@ -54,9 +54,23 @@ public sealed class NewNote : PSCmdlet
if (Open && ShouldProcess(createdItem.FullName, "Open"))
{
InvokeCommand.InvokeScript(
$"{GetVariableValue("Env:EDITOR")} {createdItem.FullName}:{content.Count(c => c is '\n')}"
);
var defaultEditorValue = new { };
var editor = GetVariableValue("Env:EDITOR", defaultEditorValue);
if (editor == defaultEditorValue)
{
WriteError(
new(
new InvalidOperationException("The EDITOR environment variable must be set to open notes."),
"NotesCli:MissingEditorEnvironmentVariable",
ErrorCategory.InvalidOperation,
createdItem
)
);
}
else
{
InvokeCommand.InvokeScript($"{editor} {createdItem.FullName}:{content.Count(c => c is '\n')}");
}
}
WriteObject(createdItem);