Skip to content

Commit a43f225

Browse files
Update OPA Plugin: Error Handling and Synchronization with Plugin Framework Updates (#1531)
* Error handling and updates with new refactoring changes in plugin framework Signed-off-by: Shriti Priya <shritip@ibm.com> * update documentation Signed-off-by: Shriti Priya <shritip@ibm.com> * fixing lint issues Signed-off-by: Shriti Priya <shritip@ibm.com> * fixing linting issues Signed-off-by: Shriti Priya <shritip@ibm.com> * fixing lint issues Signed-off-by: Shriti Priya <shritip@ibm.com> * Fixing pylint issues Signed-off-by: Shriti Priya <shritip@ibm.com> * Replacing exception with pluginerror Signed-off-by: Shriti Priya <shritip@ibm.com> * Updating documentation and plugin code Signed-off-by: Shriti Priya <shritip@ibm.com> * fixing flake issues Signed-off-by: Shriti Priya <shritip@ibm.com> * fix lint issues Signed-off-by: Shriti Priya <shritip@ibm.com> * fix: correct f-string syntax in OPA plugin error logging The f-string at line 225 had incorrect syntax with the colon and variable inside the format specifier. Changed from: f"{OPAPluginErrorCodes.UNSUPPORTED_HOOK_TYPE.value: {hook}}" to: f"{OPAPluginErrorCodes.UNSUPPORTED_HOOK_TYPE.value}: {hook}" Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Shriti Priya <shritip@ibm.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
1 parent dccd778 commit a43f225

File tree

5 files changed

+361
-86
lines changed

5 files changed

+361
-86
lines changed

plugins/external/opa/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,21 @@ make test
275275
The`make test` command executes a complete testing workflow: it launches an OPA server using the policy file located at ./opaserver/rego/policy.rego (as specified by `POLICY_PATH`), runs all test cases against this server, and automatically terminates the OPA server process once testing finishes.
276276

277277

278+
## Error Handling Verification
279+
280+
1. `OPA_SERVER_NONE_RESPONSE` = "OPA server returned an empty response"
281+
2. `OPA_SERVER_ERROR` = "Error while communicating with the OPA server"
282+
3. `OPA_SERVER_UNCONFIGURED_ENDPOINT` = "Policy endpoint not configured on the OPA server"
283+
4. `UNSPECIFIED_REQUIRED_PARAMS` = "Required parameters missing: policy config, payload, or hook type"
284+
5. `UNSUPPORTED_HOOK_TYPE` = "Unsupported hook type (only tool, prompt, and resource are supported)"
285+
6. `INVALID_POLICY_ENDPOINT` = "Policy endpoint must be curated with the supported hooktypes"
286+
7. `UNSPECIFIED_POLICY_MODALITY` = "Unspecified policy modality. Picking up default modality: text"
287+
8. `UNSUPPORTED_POLICY_MODALITY` = "Unsupported policy modality (Supports text, image and resource)"
288+
9. `UNSPECIFIED_POLICY_PACKAGE_NAME` = "Unspecified policy package name"
289+
290+
If OPA plugin encounters any of the errors above, it raises a PluginError.
291+
The file `test_errors.py` includes unit tests to verify that these errors are correctly raised under the corresponding conditions.
292+
Run it using `make test`
278293

279294
## License
280295

0 commit comments

Comments
 (0)