package erratum

const testVersion = 2

func Use(o ResourceOpener, inp string) (err error) {
	var r Resource
	moveOn := false
	for !moveOn {
		moveOn = true
		if r, err = o(); err != nil {
			switch err.(type) {
			case TransientError:
				moveOn = false
			default:
				return err
			}
		}
	}
	defer r.Close()
	defer func() {
		if rec := recover(); rec != nil {
			switch v := rec.(type) {
			case FrobError:
				r.Defrob(v.defrobTag)
				err = v
			case error:
				err = v
			}
		}
	}()

	r.Frob(inp)

	return err
}
