Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Exception Handling and Log #470

Closed
wants to merge 24 commits into from

Conversation

taooceros
Copy link
Member

@taooceros taooceros commented Jun 11, 2021

  1. Introduce Demystifier library to make stacktrace more readable. https://github.com/benaadams/Ben.Demystifier
  2. Make QueryResult Method async void to allow exception thrown, which will trigger the report window on runtime.
  3. Use ExceptionDispatchInfo in Log.Exception to preserve stacktrace
  4. Make NLog log in async, and make Log.Exception not implemented synchronously.
  5. Use NLog's exception layout renderer to render exception.
  6. Use NLog's OutputDebugStringTarget to print to debug window
  7. Change layout to ${logger}->${time}|${level}|${message} (need discussion) (Exception layout is similar but too more new line is added before and after Exception block)
    • PluginManager->21:40:16.0845|Debug|"QueryForPluginAsync"|"Cost for System Commands <14ms>"|
  8. Replace all "prefix|UnPrefix" message to call overload that allow a className and methodName
  9. Use Conditional("DEBUG") for Debug method in logger.

The Exception block has been simplified to only Exception.ToString, because that will include message, Exception Type, and Stacktrace. I don't believe extra HResult or TargetSite will help us debugging.

TODO:

  • Unify Program Logger

Some Discussion

  • Do we want every exception thrown by plugin to report in a report window? (if not, do we want a message to notice user?)

Future (need discussion)

  • Make Logging system not static class but with per instance logger (which allows NLog to catch callsite)

1. Introduce Demystifier library to make stacktrace more readable. https://github.com/benaadams/Ben.Demystifier
2. Make QueryResult Method async void to allow exception thrown, which will trigger the report window on runtime.
3. Use ExceptionDispatchInfo in Log.Exception to preserve stacktrace
@taooceros taooceros changed the title Optimize Exception Handling Optimize Exception Handling and Log Jun 11, 2021
@jjw24
Copy link
Member

jjw24 commented Jun 13, 2021

Do we want every exception thrown by plugin to report in a report window? (if not, do we want a message to notice user?)

For now maybe report window as long as the link to report it is to the plugin's website not flow launcher unless they are default plugins. Reason is i would rather plugin devs be aware of the issue so they could fix it.

@jjw24
Copy link
Member

jjw24 commented Jun 13, 2021

Make Logging system not static class but with per instance logger (which allows NLog to catch callsite)

what do you mean callsite?

@taooceros
Copy link
Member Author

Make Logging system not static class but with per instance logger (which allows NLog to catch callsite)

what do you mean callsite?

If the log is logged directly. NLog allows to record caller information (like PluginManager.QueryAsync), so we won't need to record that separately.

@jjw24
Copy link
Member

jjw24 commented Jun 13, 2021

Make Logging system not static class but with per instance logger (which allows NLog to catch callsite)

what do you mean callsite?

If the log is logged directly. NLog allows to record caller information (like PluginManager.QueryAsync), so we won't need to record that separately.

Perfect, as long as it records the calling method

@taooceros
Copy link
Member Author

Perfect, as long as it records the calling method

Yeah, that's why currently we cannot do that, because we Log via another method which will change the callsite.

Maybe we can simply expose a readonly logger for people to use.

@jjw24
Copy link
Member

jjw24 commented Jun 13, 2021

👍 sounds good

@taooceros
Copy link
Member Author

Hmmm NLog's document suggests that callsite can be expensive (include a stacktrace tracking), but they are improving it in NLog 5.0. Maybe currently it would be better to still record caller by ourselves.

@jjw24
Copy link
Member

jjw24 commented Jun 13, 2021

Damn, ok sounds good

@taooceros
Copy link
Member Author

Another question is, should we removed the manual message. "prefix|unprefix", while prefix means classname and methodname, and direct all usage to Log.${Level}(message, classname, methodname[CallerMemberName])?

@jjw24
Copy link
Member

jjw24 commented Jun 13, 2021

yes 👍

Replace all prefix|unprefix message with overload with classname and [CallerMemberName] methodName.
Use nameof to get class Name
@taooceros
Copy link
Member Author

Done

@pc223
Copy link
Contributor

pc223 commented Jun 21, 2021

Do we want every exception thrown by plugin to report in a report window? (if not, do we want a message to notice user?)

For now maybe report window as long as the link to report it is to the plugin's website not flow launcher unless they are default plugins. Reason is i would rather plugin devs be aware of the issue so they could fix it.

I vote yes 👍 on this. Make sure users know something break and where to get help is good.

Should the report window have logs.txt file content and have a button to copy the logs too?

I think it's better that Flow exposes the logs file a bit more. I see a lot of users have hard time to find the logs file, especially with non-portable mode, the logs file path is really...long and obscure.

I'm thinking of something like this 🤓

image

Better error reporting is really useful when we introduce plugin-making for users that not professional dev.

@jjw24
Copy link
Member

jjw24 commented Jun 21, 2021

Please resolve conflict.

A fair bit of changes here, what have you tested so far?

Do we want this in 1.8.0?

I think it's better that Flow exposes the logs file a bit more. I see a lot of users have hard time to find the logs file, especially with non-portable mode, the logs file path is really...long and obscure.

@pc223 1.8.0 has command to open log file location directly, let me know if it's sufficient

@taooceros
Copy link
Member Author

Do we want this in 1.8.0?

At least part of it, including @pc223 's point.

@taooceros
Copy link
Member Author

taooceros commented Jun 22, 2021

image

I haven't notice this one when reviewing the last change. Why do we need to include another JsonStorage?

