Skip to content

golang-exp/errors-poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

errors-poc

Leveled approach to errors - Proof of Concept (WIP) This project exists just to test possible design for adding stacktaces to go errors

Thanks to @mitar and golang community in general for ideas
mostly from this conversation
and from the leveled approach to logging used in log/slog

The interface of standard errors is unchanged
Much of the functionality is in the internal folder
There are some hacks to emulate the standard library for Errorf function
Hopefully this can be a good idea to add to the design of stacktraces in standard golang errors

There are 4 levels of errors as of now
suggestions to remove/add/modify levels are welcome
use stackLevelVar to make it dynamic (like log/slog LevelVar)

  1. LevelNoStack - behaves as if errors have no stacktrace infos (default)
  2. LevelProgramCounter - adds program counter to error
  3. LevelStackOnFirst level adds stacktrace to first error and PC to following errors
  4. LevelFullStack - adds stacktrace to all errors (personally I do not like this one)

Errors are generated by configurable structs that contain the StackLevel field

  • errorer
  • errorFormatter

StackDetails are generated by configurable struct which contains DetailFunc

  • detailer

Should the errors tree be explored when exracting the error details?
(i.e.: when joined errors are wrapped) Not for now.
Should we have another configuation variable for this functionality?? CLimbTheTreeVar (??)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages