Display Last KM Macro Error

Use Case

  • Your KM Macro just terminated due to an error
  • You need to quickly get the error details, and edit the Macro to fix it
  • KM native reporting of Macro errors via the macOS Notification Center is very poor
    (sorry @peternlewis, but it's true)
  • The below Macro attempts to provide better error reporting
    • However, because KM does NOT use a consistent format for logging errors, this Macro may not find all errors
    • If your Macro has an error that the Macro does NOT find, please post details in a reply. See instructions at bottom of this post. I will try to update the macro to catch your error.

PURPOSE

  • Display Detailed Info about Last Macro Error
  • With Options to
    • Edit Macro with Error and Search for Action that caused the error
    • Display KME Log file
    • Display Last N Lines from Log using BBEdit

Note: This Macro is Not Perfect

  • Because KM does NOT output all Macro errors in a consistent format, I have had to make an educated guess on the error format.
  • As a result, I expect there are some macro errors that will not be found by this Macro.
  • If you encounter an error not found by this Macro, please report it here.
  • See the below section for details: "Reporting Macro Errors Not Found By This Macro"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Display Last KM Macro Error Ver 4 [Pub]

UPDATED: 2021-07-21 17:30 GMT-5

  • Ver 4.4 provides a much enhanced output of the KM Log to BBEdit

-~~~ VER: 4.4    2021-07-21 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Display Last KM Macro Error Ver 4 [Pub].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Display Detailed Info about Last Macro Error
  • With Options to
    • Edit Macro with Error
    • Display KME Log file
    • Display Last N Lines from Log

HOW TO USE

  1. First, make sure you have followed instructions in the Macro Setup below.
  2. Immeditely after you see/hear the notification about a Macro Error, trigger this macro.

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. ??
      .

REQUIRES:

  1. KM 9.0+ (may work in KM 8.2+ in some cases)
  2. macOS 10.11.6 (El Capitan)+
  3. Sub-Macros
    • Display Last N Lines of KM Engine Log with Optional RegEx Filter [Sub-Macro] @DEV @TODO
    • Display Last N Lines of KM Engine Log [SUB-MACRO]

TAGS: @errors @KM @Macro @Log @JXA

REFERENCES:

  1. KM Forum discussion, 2016-10-15

image

Reporting Macro Errors Not Found By This Macro

  • KM does NOT use a consistent format for logging errors, so this Macro may not find some errors
  • If your Macro has an error that the Macro does NOT find, please post details in a reply.
    • Post the lines from the KM Error log shown in BBEdit that include all lines that contain the error information about your error, and two lines above and below them.
    • Post using the KM Forum Code Block
    • Here is an example of what I need:
2020-07-03 13:09:39 Variable “KMVAR_TEST__PageSource” excluded from environment to ensure the environment is not too large
2020-07-03 13:09:39 Execute macro “Display Last KM Macro Error Ver 4 SIMPLE” from trigger The Hot Key ⌃⌥⌘E is pressed

2020-07-03 13:09:33 Execute an AppleScript failed with script error: /Users/jimunderwood/Documents/My KM Data/Scripts/Extract Author and Article Title from EWT EMail.scpt: execution error: [ERROR] [MACRO CANCELLED] NSRegularExpression doesn’t understand the “regularExpressionWithPattern_options_error_” message. (-2700)
2020-07-03 13:09:32 Variable “KMVAR_DiscussionText” excluded from environment to ensure the environment is not too large
2020-07-03 13:09:32 Variable “KMVAR_TEST__PageSource” excluded from environment to ensure the environment is not too large
2020-07-03 13:09:32 Variable “KMVAR_DiscussionText” excluded from environment to ensure the environment is not too large
2020-07-03 13:09:32 Variable “KMVAR_TEST__PageSource” excluded from environment to ensure the environment is not too large
2020-07-03 13:09:32 Execute macro “FWD Selected EMail to @Evernote @EN @OL” from trigger The Hot Key ⌃⇧E is pressed

2020-07-03 13:09:21 Execute an AppleScript failed with script error: /Users/jimunderwood/Documents/My KM Data/Scripts/Extract Author and Article Title from EWT EMail.scpt: execution error: [ERROR] [MACRO CANCELLED] NSRegularExpression doesn’t understand the “regularExpressionWithPattern_options_error_” message. (-2700)
2020-07-03 13:09:21 Variable “KMVAR_DiscussionText” excluded from environment to ensure the environment is not too large

Note I have added a blank line immediately above and below what looks like that actual error msg.
Sometimes you will find unrelated lines mixed in with your error lines.

Thanks for your help in identifying all of the error log formats.

9 Likes
Stop on Error in a Multistep Macro?
Can't Read AppleScript Error Message Because It's Cut Off
KM Macro Cancellation Notifications
KM Macro Cancellation Notifications
Set Multiple Variables Plug In Action
Failing Actions and Shell Scripts
How to Debug a Macro That Requires a Specific Mouse Location?
Troubleshooting When One Hotkey Trigger Stops Working
Conflict hotkey triggers
Frequent Keyboard Maestro Engine Crash
Skip Prompt With List
Feature Request: auto-scrub 'Running application query took a while'
Facing KM-Problems using macOS HighSierra 10.13.6
Log/History of all KM actions run
How To Solve KM Problems Using the KM Debugger
Trigger on a Active Window with a Specific Tltle..? Possible?
A Hotkey to Repeat the Last Macro Used?
Macro Misbehaves Due to AntiVirus System
How Do I See the Full KM Error Message of Error Displayed by Notification Center?
Bring Window To Front
How to Read the Entire Error Message?
[feature request] execute python script
[FILE] Process Lines in Text File
[FILE] Process Lines in Text File
[FILE] Process Lines in Text File
[FILE] Process Lines in Text File
Edit Macro by Name
Growl Gone; Can't Read Long Errors; Macro to Show Error Log File
"Open a File, Folder, Application" not accepting variable?
How to "see" complete error message in Notification Centre - macro failed
Open Evernote attached file within current note
Macro Failure as a Trigger
P1 Bug: KM not opening newly updated Chrome?
MACRO: Spotlight Search Prompt
Try/Catch: Would Love to Get More Details in Tokens
Is it/could it be possible to prevent some macros from logging to the engine log?
Help understanding log entry "CompileAppleScript string failed"

@peternlewis, my macro assumes that all macro errors are logged using the same format. I use this RegEx to parse the log entry:

^([\d-: ]+) (.+)Macro\s‘([^’]+)’ ([\w ]+)\(while executing (.+)\)

Could you please confirm that all macro errors use this format, or, if not, provide the other formats?

If you have any suggestions on how to improve this, I'd love to hear/see them. :smile:

Thanks.

Example Log Entry

2016-10-27 12:51:12 Search Variable failed to match \d+ Macro ‘KM TEST Notifications’ cancelled (while executing FORCE ERROR to Abort Macro and AutoLog).

From this, I generate this display:

1 Like

I don’t know. Log messages are plain text and could contain anything. There are around 800 places where log messages are printed. Most of them are debugging that is disabled by default. I’ve got no idea what other ones might be of interest I’m afraid, it isn’t something I can support. If it works and finds what you’re after now, that is as good a guarantee as you’re going to get.

Sorry for the bug guys. Hopefully this will fix it.
Please update to this new version.

Thanx for this handy and nifty macro, but the download link still gives version 1.1 instead of version 2.0?

I’m not sure why that happen for you. I just tested it (downloaded it), and it is

~~~ ReleaseNotes for VER: 2.0 2018-03-21 ~~~

BTW, I believe the macro name even change a bit with Ver 2.
Please try again and let us know what happens.

I tried again and it’s working fine. Must have been a user error from this side :wink:
Thanx again for this, I’m positive i’ll be using it a lot.

Thank you!

Am I correct in understanding that only entries containing "Executing macro" and "Running application" are filtered out, and all other entries should appear? My log has these recent entries:

2020-05-17 08:02:58 Open File failed with non-existent path “/x.txt”.
2020-05-17 08:02:58 Open File failed with non-existent path “/x.txt”. Macro “Open x.txt” cancelled (while executing Open “/x.txt”).

When I trigger Display Last KM Macro Error, I get:
image

Can you help me understand why these failures are being filtered out/not being shown?

The problem is that there is not a standard format in which KM reports an error, failure, or termination to the log. I have asked @peternlewis to adopt one, but he declines to do so.
So I have had to make my best guess as to what constitutes an error, and extract the log entries accordingly.

Clearly my method is not perfect, and never will be until/if KM adopts a standard format.
If you, or anyone, can suggest a better method/regex I would be glad to incorporate it.

Hopefully my macro will be of help most of the time. I find how KM reports an error to the user to be lacking and frustrating. The macOS Notification is very limited, and often we can't read all of the error msg.

So if you have any suggestions for improvement, please let me know.

Thanks for the reply (and the macro). Actually, it’s helpful even to have the last five lines. I just wanted to make sure I understood. Sorry I can’t offer anything helpful.

Just updated my above post and macro.
Please delete the existing version in your KM account before you import this version.

Also, I need your help to make this macro better for all:

2 Likes

the macro is a gem !

I've found this really, really useful thanks. The notifications that pop up are really frustrating as half the time the info is cut off by the notification format not allowing the full message. Maybe there's another way to see the whole message, but I found this first and it's excellent!

2 Likes

Jim - I don't know how I missed this macro before, but thanks - it's awesome!

Can I assume this is a typo - that the "period" is on a separate line?

image

I'm only asking because I know you sometimes do things on purpose that the reason isn't initially obvious (but ends up being a good reason!), so I wanted to double-check.

Dan, it is on purpose. It is needed to provide a "blank" line at the bottom -- purely a visual thing.

I should have guessed that - I've done the same thing. If memory serves, there's an unprintable character you can use instead, but I'll be darned if I can remember which one. Maybe I'm thinking of something else. Anyway, thanks again for the macro!

1 Like

Option-space will very often do the trick in a case like this. Perhaps that’s what you’re remembering, @DanThomas?

2 Likes

Just updated the above OP with Ver 4.3.

It will now report on errors like this:

  • I expect there are other macro errors that will not be found by this Macro.
  • If you encounter an error not found by this Macro, please report it here.
  • See the above section for details: "Reporting Macro Errors Not Found By This Macro"
2 Likes

When you choose to open the KM Log in BBEdit, you will find a much more useful and easy to read window, with all of the "Execute Macro" lines highlighted.
Of course, when looking for an error, you need to start with the execution of the Macro, and, in this case, look UP (because the log is shown in reverse chron (last first) order) for the error details, which may NOT immediately follow the execution log entry.

You'll see a BBEdit window like this:

Please let me know if you have any suggestions for improvements, and if you encounter any errors not found by my macro.