Added `current_error_info` to `defer_error`

14 views
Skip to first unread message

edA-qa mort-ora-y

unread,
Jul 22, 2017, 3:31:11 PM7/22/17
to Leaflang
The `current_error_info` is now available in a `defer_error` block. This provides a simple way to add extra information to any error that occurs.

    defer_fail {
        current_error_info.add( tag_pine )
    }


Below is the advanced unit test for failure paths using this feature. I'm so happy this works!


/*EXPECT(-2saptruetrue)*/
//an extended test of nested function calls with fail and defer paths
var tag_sap = string_tag("sap")
var tag_pine = string_tag("pine")

defn sap = (x:integer)-> {
	x > 5 then fail tag_sap
	return -x
}

defn branch = (x:integer)->(q:integer) {
	do {
		//TODO: return sap(x)   instead of named return
		q = sap(x)
	} on fail {
		trace( current_error_info.tag )
		resume_fail
	}
}

defn pine = (x:integer)-> {
	defer_fail {
		current_error_info.add( tag_pine )
	}
	
	return branch(x)
}

trace(pine(2))

trace(pine(7)) on fail { 
	trace( current_error_info.contains(tag_sap) )
	trace( current_error_info.contains(tag_pine) )
}
Reply all
Reply to author
Forward
0 new messages