Skip to content

Commit

Permalink
refactor(shirelang): improve error handling and logging for ShireRunC…
Browse files Browse the repository at this point in the history
…onfigurationProfileState and PatternActionProcessor #24

Improve error handling by adding a check for empty prompt content in ShireRunConfigurationProfileState. This prevents running the process when there's no content to execute.

Additionally, enhance logging in FrontmatterParser and PatternActionProcessor to warn and error respectively for unknown pattern actions. This will help in debugging and identifying issues with custom user actions.
  • Loading branch information
phodal committed Jun 27, 2024
1 parent 96ea71b commit 38c8533
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,11 @@ object FrontmatterParser {
processor.add(PatternActionFunc.Cat(*args.toTypedArray()))
}

null -> {
logger.warn("parsePatternAction, Unknown pattern action: ${expr.funcCall}")
}

else -> {
// processor.add(PatternActionFunc.Prompt(text))
val funcName = funcCall?.funcName?.text ?: ""
processor.add(PatternActionFunc.UserCustom(funcName, args))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ class PatternActionProcessor(val myProject: Project, val editor: Editor, val hol
action.variables
}

is PatternActionFunc.UserCustom -> {
logger<PatternActionProcessor>().error("TODO for User custom: ${action.funcName}")
}

else -> {
logger<PatternActionProcessor>().error("Unknown pattern processor type: ${action.funcName}")
""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ open class ShireRunConfigurationProfileState(
val promptText = ShireTemplateCompiler(myProject, hobbitHole, symbolTable, input).compile()
logCompiled(console!!, promptText)


// check prompt text had content or just new line with whitespace
val promptTextTrim = promptText.trim()
if (promptTextTrim.isEmpty()) {
console!!.print("No content to run", ConsoleViewContentType.ERROR_OUTPUT)
processHandler.destroyProcess()
return DefaultExecutionResult(console, processHandler)
}

if (promptText.contains(SHIRE_ERROR)) {
processHandler.exitWithError()
return DefaultExecutionResult(console, processHandler)
Expand Down

0 comments on commit 38c8533

Please sign in to comment.