@jjw24
Copy link
Member

jjw24 commented Jun 22, 2021

That one is because in the old infra dll it looks for JsonStrorage class, the incorrectly spelled JsonStorage

@taooceros
Copy link
Member Author

That one is because in the old infra dll it looks for JsonStrorage class, the incorrectly spelled JsonStorage

Oh, got you. I didn't notice the typo.

1. Fix unpassed Exception parameter
2. Remove | in message in Program plugin
3. Adjust Format
@jjw24
Copy link
Member

jjw24 commented Jun 29, 2021

is this pr ready for review?

does it need to be in 1.8.0(a lot of changes across several plugins from a glance)?

@taooceros
Copy link
Member Author

is this pr ready for review?

does it need to be in 1.8.0(a lot of changes across several plugins from a glance)?

The major changes across plugins are from the api revise. You can take a glance on it, or if that's too much for review, let me pick a few things that worth to be included in 1.8.0.

@jjw24
Copy link
Member

jjw24 commented Jun 29, 2021

is this pr ready for review?
does it need to be in 1.8.0(a lot of changes across several plugins from a glance)?

The major changes across plugins are from the api revise. You can take a glance on it, or if that's too much for review, let me pick a few things that worth to be included in 1.8.0.

Yeah I think could you please pull out a few that is worth to be included into a separate pr and let me know what you have tested with them so I don't double up with my own testing

@taooceros
Copy link
Member Author

@jjw24 Do we want to include the layout change in 1.8.0?

@jjw24
Copy link
Member

jjw24 commented Jun 29, 2021

Layout change? What do you mean

@jjw24
Copy link
Member

jjw24 commented Jun 29, 2021

The log message layout?

@taooceros
Copy link
Member Author

The log message layout?

Yes

@jjw24
Copy link
Member

jjw24 commented Jun 29, 2021

Yeah sure

@jjw24
Copy link
Member

jjw24 commented Jun 30, 2021

@taooceros could you also merge dev and resolve conflict please

@taooceros
Copy link
Member Author

@taooceros could you also merge dev and resolve conflict please

Sure, will do tonight

@pc223
Copy link
Contributor

pc223 commented Aug 3, 2021

Do we want every exception thrown by plugin to report in a report window? (if not, do we want a message to notice user?)

@taooceros @jjw24 I think we should try to push this report-window-feature to release soon, because it affects adoption of the new Python plugins template, plugin-dev should aware of exception like this (or any invalid request/response RPC)

18:14:57.0716+07:00 - ERROR - JsonRPCPlugin.ExecuteAsync - Traceback (most recent call last):
  File "C:\Users\user1\AppData\Roaming\FlowLauncher\Plugins\Search-MDI-2.1.1\main.py", line 13, in <module>
    from plugin.main import MDI
ModuleNotFoundError: No module named 'plugin'

I caught this exception while trying to install the Search-MDI plugin, it indicates the main.py missing these lines. This should not break silently 😎

import sys,os
parent_folder_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(parent_folder_path)
sys.path.append(os.path.join(parent_folder_path, 'lib'))
sys.path.append(os.path.join(parent_folder_path, 'plugin'))

@jjw24
Copy link
Member

jjw24 commented Aug 7, 2021

Do we want every exception thrown by plugin to report in a report window? (if not, do we want a message to notice user?)

@taooceros @jjw24 I think we should try to push this report-window-feature to release soon, because it affects adoption of the new Python plugins template, plugin-dev should aware of exception like this (or any invalid request/response RPC)

18:14:57.0716+07:00 - ERROR - JsonRPCPlugin.ExecuteAsync - Traceback (most recent call last):
  File "C:\Users\user1\AppData\Roaming\FlowLauncher\Plugins\Search-MDI-2.1.1\main.py", line 13, in <module>
    from plugin.main import MDI
ModuleNotFoundError: No module named 'plugin'

I caught this exception while trying to install the Search-MDI plugin, it indicates the main.py missing these lines. This should not break silently 😎

import sys,os
parent_folder_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(parent_folder_path)
sys.path.append(os.path.join(parent_folder_path, 'lib'))
sys.path.append(os.path.join(parent_folder_path, 'plugin'))

yep makes sense to me.

Could you @taooceros merge dev again please

@taooceros
Copy link
Member Author

The feature has been merged. Jsonrpc exception is suppressed for now, but will be exposed in #633

@taooceros
Copy link
Member Author

The only thing left is the exception api refractor. Probably do a clean one will be easier than merging it, but anyway, I will take a try later.

@jjw24 jjw24 added review in progress Indicates that a review is in progress for this PR enhancement New feature or request labels Sep 15, 2021
@jjw24 jjw24 added this to the 1.9.0 milestone Sep 15, 2021
@jjw24
Copy link
Member

jjw24 commented Sep 22, 2021

@taooceros when you get a chance, could you merge dev in, i gave it a shot but still had many differences i am unsure of, so i reverted back.

@taooceros
Copy link
Member Author

@taooceros when you get a chance, could you merge dev in, i gave it a shot but still had many differences i am unsure of, so i reverted back.

Sure

@taooceros
Copy link
Member Author

It's too hard to merge....I will refactor the rest of the part once I am free

@jjw24 jjw24 removed the review in progress Indicates that a review is in progress for this PR label Sep 22, 2021
@taooceros taooceros modified the milestones: 1.9.0, Future Dec 3, 2021
@taooceros taooceros closed this Jan 17, 2024
@jjw24 jjw24 removed this from the Future milestone Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants