ichiban / prolog

The only reasonable scripting engine for Go.
MIT License
564 stars 27 forks source link

Enable creation of PermissionError and ResourceError Exceptions #310

Closed ccamel closed 6 months ago

ccamel commented 7 months ago

Context

We extensively use ichiban/prolog for our okp4/okp4d protocol, and we have reached a point where there is a need to standardize the error representation of our custom predicates. This includes throwing exceptions such as permission_error and resource_error.

Issue

At present, the ichiban/prolog library allows custom predicates to raise exceptions such as TypeError and DomainError. However, it lacks the capability to raise PermissionError and ResourceError exceptions since the relevant functions are private (engine/exception.go#L294). Additionally, the NewException function, while seemingly useful, cannot capture the private current context (varContext), which is important.

Solution

A straightforward solution would be to make the functions responsible for creating exceptions like PermissionError and ResourceError accessible to developers by making them publicly available. However, I trust your judgment for making the final decision on the solution.

Thx

PS: I would be delighted to contribute if needed. Just let me know.

ichiban commented 7 months ago

I was sure that the developers will need TypeError and DomainError but unsure about other errors. So I've been waiting for the requests. Let's add PermissionError and ResourceError If you need them!

I'll do it when I've got time (been busy moving) or you can make a PR and I'll happily merge it!

ichiban commented 6 months ago

Thank you for the contribution, @ccamel! I merged the PR and released v1.2.0.