Skip to content

DirtyPanic Concept #11

@amberpixels

Description

@amberpixels

Usually in libraries we can simply panic if a developer messes something up. here, in d3rty/json the main concept is to "forgive" any mistakes. So we must forgive mistakes of the developer who does use the di3rt/json as well.

So, when the config is corrupted, or invalid usage of dirty models, we need a way to shout out loud (as panics), but do not ruin the code: return as much valid clean data as we can.

e.g.

		boolFromNumber = func(n float64) option.Bool {
			// assuming config is enabled
			fromNumbersCfg := cfg.FromNumbers
			var b option.Bool
			if parser, ok := parsersBoolFromNum[fromNumbersCfg.CustomParseFunc]; ok {
				b = parser(n)
			} else {
				// TRICKY THING. CORRUPTED CONFIG IS HERE. We should not just silently exit
				// Let's log or something similar (TODO: handle this carefully)
				return option.NoneBool()
			}

			if b.Some() {
				return b
			}

			return cfg.FallbackValue
		}

It might be some loud log (it might be auto-repeatable annoying log, or log with destination - in slack, telegram, etc).

Same concept can be used in yellow/red results notifications

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions