p0358 / notepadpp-CodeStats

Notepad++ plugin for Code::Stats (https://codestats.net)
Other
39 stars 22 forks source link

Errors popping as I type in files that have extensions that are not supported (eg. .*cmd, *.au3) #8

Closed deskobj closed 2 years ago

deskobj commented 5 years ago

Installed the Code::Stats Plugin for Notepad++ a few hours ago, and run into a pretty serious issue; the kind of issue that will make me uninstall CodeStats ASAP.

What is the bug about: As soon as I start typing in files which have an extension that is not registered I am getting error.

The bugfix should :

image

---------------------------
Error writing to log file
---------------------------
System.IO.IOException: The process cannot access the file 'C:\Users\Pino\AppData\Roaming\Notepad++\plugins\Config\CodeStats.log' because it is being used by another process.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)

   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)

   at CodeStats.Logger.Setup()

   at CodeStats.Logger.Log(LogLevel level, String msg)
---------------------------
OK   
---------------------------

Followed by:

---------------------------
Error writing to log file
---------------------------
C:\Users\Pino\AppData\Roaming\Notepad++\plugins\Config\Code::Stats.log
---------------------------
OK   
---------------------------

Typical files which trigger the error are ".cmd" and ".au3".

Despite the fact the error says the log file could not be written, we can still see some output in there. (And the output seem up-to-date.)

[Code::Stats Debug 06:28:12 PM] SCN_CHARADDED - File: U:\Dropbox\Sandbox\CodeStat-Assist.au3, char: 97, lang: AutoIt
[Code::Stats Info 06:28:12 PM] Key = "au3" is not found.
[Code::Stats Info 06:28:12 PM] Key = "au3" is not found.
[Code::Stats Debug 06:28:12 PM] SCN_CHARADDED - File: U:\Dropbox\Sandbox\CodeStat-Assist.au3, char: 115, lang: AutoIt
[Code::Stats Info 06:28:12 PM] Key = "au3" is not found.
[Code::Stats Info 06:28:12 PM] Key = "au3" is not found.
[Code::Stats Debug 06:28:12 PM] SCN_CHARADDED - File: U:\Dropbox\Sandbox\CodeStat-Assist.au3, char: 97, lang: AutoIt
[Code::Stats Info 06:28:12 PM] Key = "au3" is not found.
[Code::Stats Info 06:28:12 PM] Key = "au3" is not found.
[Code::Stats Debug 06:28:12 PM] SCN_CHARADDED - File: U:\Dropbox\Sandbox\CodeStat-Assist.au3, char: 115, lang: AutoIt
[Code::Stats Debug 06:28:28 PM] No proxy will be used. It's either not set or badly formatted.
[Code::Stats Debug 06:28:28 PM] Pulsing {"xps":[{"language":"AutoIt","xp":16}],"coded_at":"2019-04-25T18:28:12+02:00"}

Or when editing a "*.cmd" command file

image

What those ".cmd" and ".au3" files seem to have in common is that they are not registered in the Plugin DLL, which, if you open it, contains the following static string : (C:\Program Files\Notepad++\plugins\CodeStats\CodeStats.dll)

  "plaintext": "Plain text",
  "txt": "Plain text",
  "log": "Log",
  "bat": "Batch",
  "clojure": "Clojure",
  "coffeescript": "CoffeeScript",
  "coffee": "CoffeeScript",
  "c": "C",
  "cpp": "C++",
  "hpp": "C++",
  "csharp": "C#",
  "cs": "C#",
  "css": "CSS",
  "diff": "Diff",
  "dockerfile": "Docker",
  "elixir": "Elixir",
  "elm": "Elm",
  "fsharpcss": "F#",
  "git": "Git",
  "gitignore": "Ignore File (gitignore syntax)",
  "git-commit": "Git",
  "git-rebase": "Git",
  "go": "Go",
  "groovy": "Groovy",
  "handlebars": "Handlebars",
  "hlsl": "HLSL",
  "html": "HTML",
  "i18n": "Localization file",
  "ini": "Ini",
  "properties": "Properties",
  "conf": "Properties",
  "cfg": "Properties",
  "java": "Java",
  "javascriptreact": "JavaScript (React)",
  "javascript": "JavaScript",
  "js": "JavaScript",
  "jsx-tags": "JavaScript (JSX)",
  "json": "JSON",
  "less": "LESS",
  "lua": "Lua",
  "makefile": "Makefile",
  "markdown": "Markdown",
  "md": "Markdown",
  "nut": "Squirrel",
  "objective-c": "Objective-C",
  "perl": "Perl",
  "perl6": "Perl 6",
  "php": "PHP",
  "powershell": "PowerShell",
  "jade": "Pug",
  "python": "Python",
  "py": "python",
  "r": "R",
  "razor": "Razor",
  "raml": "RAML",
  "ruby": "Ruby",
  "rust": "Rust",
  "scss": "SCSS",
  "shaderlab": "Shaderlab",
  "shellscript": "Shell Script",
  "sql": "SQL",
  "swift": "Swift",
  "typescript": "TypeScript",
  "typescriptreact": "TypeScript (React)",
  "vb": "Visual Basic",
  "xml": "XML",
  "xsl": "XSL",
  "yaml": "YAML"

