Assertions with stark update

I was updating some stuff to Stardog 7 and noticed that the previous assertions ie. assertStringLiteral no longer throw an exception which makes sense since you're now expected to return ValueOrError. The name is a bit confusing though since it isn't asserting anything but I know that's a holdover from the way it previously worked.

I noticed though in the examples

that it's still being used the old way so assertStringLiteral is being called but it doesn't matter what is returned and the following cast will fail.

What I can't figure out is how to return a ValueOrError with an explicit error. "it's not a literal. I'd like to return a ValueOrErrar that's an error"

Yeah, you're right that the example should be updated. To return an error you can just use ValueOrError.Error or create your own implementation of ValueOrError which would return true from isError().

Thanks,
Pavel

Thanks. I hadn't noticed that TypeError extends ValueOrError. I guess you just get the generic error message. I used to return somewhat informative error messages with the ExpressionEvaluationException.

Yeah, we can probably introduce a method to provide an error message. The reason we killed ExpressionEvaluationException was performance, there're queries which generated too many of those and the try-catch overhead was very noticeable.

Best,
Pavel

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.