util: Properly handle errors during log message formatting #9963

pull laanwj wants to merge 2 commits into bitcoin:master from laanwj:2017_03_handle_exception_tinyformat changing 2 files +23 −6
  1. laanwj commented at 10:42 am on March 9, 2017: member

    Instead of having an exception propagate into the program (which at worst causes a crash) when an error happens while formatting a log message, just print a message to the log. This message clearly indicates what log message was formatted wrongly, and what error happened during formatting it.

    Addresses #9423.

    Before

     02017-03-09 10:58:20 
     1
     2************************
     3EXCEPTION: St13runtime_error       
     4tinyformat: Too many conversion specifiers in format string       
     5bitcoin in AppInit()       
     6
     7
     8
     9************************
    10EXCEPTION: St13runtime_error       
    11tinyformat: Too many conversion specifiers in format string       
    12bitcoin in AppInit()       
    13
    142017-03-09 10:58:20 Shutdown: In progress...
    152017-03-09 10:58:20 scheduler thread interrupt
    162017-03-09 10:58:20 Shutdown: done
    

    (and process exits)

    After

    02017-03-09 10:51:50 Error "tinyformat: Too many conversion specifiers in format string" while formatting log message: Erasing %s %s
    

    (and process continues)

  2. laanwj added the label Docs and Output on Mar 9, 2017
  3. laanwj added the label Utils and libraries on Mar 9, 2017
  4. TheBlueMatt commented at 5:52 pm on March 10, 2017: member
    Looks good, though I’d prefer if we narrow the catch and change TINYFORMAT_ERROR to throw a more narrow exception type. Not for any specific concern, but…man I hate C++ exceptions.
  5. laanwj commented at 6:20 pm on March 10, 2017: member
    So are there any errors during log message formatting that raise runtime_error that you’d want to escalate? We don’t have any sensible/specific exception handling so personally I’d prefer to keep it like this.
  6. laanwj commented at 6:21 pm on March 10, 2017: member
    Ehh oops I guess it makes sense to have the catch() only around tfm::format, though, not LogPrintStr (which does I/O).
  7. util: Properly handle errors during log message formatting
    Instead of having an exception propagate into the program when an
    error happens while formatting a log message, just print a message to
    the log.
    
    Addresses #9423.
    3b092bd9b6
  8. laanwj force-pushed on Mar 12, 2017
  9. laanwj commented at 6:59 am on March 12, 2017: member
    Okay, updated so that only the formatting is guarded and there is a single LogPrintStr call which can still fail for legit reasons such as disk full…
  10. TheBlueMatt commented at 11:46 pm on March 12, 2017: member

    Heh, I knew it needed a tighter catch somehow :P. Anyway, if you dont want to have something more specific that’s fine.

    utACK 3b092bd9b6b3953d5c3052d57e4827dbd85941fd

  11. util: Throw tinyformat::format_error on formatting error
    Throw tinyformat::format_error on formatting error instead of the
    `std::runtime_error`.
    b651270cd6
  12. laanwj commented at 5:53 am on March 13, 2017: member
    LIke this? I don’t think this is a very interesting place to get started defining more specific exceptions, but we have to start somewhere…
  13. TheBlueMatt commented at 12:19 pm on March 13, 2017: member

    Yea, agreed. I do like that better, though I suppose we really need to come up with some kind of coherent exception-use design at some point.

    On March 13, 2017 1:53:19 AM EDT, “Wladimir J. van der Laan” notifications@github.com wrote:

    LIke this? I don’t think this is not a very interesting place to get started defining more specific exceptions, but we have to start somewhere…

    – You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/bitcoin/bitcoin/pull/9963#issuecomment-286021176

  14. laanwj merged this on Mar 13, 2017
  15. laanwj closed this on Mar 13, 2017

  16. laanwj referenced this in commit 8040ae6fc5 on Mar 13, 2017
  17. sickpig referenced this in commit 5189d4b044 on Jan 11, 2018
  18. sickpig referenced this in commit 50fd5ca5f9 on Jan 11, 2018
  19. PastaPastaPasta referenced this in commit c402fc6a5b on May 12, 2019
  20. PastaPastaPasta referenced this in commit 597b039838 on May 16, 2019
  21. codablock referenced this in commit a6eee07f29 on May 21, 2019
  22. deadalnix referenced this in commit e87be9ab69 on Jan 21, 2020
  23. barrystyle referenced this in commit 1917dafa6a on Jan 22, 2020
  24. furszy referenced this in commit 9ef9f5dea1 on Mar 27, 2020
  25. akshaynexus referenced this in commit 5c753ce7c2 on Mar 30, 2020
  26. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-28 22:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me