mirror of
https://github.com/enso-org/enso.git
synced 2024-12-28 13:22:31 +03:00
Add a .to_json
conversion for Error
(#1742)
This commit is contained in:
parent
48bcebc723
commit
1a6b67d361
@ -84,6 +84,23 @@ Error.to_default_visualization_data = this.catch .to_default_visualization_data
|
||||
Error.to_display_text : Text
|
||||
Error.to_display_text = "Error: " + (this.catch .to_display_text)
|
||||
|
||||
## UNSTABLE
|
||||
|
||||
Returns a JSON representation of the dataflow error.
|
||||
|
||||
> Example
|
||||
Converting a dataflow error to JSON.
|
||||
|
||||
import Standard.Examples
|
||||
|
||||
example_to_json = Examples.throw_error.to_json
|
||||
Error.to_json : Json.Object
|
||||
Error.to_json =
|
||||
error_type = ["type", "Error"]
|
||||
error_content = ["content", this.catch .to_json]
|
||||
error_message = ["message", this.catch .to_display_text]
|
||||
Json.from_pairs [error_type, error_content, error_message]
|
||||
|
||||
## Transforms an error.
|
||||
|
||||
Arguments:
|
||||
@ -126,4 +143,3 @@ Error.is_error = True
|
||||
example_rethrow = Panic.rethrow Examples.throw_error
|
||||
Panic.rethrow : (Any ! Any) -> Any
|
||||
Panic.rethrow value = value.catch Panic.throw
|
||||
|
||||
|
@ -23,6 +23,21 @@ spec =
|
||||
Test.specify "should be able to be shown in the default visualization" <|
|
||||
json = (Error.throw <| My_Type "aaa").to_default_visualization_data
|
||||
json . should_equal <| (Json.from_pairs [["foo", "aaa"], ["type", "My_Type"]]).to_text
|
||||
|
||||
Test.specify "should be able to be shown in the default vector visualization" <|
|
||||
vec = [My_Type "bar", Error.throw (My_Type 42)]
|
||||
visualization_text = vec.to_default_visualization_data
|
||||
expected_json = Json.parse '''
|
||||
[
|
||||
{ "foo":"bar",
|
||||
"type":"My_Type"
|
||||
},
|
||||
{ "content":{ "foo":42, "type":"My_Type" },
|
||||
"message":"My_Type",
|
||||
"type":"Error"
|
||||
}
|
||||
]
|
||||
visualization_text.should_equal expected_json.to_text
|
||||
Test.specify "should implement to_display_text" <|
|
||||
Error.throw Nothing . to_display_text . should_equal "Error: Nothing"
|
||||
Test.specify "should be able to be mapped" <|
|
||||
|
Loading…
Reference in New Issue
Block a user