I don't think the log file is used by another process. The only thing that is specific with my setup is that my directory "%AppData%\Roaming\Notepad++\plugins\Config" is actually a hardlink to another location (a Dropbox directory), and for some reason this is maybe making harder for the plugin to write in it, which then causes the exception and finally makes Notepad++ display error message dialogs as I type.

Also, note that I don't have this problem if I write in more common files, such as a .txt or a .cs, so it's a cascading effect, ie. there are 2 problems here : 1/ log file being filled with the "Key = "EXT" is not found." and 2/ actually sometimes failing to write there and causing the errors to pop and interrupt editing ever couple of keystrokes.

pinodev commented 5 years ago

Keywords

SAVE_LOG_IN_TEMP_INSTEAD_OF_PLUGIN_DIR

Synopsis

Do not save the log file in the Notepad++'s AppData directory, use the TEMP directory instead.

Description

I have implemented a fix for the problem reported at:

p0358/notepadpp-CodeStats "Errors popping as I type in files that have extensions that are not supported (eg. .cmd, .au3)" https://github.com/p0358/notepadpp-CodeStats/issues/8

Changesets:

and the Binary DLLs:

(tested with Notepad++ 7.6.6)

Kind regards,

P.

p0358 commented 5 years ago

@deskobj Hmm, I seem to have problems reproducing this issue in current public plugin version. Of course, the "Key = "x" is not found." spam in log occurs. But the only way I can reproduce is having the log file opened in the same Notepad++ instance in monitoring (aka tail -f) mode. Perhaps you had some software that was monitoring the file and interfering? Anyways, my proposed fix for unwanted errors popping up is to limit log error message boxes to up to 1 per session, so that further errors will be ignored in order not to interrupt user work

pinodev commented 5 years ago

Hi, yes, sorry it's me, I didn't pay attention and logged the ticket with my other account.

Great idea to having used the monitoring mode to reproduce the problem (y) ;-)

Yes, indeed, the file is being monitored by Dropbox because I am using Notepad++ as a portable application.

Even without the errors related to the unrecognised extensions (au3, cmd), there were still too many open-write-close operations performed on the log file and I kept getting dialog boxes in my faces (although slightly less often).

Changing the location of the log file to TEMP fixed the problem.

p0358 commented 5 years ago

By the way, this is why Notepad++ has "Settings on cloud" feature (Settings->Preferences->Cloud). It also doesn't safe session (opened files, their positions), so it's better to use across multiple computers. Its disadvantage though is that it doesn't save plugins or their config. Thus moving logs to temp folder might be a good solution, I will consider it and probably implement

pinodev commented 5 years ago

Yes indeed, I noticed the "Settings on cloud" and tried it a couple months ago, but I found that I was missing some settings.

And actually my trick of making AppData\Notepad++ a junction to a synchronized location wasn't great either because it didn't contain my plugins which were stored in ProgramFiles (although it did contain the plugins configuration, but not the binaries).

I guess I could have fixed this by making use of the allowAppDataPlugins.xml and moving all my plugins to the AppData directory, but this started to feel like becoming overly complicated (and not any safer/secure anyway, at that point).

So earlier this month, I actually uninstalled Notepad++, and I am using the portable package instead now (so everything runs from the same directory, from Dropbox-or-alike).

p0358 commented 2 years ago

This should now be fixed/mitigated in v1.1.0 due to following changes: