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

fix edge case with {}'s in logs #9

Merged
merged 1 commit into from
Nov 8, 2019

Conversation

jdodds
Copy link
Contributor

@jdodds jdodds commented Nov 8, 2019

Proposed Changes

This fixes an edge case where it's possible for writeMessage to try to send a string to String.Format that looks like it still has format specifiers in it when there are none.

I haven't yet been able reproduce this with a toplevel test without reproducing the app I'm working ons environment, but here's a stack trace:

System.FormatException: Input string was not in a correct format.
   at System.Text.StringBuilder.FormatError()
   at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)                                                                                              
   at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.Format(IFormatProvider provider, String format, Object[] args)
   at A.B.Logging.Providers.ConsoleProvider.ConsoleProvider.writeMessage[a](a name, LogLevel logLevel, FSharpOption`1 messageFunc, FSharpOption`1 exception, Object[] formatParams) in /Users/jeremiahdodds/workspace/my/project/paket-files/TheAngryByrd/FsLibLog/src/FsLibLog/FsLibLog.fs:line 463
   at A.B.Logging.Providers.ConsoleProvider.A-B-Logging-Types-ILogProvider-GetLogger@487.Invoke(LogLevel logLevel, FSharpOption`1 messageFunc, FSharpOption`1 exception, Object[] formatParams) in /Users/jeremiahdodds/workspace/my/project/paket-files/TheAngryByrd/FsLibLog/src/FsLibLog/FsLibLog.fs:line 487                                                                                      
   at A.B.Logging.Types.Inner.ILog.fromLog(ILog logger, Log log) in /Users/jeremiahdodds/workspace/my/project/paket-files/TheAngryByrd/FsLibLog/src/FsLibLog/FsLibLog.fs:line 86                 
   at A.B.Logging.Types.Inner.ILog.error'(ILog logger, FSharpFunc`2 logConfig) in /Users/jeremiahdodds/workspace/my/project/paket-files/TheAngryByrd/FsLibLog/src/FsLibLog/FsLibLog.fs:line 126  
   at A.B.Logging.Types.Inner.ILog.error(ILog logger, FSharpFunc`2 logConfig) in /Users/jeremiahdodds/workspace/my/project/paket-files/TheAngryByrd/FsLibLog/src/FsLibLog/FsLibLog.fs:line 140   
   at <redacted>
   at FSharp.Control.Tasks.TaskBuilder.tryWith[a](FSharpFunc`2 step, FSharpFunc`2 catch)

The fix itself also might be done in a better way than two string replacements :/

Types of changes

What types of changes does your code introduce to FsLibLog?
Put an x in the boxes that apply

  • [x ] Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • Build and tests pass locally
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

Further comments

Tested via fsi calling String.Format on values as they appeared at runtime when I was seeing the error.

@TheAngryByrd TheAngryByrd merged commit 4a04cde into TheAngryByrd:master Nov 8, 2019
@TheAngryByrd
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants